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

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var ex = await Assert.ThrowsExceptionAsync <NotFoundException>(() => sut.UpdateReviewAsync(2, "Edit Text of Review01"));

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

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review01());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var review = await sut.UpdateReviewAsync(1, "Edit Text of Review01");

                mockBusinessValidator.Verify(x => x.IsDescriptionInRange("Edit Text of Review01"), Times.Exactly(1));

                Assert.AreEqual(review.EditedDescription, "Edit Text of Review01");
            }
        }
Пример #3
0
        public async Task Succeed_ReturnGetAllReviewsByBusinessUnitId()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnGetAllReviewsByBusinessUnitId));

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review01());

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review02());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var review = await sut.GetAllReviewsByBusinessUnitIdAsync(1);

                Assert.AreEqual(review.Count, 2);
            }
        }
        public async Task ThrowsExeptionWhenModeratorNotExistsBy_ReturnGetAllReviewsByModeratorId()
        {
            var options = TestUtils.GetOptions(nameof(ThrowsExeptionWhenModeratorNotExistsBy_ReturnGetAllReviewsByModeratorId));

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review01());

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review02());

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

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var review = await sut.GetAllReviewsByModeratorIdAsync(TestHelperReview.TestUser01().Id);

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

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

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review01());

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review02());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var review = await sut.GetReviewByIdAsync(1);

                Assert.AreEqual(review.OriginalDescription, TestHelperReview.Review01().OriginalDescription);
                Assert.AreEqual(review.EditedDescription, TestHelperReview.Review01().EditedDescription);
                Assert.AreEqual(review.Id, TestHelperReview.Review01().Id);
                Assert.AreEqual(review.CreatedOn, TestHelperReview.Review01().CreatedOn);
                Assert.AreEqual(review.isVisible, TestHelperReview.Review01().isVisible);
                Assert.AreEqual(review.BusinessUnitId, TestHelperReview.Review01().BusinessUnitId);
            }
        }
        public async Task Succeed_ReturnGetAllReviewsInDateRange()
        {
            var options = TestUtils.GetOptions(nameof(Succeed_ReturnGetAllReviewsInDateRange));

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

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review02());

                await arrangeContext.Reviews.AddAsync(TestHelperReview.Review03());

                await arrangeContext.SaveChangesAsync();
            }

            using (var assertContext = new ManagerLogbookContext(options))
            {
                var mockBusinessValidator = new Mock <IBusinessValidator>();
                var mockReviewEditor      = new Mock <IReviewEditor>();

                var sut = new ReviewService(assertContext, mockBusinessValidator.Object, mockReviewEditor.Object);

                var review = await sut.GetAllReviewsInDateRangeAsync(TestHelperReview.Review02().CreatedOn, TestHelperReview.Review04().CreatedOn);

                mockBusinessValidator.Verify(x => x.IsDateValid(TestHelperReview.Review02().CreatedOn), Times.Exactly(2));

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