public async Task NotChangedWhenNullValuesAdded()
        {
            var options = TestUtils.GetOptions(nameof(NotChangedWhenNullValuesAdded));

            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 noteDTO = await sut.EditNoteAsync(TestHelpersNote.TestNote1().Id,
                                                      TestHelpersNote.TestUser1().Id,
                                                      null, null, null);

                Assert.AreEqual(noteDTO.Description, TestHelpersNote.TestNote1().Description);
                Assert.AreEqual(noteDTO.Image, TestHelpersNote.TestNote1().Image);
                Assert.AreEqual(noteDTO.CategoryName, TestHelpersNote.TestNoteCategory2().Name);
            }
        }
        public async Task SuccessfullyEditNote()
        {
            var options = TestUtils.GetOptions(nameof(SuccessfullyEditNote));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote1());

                await arrangeContext.NoteCategories.AddAsync(TestHelpersNote.TestNoteCategory1());

                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.EditNoteAsync(TestHelpersNote.TestNote1().Id,
                                                      TestHelpersNote.TestUser1().Id,
                                                      "The room is clean", "710f8fd0-c90f-4d6a-b421-3aef173d9cf4", TestHelpersNote.TestNoteCategory1().Id);

                Assert.AreEqual(noteDTO.Description, "The room is clean");
                Assert.AreEqual(noteDTO.Image, "710f8fd0-c90f-4d6a-b421-3aef173d9cf4");
                Assert.AreEqual(noteDTO.CategoryName, TestHelpersNote.TestNoteCategory1().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);
            }
        }
Exemplo n.º 4
0
        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);
            }
        }
Exemplo n.º 5
0
        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 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 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);
            }
        }
Exemplo n.º 8
0
        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);
            }
        }
Exemplo n.º 9
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);
            }
        }
Exemplo n.º 10
0
        public async Task ThrowsExeption_WhenLogbookNotFound()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserIsManagerOfLogbook));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1());

                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 <NotFoundException>(() => sut.SwitchLogbookAsync(TestHelpersNote.TestUser1().Id, TestHelpersNote.TestLogbook1().Id));

                Assert.AreEqual(ex.Message, ServicesConstants.LogbookNotFound);
            }
        }
        public async Task ReturnRightUser()
        {
            var options = TestUtils.GetOptions(nameof(ReturnRightUser));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Users.AddAsync(TestHelpersNote.TestUser1());

                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.GetUserByIdAsync(TestHelpersNote.TestUser1().Id);

                Assert.AreEqual(userDTO.Id, TestHelpersNote.TestUser1().Id);
            }
        }
        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);
            }
        }
Exemplo n.º 13
0
        public async Task ThrowsExeption_WhenUserIsNotFromLogbook()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeption_WhenUserIsNotFromLogbook));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Notes.AddAsync(TestHelpersNote.TestNote4());

                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.DeactivateNoteActiveStatus(TestHelpersNote.TestNote1().Id,
                                                                                                                         TestHelpersNote.TestUser1().Id));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserIsNotAuthorizedToEditNote, TestHelpersNote.TestUser1().UserName));
            }
        }
Exemplo n.º 14
0
        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.DeactivateNoteActiveStatus(TestHelpersNote.TestNote1().Id,
                                                                                                                    TestHelpersNote.TestUser1().Id));

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