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

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.RemoveManagerFromLogbookAsync("2", TestHelpersLogbook.TestLogbook01().Id));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotFound));
            }
        }
        public async Task Succeed_ReturnLogbookWhenManagerIsAdded()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnLogbookWhenManagerIsAdded));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01());

                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser02());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                await sut.AddManagerToLogbookAsync(TestHelpersLogbook.TestUser02().Id, TestHelpersLogbook.TestLogbook01().Id);

                Assert.AreEqual(assertContext.UsersLogbooks.Select(x => x.LogbookId).Count(), 2);
            }
        }
예제 #3
0
        public async Task ThrowsExeptionWhenUserWasNotFound()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnAllLogbooksByUser));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01());

                await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote02());

                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook03());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks03());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.GetAllLogbooksByUserAsync("2"));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.UserNotFound));
            }
        }
        public async Task ThrowsExeptionWhenManagerIsAlreadyAddedToLogbook()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenManagerIsAlreadyAddedToLogbook));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var ex = await Assert.ThrowsExceptionAsync <ArgumentException>(() => sut.AddManagerToLogbookAsync(TestHelpersLogbook.TestUser01().Id, 1));

                Assert.AreEqual(ex.Message, string.Format(ServicesConstants.ManagerIsAlreadyInLogbook, TestHelpersLogbook.TestUser01().UserName, TestHelpersLogbook.TestLogbook01().Name));
            }
        }
예제 #5
0
        public async Task Succeed_ReturnAllLogbooksByUser()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnAllLogbooksByUser));

            using (var arrangeContext = new ManagerLogbookContext(options))
            {
                await arrangeContext.BusinessUnits.AddAsync(TestHelpersLogbook.TestBusinessUnit01());

                await arrangeContext.Notes.AddAsync(TestHelpersLogbook.TestNote02());

                await arrangeContext.Users.AddAsync(TestHelpersLogbook.TestUser01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook01());

                await arrangeContext.Logbooks.AddAsync(TestHelpersLogbook.TestLogbook03());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks01());

                await arrangeContext.UsersLogbooks.AddAsync(TestHelpersLogbook.TestUsersLogbooks03());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockedBusinessValidator = new Mock <IBusinessValidator>();
                var sut = new LogbookService(assertContext, mockedBusinessValidator.Object);

                var allLogbooksByUser = await sut.GetAllLogbooksByUserAsync(TestHelpersLogbook.TestUser01().Id);

                Assert.AreEqual(allLogbooksByUser.Count, 2);
            }
        }