public async Task TestGetByIdAsyncIdInvalid() { // Arrange var options = TestUtilities.BuildTestDbOptions(); const int testId = 1; await using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); var repoWrapper = new RepositoryWrapper(context); var service = new ClassSessionService(repoWrapper); // Act // Assert var ex = await Assert.ThrowsAsync <Exception>( () => service.GetByIdAsync(testId)); Assert.Equal( $"ClassSession with Id {testId} could not be found.", ex.Message); context.Database.EnsureDeleted(); } }
public async Task TestGetByIdAsyncIdBad(int testId) { // Arrange var options = TestUtilities.BuildTestDbOptions(); await using (var context = new ApplicationDbContext(options)) { var repoWrapper = new RepositoryWrapper(context); var service = new ClassSessionService(repoWrapper); // Act // Assert var ex = await Assert.ThrowsAsync <Exception>( () => service.GetByIdAsync(testId)); Assert.Equal("Bad Id", ex.Message); } }
public async Task TestGetByIdAsyncIdValid() { // Arrange var options = TestUtilities.BuildTestDbOptions(); const int testId = 1; ClassSession result; await using (var context = new ApplicationDbContext(options)) { context.Database.EnsureCreated(); context.ClassSession.Add(new ClassSession()); context.SaveChanges(); Assert.Single(context.ClassSession); var repoWrapper = new RepositoryWrapper(context); var service = new ClassSessionService(repoWrapper); // Act result = await service.GetByIdAsync(testId); } // Assert await using (var context = new ApplicationDbContext(options)) { Assert.NotNull(result); Assert.IsAssignableFrom <ClassSession>(result); context.Database.EnsureDeleted(); } }