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.TestNote1()); await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote2()); await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote3()); 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.ShowLogbookNotesForDaysBeforeAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id, 3); Assert.AreEqual(notesDTO.Count, 2); } }
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 ThrowsExceptionWhenAddNotExistingCategory() { var options = TestUtils.GetOptions(nameof(ThrowsExceptionWhenAddNotExistingCategory)); 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 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.NoteCategoryDoesNotExists); } }
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 Succeed() { var options = TestUtils.GetOptions(nameof(Succeed)); using (var arrangeContext = new ManagerLogbookContext(options)) { 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 noteDTO = await sut.DeactivateNoteActiveStatus(TestHelpersNote.TestNote4().Id, TestHelpersNote.TestUser1().Id); Assert.IsFalse(noteDTO.IsActiveTask); } }