December 2019
Intermediate to advanced
510 pages
11h 33m
English
After implementing the ItemsRepositoryTests type, in Chapter 8, Building the Data Access Layer, you might notice that we are using a recurring pattern in the ItemRepositoryTests class:
... var options = new DbContextOptionsBuilder<CatalogContext>() .UseInMemoryDatabase(databaseName: "should_get_data") .Options; await using var context = new TestCatalogContext(options); context.Database.EnsureCreated(); var sut = new ItemRepository(context);...
The preceding snippet has been replicated in every test method written up to now. It is possible to improve our test code by extracting the implementation in a different type. The xunit framework provides a way to share test contexts between test methods of the same test ...