public async Task SuccessfullySwitch() { var options = TestUtils.GetOptions(nameof(SuccessfullySwitch)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1()); await arrangeContext.Logbooks.AddAsync(TestHelpersNote.TestLogbook1()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersNote.TestUsersLogbooks1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedRapper = new Mock <IUserServiceWrapper>(); var sut = new UserService(assertContext, mockedRapper.Object); var userDTO = await sut.SwitchLogbookAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id); Assert.AreEqual(userDTO.CurrentLogbookId, TestHelpersNote.TestLogbook1().Id); } }
public async Task Return_RightCollection() { var options = TestUtils.GetOptions(nameof(Return_RightCollection)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote2()); await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote4()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersNote.TestUsersLogbooks1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var notesDTO = await sut.ShowLogbookNotesWithActiveStatusAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id); Assert.AreEqual(notesDTO.Count, 1); } }
public async Task ThrowsExceptionWhenUserIsNotAuthorized() { var options = TestUtils.GetOptions(nameof(ThrowsExceptionWhenUserIsNotAuthorized)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1()); await arrangeContext.Logbooks.AddAsync(TestHelpersNote.TestLogbook1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var description = "Room 37 needs cleaning."; var image = "abd22cec-9df6-43ea-b5aa-991689af55d1"; var ex = await Assert.ThrowsExceptionAsync <NotAuthorizedException>(() => sut.CreateNoteAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id, description, image, TestHelpersNote.TestNoteCategory2().Id)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotManagerOfLogbook, TestHelpersNote.TestUser1().UserName, TestHelpersNote.TestLogbook1().Name)); } }
public async Task SucceedCreateWhenNoCategoryAdded() { var options = TestUtils.GetOptions(nameof(SucceedCreateWhenNoCategoryAdded)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.UsersLogbooks.AddAsync(TestHelpersNote.TestUsersLogbooks1()); await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1()); await arrangeContext.Logbooks.AddAsync(TestHelpersNote.TestLogbook1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var description = "Room 37 needs cleaning."; var image = "abd22cec-9df6-43ea-b5aa-991689af55d1"; var noteDTO = await sut.CreateNoteAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id, description, image, null); mockedValidator.Verify(x => x.IsDescriptionInRange(description), Times.Exactly(1)); mockedValidator.Verify(x => x.IsDescriptionIsNullOrEmpty(description), Times.Exactly(1)); Assert.AreEqual(noteDTO.Id, 1); Assert.AreEqual(noteDTO.Description, description); Assert.IsNull(noteDTO.CategoryName); Assert.IsFalse(noteDTO.IsActiveTask); } }
public async Task ReturnRightPagesCount() { var options = TestUtils.GetOptions(nameof(ReturnRightPagesCount)); using (var arrangeContext = new ManagerLogbookContext(options)) { var notes = new List <Note>(); for (int i = 0; i < 35; i++) { notes.Add(new Note() { Description = "Very nice morning.", LogbookId = TestHelpersNote.TestLogbook1().Id }); } await arrangeContext.Notes.AddRangeAsync(notes); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var notesPerPage = 15; var sut = new NoteService(assertContext, mockedValidator.Object); var pages = await sut.GetPageCountForNotesAsync(notesPerPage, TestHelpersNote.TestLogbook1().Id); Assert.AreEqual(pages, 3); } }
public async Task Return_RightCollectionWhenNoDatesSelected() { var options = TestUtils.GetOptions(nameof(Return_RightCollectionWhenNoDatesSelected)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote1()); await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote2()); await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote3()); await arrangeContext.NoteCategories.AddAsync(TestHelpersNote.TestNoteCategory1()); await arrangeContext.UsersLogbooks.AddAsync(TestHelpersNote.TestUsersLogbooks1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var notesDTO = await sut.SearchNotesAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id, DateTime.MinValue, DateTime.MinValue, 2, "room37", null); Assert.AreEqual(notesDTO.Count, 2); } }
public async Task ThrowsExeption_WhenUserIsManagerOfLogbook() { var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserIsManagerOfLogbook)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1()); await arrangeContext.Logbooks.AddAsync(TestHelpersNote.TestLogbook1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedRapper = new Mock <IUserServiceWrapper>(); var sut = new UserService(assertContext, mockedRapper.Object); var ex = await Assert.ThrowsExceptionAsync <NotAuthorizedException>(() => sut.SwitchLogbookAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotManagerOfLogbook, TestHelpersNote.TestUser1().UserName, TestHelpersNote.TestLogbook1().Name)); } }
public async Task ThrowsExeption_WhenUserNotFound() { var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserNotFound)); using (var assertContext = new ManagerLogbookContext(options)) { var mockedRapper = new Mock <IUserServiceWrapper>(); var sut = new UserService(assertContext, mockedRapper.Object); var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.SwitchLogbookAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id)); Assert.AreEqual(ex.Message, ServicesConstants.UserNotFound); } }
public async Task ThrowsExeption_WhenUserIsNotFound() { var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserIsNotFound)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote1()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.ShowLogbookNotesForDaysBeforeAsync(TestHelpersNote.TestUser3().Id, TestHelpersNote.TestLogbook1().Id, 4)); Assert.AreEqual(ex.Message, ServicesConstants.UserNotFound); } }
public async Task ThrowsExeption_WhenUserIsNotAuthorized() { var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserIsNotAuthorized)); using (var arrangeContext = new ManagerLogbookContext(options)) { await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote1()); await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser3()); await arrangeContext.SaveChangesAsync(); } using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var ex = await Assert.ThrowsExceptionAsync <NotAuthorizedException>(() => sut.ShowLogbookNotesWithActiveStatusAsync(TestHelpersNote.TestUser3().Id, TestHelpersNote.TestLogbook1().Id)); Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserIsNotAuthorizedToViewNotes, TestHelpersNote.TestUser3().UserName)); } }
public async Task ThrowsExceptionWhenUserNotFound() { var options = TestUtils.GetOptions(nameof(ThrowsExceptionWhenUserNotFound)); using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var description = "Room 37 needs cleaning."; var image = "abd22cec-9df6-43ea-b5aa-991689af55d1"; var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.CreateNoteAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id, description, image, TestHelpersNote.TestNoteCategory2().Id)); Assert.AreEqual(ex.Message, ServicesConstants.UserNotFound); } }
public async Task ThrowsException_WhenUserNotFound() { var options = TestUtils.GetOptions(nameof(ThrowsException_WhenUserNotFound)); using (var assertContext = new ManagerLogbookContext(options)) { var mockedValidator = new Mock <IBusinessValidator>(); var sut = new NoteService(assertContext, mockedValidator.Object); var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.SearchNotesAsync(TestHelpersNote.TestUser2().Id, TestHelpersNote.TestLogbook1().Id, DateTime.MinValue, DateTime.MinValue, null, null, null)); Assert.AreEqual(ex.Message, ServicesConstants.UserNotFound); } }