Example #1
0
        public async Task ReturnRightCollection()
        {
            var options = TestUtils.GetOptions(nameof(ReturnRightCollection));

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedRapper = new Mock <IUserServiceWrapper>();
                var sut          = new UserService(assertContext, mockedRapper.Object);
                var managers     = new List <User>()
                {
                    TestHelpersNote.TestUser1(), TestHelpersNote.TestUser2()
                };

                mockedRapper.Setup(x => x.GetAllUsersInRoleAsync("Manager")).ReturnsAsync(managers);

                var usersDTO = await sut.GetAllManagersNotPresentInLogbookAsync(1);

                Assert.AreEqual(usersDTO.Count, 2);
            }
        }
        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.TestUser2());

                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.EditNoteAsync(TestHelpersNote.TestNote1().Id,
                                                                                                            TestHelpersNote.TestUser2().Id, "edited note", null, null));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserIsNotAuthorizedToEditNote, TestHelpersNote.TestUser2().UserName));
            }
        }
        public async Task ThrowsExeption_WhenNoteNotExists()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenNoteNotExists));

            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.EditNoteAsync(TestHelpersNote.TestNote1().Id,
                                                                                                       TestHelpersNote.TestUser2().Id, null, null, null));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.NotNotFound));
            }
        }
        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);
            }
        }
Example #5
0
        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.DeactivateNoteActiveStatus(TestHelpersNote.TestNote1().Id,
                                                                                                                    TestHelpersNote.TestUser2().Id));

                Assert.AreEqual(ex.Message, ServicesConstants.UserNotFound);
            }
        }