You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**EntityFrameworkCore.AutoFixture** is the logical product of [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) in-memory providers and [AutoFixture](https://github.com/AutoFixture/AutoFixture).
9
+
**EntityFrameworkCore.AutoFixture** is the logical product
10
+
of [Entity Framework Core](https://docs.microsoft.com/en-us/ef/core/) in-memory providers
11
+
and [AutoFixture](https://github.com/AutoFixture/AutoFixture).
10
12
11
-
Using **EntityFrameworkCore.AutoFixture** you can greatly reduce the boilerplate work necessary to unit test code that uses **Entity Framework Core** database contexts (see [examples](#examples)). You'll appreciate this library if you are already using **AutoFixture** as your auto-mocking container.
13
+
Using **EntityFrameworkCore.AutoFixture** you can greatly reduce the boilerplate work necessary to unit test code that
14
+
uses **Entity Framework Core** database contexts (see [examples](#examples)). You'll appreciate this library if you are
15
+
already using **AutoFixture** as your auto-mocking container.
12
16
13
-
**EntityFrameworkCore.AutoFixture** extens **AutoFixture** with the ability to create fully functional `DbContext` instances, with very little setup code.
17
+
**EntityFrameworkCore.AutoFixture** extens **AutoFixture** with the ability to create fully functional `DbContext`
18
+
instances, with very little setup code.
14
19
15
-
Unlike other libraries for faking EF contexts, **EntityFrameworkCore.AutoFixture** does not use mocking frameworks or dynamic proxies in order to create `DbContext` instances, instead it uses the Microsoft's own in-memory [providers](https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/) for EF Core. This allows to make less assumptions (read as: mock setups) in your tests about how the `DbContext` will behave in the real environment.
20
+
Unlike other libraries for faking EF contexts, **EntityFrameworkCore.AutoFixture** does not use mocking frameworks or
21
+
dynamic proxies in order to create `DbContext` instances, instead it uses the Microsoft's own
22
+
in-memory [providers](https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/) for EF Core. This allows to make
23
+
less assumptions (read as: mock setups) in your tests about how the `DbContext` will behave in the real environment.
16
24
17
25
#### :warning: .NET Standard 2.0 in EF Core v3.0.x :warning:
18
26
19
-
Entity Framework Core `v3.0.0` - `v3.0.3` are targeting `netstandard2.1`, which means they are not compatible with target frameworks that support at most `netstandard2.0` (`>= net47` and `netcoreapp2.1`).
20
-
Versions after `v3.1` are targeting `netstandard2.0`. If you've encountered this issue consider upgrading to a later version of Entity Framework Core.
27
+
Entity Framework Core `v3.0.0` - `v3.0.3` are targeting `netstandard2.1`, which means they are not compatible with
28
+
target frameworks that support at most `netstandard2.0` (`>= net47` and `netcoreapp2.1`).
29
+
Versions after `v3.1` are targeting `netstandard2.0`. If you've encountered this issue consider upgrading to a later
30
+
version of Entity Framework Core.
21
31
22
32
## Features
23
33
24
34
**EntityFrameworkCore.AutoFixture** offers three customizations to aid your unit testing workflow:
25
35
26
-
-`InMemoryContextCustomization` - customizes fixtures to use the In-Memory database provider when creating *DbContext* instances
27
-
-`SqliteContextCustomization` - customizes fixtures to use the SQLite database provider when creating *DbContext* instances.
28
-
By default the customization will create contexts for an in-memory *connection string* (i.e. `DataSource=:memory:`). This can be changed by providing the fixture a predefined `SqliteConnection` instance.
29
-
-`DbContextCustomization` - serves as the base customization for the other two implementations. The customization can be used, in more advanced scenarios, when you want to extend the fixtures with your own specimen builders.
36
+
-`InMemoryContextCustomization` - customizes fixtures to use the In-Memory database provider when creating *DbContext*
37
+
instances
38
+
-`SqliteContextCustomization` - customizes fixtures to use the SQLite database provider when creating *DbContext*
39
+
instances.
40
+
By default the customization will create contexts for an in-memory *connection string* (i.e. `DataSource=:memory:`).
41
+
This can be changed by providing the fixture a predefined `SqliteConnection` instance.
42
+
-`DbContextCustomization` - serves as the base customization for the other two implementations. The customization can
43
+
be used, in more advanced scenarios, when you want to extend the fixtures with your own specimen builders.
30
44
31
45
## Examples
32
46
33
-
The examples below demonstrate, the possible ways of using the library in [xUnit](https://github.com/xunit/xunit) test projects, both with `[Fact]` and `[Theory]` tests.
47
+
The examples below demonstrate, the possible ways of using the library in [xUnit](https://github.com/xunit/xunit) test
48
+
projects, both with `[Fact]` and `[Theory]` tests.
34
49
35
-
The library is not limited to `xUnit` and can be used with other testing frameworks like `NUnit` and `MSTest`, since it only provides a few `Customization` implementations.
50
+
The library is not limited to `xUnit` and can be used with other testing frameworks like `NUnit` and `MSTest`, since it
51
+
only provides a few `Customization` implementations.
36
52
37
53
### Using In-Memory database provider
38
54
@@ -57,7 +73,8 @@ public async Task CanUseGeneratedContext()
57
73
}
58
74
```
59
75
60
-
The next example uses a custom `AutoData` attribute `AutoDomainDataWithInMemoryContext` that customizes the fixture with the same customization as in the example above. This helps abstract away even more setup code.
76
+
The next example uses a custom `AutoData` attribute `AutoDomainDataWithInMemoryContext` that customizes the fixture with
77
+
the same customization as in the example above. This helps abstract away even more setup code.
61
78
62
79
```csharp
63
80
[Theory, InMemoryData]
@@ -71,6 +88,7 @@ public async Task CanUseGeneratedContext(TestDbContext context)
The attribute used in the test above might look something like the following.
75
93
76
94
```csharp
@@ -87,9 +105,12 @@ public class InMemoryDataAttribute : AutoDataAttribute
87
105
}
88
106
}
89
107
```
108
+
90
109
### Using SQLite database provider
91
110
92
-
When using the SQLite database provider there is another configuration available in the customization, called `AutoOpenConnection` which allows to automatically open database connections, after they are resolved from the fixture. The option is turned off by default in v1, but might become the default in next major releases.
111
+
When using the SQLite database provider there is another configuration available in the customization,
112
+
called `AutoOpenConnection` which allows to automatically open database connections, after they are resolved from the
113
+
fixture. The option is turned off by default in v1, but might become the default in next major releases.
0 commit comments