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 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); } }