public async Task ThrowsExeptionWhenManagerWasNotFoundByRemoveManagerFromLogbook() { var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenManagerWasNotFoundByRemoveManagerFromLogbook)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.RemoveManagerFromLogbookAsync("2", TestHelpersLogbook.TestLogbook01().Id)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotFound)); } }
public async Task Succeed_ReturnLogbookWhenManagerWasRemoved() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnLogbookWhenManagerWasRemoved)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01()); await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser02()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook04()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks04()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); await sut.RemoveManagerFromLogbookAsync(TestHelpersLogbook.TestUser01().Id, TestHelpersLogbook.TestLogbook04().Id); Assert.AreEqual(assertContext.UsersLogbooks.Select(x => x.LogbookId).Count(), 0); } }