public async Task GetSurveyAsync_Returns_Survey_Requests() { // All contexts that share the same service provider will share the same InMemory database var options = CreateNewContextOptions(); // Run the test against one instance of the context using (var context = new ApplicationDbContext(options)) { var survey = new Survey { Id = 1, Requests = new List <ContributorRequest> { new ContributorRequest() } }; context.Add(survey); context.SaveChanges(); } // Use a separate instance of the context to verify correct data was saved to database using (var context = new ApplicationDbContext(options)) { var store = new SqlServerSurveyStore(context); var result = await store.GetSurveyAsync(1); Assert.NotNull(result.Requests); Assert.NotEmpty(result.Requests); } }
public async Task GetSurveyAsync_Returns_CorrectSurvey() { // All contexts that share the same service provider will share the same InMemory database var options = CreateNewContextOptions(); using (var context = new ApplicationDbContext(options)) { context.Add(new Survey { Id = 1 }); context.SaveChanges(); } using (var context = new ApplicationDbContext(options)) { var store = new SqlServerSurveyStore(context); var result = await store.GetSurveyAsync(1); Assert.Equal(1, result.Id); } }