U
U
Unit Testing in C#
Search…
U
U
Unit Testing in C#
Unit testing in C#
Unit testing
What to test
When to test
Qualities of a good unit test suite
Qualities of a good unit test
Dealing with dependencies
Running the tests
NUnit
Quick glance at NUnit
Creating a NUnit test project
Anatomy of a test fixture
Lifecycle of a test fixture
Assertions
Asynchronous executions
Parameterized tests
Assumptions
Describing your tests
Moq
Quick glance at Moq
Method arguments
Method calls
Properties
Results
Callbacks
Exceptions
Events
Verifications
Base class
Mock customization
Implicit mocks
Mock repository
Custom matchers
Multiple interfaces
Protected members
Generic methods
Delegates
AutoFixture
Quick glance at AutoFixture
Fixture
Create and Build
Type customization
Data annotations
Default configurations
Building custom types
Relays
Tricks
Idioms
Integration with NUnit
Integration with Moq
Combining AutoFixture with NUnit and Moq
Extending AutoFixture
Advanced topics
Testing HttpClient
Powered By
GitBook
Mock repository
Working with several mocks can be very tedious. Especially when each needs to be configured (behavior and default value provider) and verified.
To facilitate this aspect, developers can use the MockRepository to create, customize and verify mocks as needed.
var
repository
=
new
MockRepository
(
MockBehavior
.
Strict
)
{
DefaultValue
=
DefaultValue
.
Mock
};
A repository can be used to create new mocks (and override the default setting if needed)
var
mockFoo
=
repository
.
Create
<
IFoo
>
();
var
mockBar
=
repository
.
Create
<
IBar
>
(
MockBehavior
.
Loose
);
Also, a repository can be used to verify the expectations configured on all mocks created by it
repository
.
Verify
();
Moq - Previous
Implicit mocks
Next - Moq
Custom matchers
Last modified
1yr ago
Copy link