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 ThrowsExeptionWhenLogbookIsNull() { var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenLogbookIsNull)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01()); 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.UpdateLogbookAsync(10, "name", 1, "picture")); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.LogbookNotFound)); } }
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); } }
public async Task ThrowsExeptionWhenManagerIsAlreadyAddedToLogbook() { var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenManagerIsAlreadyAddedToLogbook)); 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 <ArgumentException>(() => sut.AddManagerToLogbookAsync(TestHelpersLogbook.TestUser01().Id, 1)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.ManagerIsAlreadyInLogbook, TestHelpersLogbook.TestUser01().UserName, TestHelpersLogbook.TestLogbook01().Name)); } }
public async Task Succeed_ReturnLogbookWhenParametersAreValid() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnLogbookWhenParametersAreValid)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); var logbookDTO = await sut.UpdateLogbookAsync(1, "Hotel", 1, "picture"); Assert.AreEqual(logbookDTO.Name, "Hotel"); Assert.AreEqual(logbookDTO.Picture, "picture"); } }
public async Task ThrowsExeptionWhenBusinessUnitWasNotFound() { var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenBusinessUnitWasNotFound)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.BusinessUnitCategories.AddAsync(TestHelpersLogbook.TestBusinessUnitCategory01()); await arrangeContext.Towns.AddAsync(TestHelpersLogbook.TestTown01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); 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.AddLogbookToBusinessUnitAsync(TestHelpersLogbook.TestLogbook01().Id, 2)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.BusinessUnitNotFound)); } }
public async Task Succeed_ReturnLogbookWhenWasAddedToBusinessUnitAsync() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnLogbookWhenWasAddedToBusinessUnitAsync)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.BusinessUnitCategories.AddAsync(TestHelpersLogbook.TestBusinessUnitCategory01()); await arrangeContext.Towns.AddAsync(TestHelpersLogbook.TestTown01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); await sut.AddLogbookToBusinessUnitAsync(TestHelpersLogbook.TestLogbook01().Id, TestHelpersLogbook.TestBusinessUnit01().Id); await assertContext.SaveChangesAsync(); Assert.AreEqual(TestHelpersLogbook.TestLogbook01().BusinessUnitId, TestHelpersLogbook.TestBusinessUnit01().Id); } }
public async Task Succeed_ReturnGetLogbookById() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnGetLogbookById)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockBusinessValidator.Object); var getLogbookById = await sut.GetLogbookById(1); Assert.AreEqual(getLogbookById.Id, 1); } }
public async Task ThrowsExeptionWhenUserWasNotFound() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnAllLogbooksByUser)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote02()); await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook03()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks03()); 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.GetAllLogbooksByUserAsync("2")); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotFound)); } }
public async Task Succeed_ReturnAllLogbooksByUser() { var options = TestUtils.GetOptions(nameof(Succeed_ReturnAllLogbooksByUser)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote02()); await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01()); await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook03()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks03()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); var allLogbooksByUser = await sut.GetAllLogbooksByUserAsync(TestHelpersLogbook.TestUser01().Id); Assert.AreEqual(allLogbooksByUser.Count, 2); } }
public async Task SucceedCreateLogbook() { var options = TestUtils.GetOptions(nameof(SucceedCreateLogbook)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01()); await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote01()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedBusinessValidator = new Mock <IBusinessValidator>(); var sut = new LogbookService(assertContext, mockedBusinessValidator.Object); var logbookDTO = await sut.CreateLogbookAsync("LogbookName", 1, "picture"); mockedBusinessValidator.Verify(x => x.IsNameInRange("LogbookName"), Times.Exactly(1)); Assert.AreEqual(logbookDTO.Name, "LogbookName"); } }