Esempio n. 1
0
        public async Task GetReviewProductTest_Success()
        {
            // Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

            using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>()))
            {
                var prodId = 1;

                // Act
                var result = await controller.GetReviewProduct(prodId);

                // Assert
                Assert.IsNotNull(result);
                var objResult = result.Result as OkObjectResult;
                Assert.IsNotNull(objResult);
                var retResult = objResult.Value as List <Review>;
                Assert.IsNotNull(retResult);
                //foreach (Review review in retResult)
                //{
                //    Assert.AreEqual(await repo.GetReview(review.Id), review);
                //}
            }
        }
Esempio n. 2
0
        public async Task ProductAverageTest_OneReview()
        {
            //Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

            using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>()))
            {
                var prodId = 3;

                //Act
                var result = await controller.ProductAverage(prodId);

                var expected = await controller.GetReviewProduct(prodId);

                //Assert
                var objResult = result.Result as OkObjectResult;
                Assert.IsNotNull(objResult);
                var retResult = objResult.Value;
                Assert.IsNotNull(retResult);
                double val = TestData.Reviews().FirstOrDefault(r => r.Purchase.Id == prodId).Rating;

                Assert.AreEqual(val, retResult);
            }
        }
Esempio n. 3
0
        public async Task GetReviewProductTest_NotExists()
        {
            //Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

            using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>()))
            {
                var prodId = 370;

                //Act
                var result = await controller.GetReviewProduct(prodId);

                //Assert
                Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
            }
        }
Esempio n. 4
0
        public async Task GetReviewProductTest_Hidden()
        {
            //Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

            using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>()))
            {
                var prodId = 2;

                //Act
                var result = await controller.GetReviewProduct(prodId);

                var expected = TestData.Reviews().Where(r => r.Purchase.ProductId == prodId && r.IsVisible).ToList();

                //Assert
                Assert.IsInstanceOfType(result.Result, typeof(NotFoundResult));
            }
        }