Beispiel #1
0
        public async Task DeleteReviewTest()
        {
            // Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

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

                // Act
                await controller.DeleteConfirmed(reviewId);

                var review = await controller.Details(reviewId);

                // Assert
                Assert.IsInstanceOfType(review.Result, typeof(NotFoundResult));
            }
        }
        public void Mock_IndexModelContainsReviews_Collection() // Confirms presence of known entry
        {
            // Arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            testReview = new Review();

            testReview.Author      = "Joey Muncher";
            testReview.ContentBody = "Great gummis, love them!";
            testReview.Rating      = 5;
            testReview.ReviewId    = 1;

            // Act
            ViewResult    indexView  = controller.Index() as ViewResult;
            List <Review> collection = indexView.ViewData.Model as List <Review>;

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }
Beispiel #3
0
        public void Mock_ConfirmReviewEntry_Test()
        {
            // Arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            int    ReviewId    = 1;
            string Author      = "Maya";
            string ContentBody = "Awesome!";
            int    Rating      = 4;
            int    ProductId   = 1;
            Review testReview  = new Review(ReviewId, Author, ContentBody, Rating, ProductId);

            // Act
            ViewResult indexView  = controller.Index() as ViewResult;
            var        collection = indexView.ViewData.Model as List <Review>;

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }
Beispiel #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));
            }
        }
Beispiel #5
0
        public void DB_CreatesNewReviews_Collection()
        {
            //arrange
            ReviewsController  controller      = new ReviewsController(db);
            ProductsController otherController = new ProductsController(pdb);
            Product            testProduct     = new Product("Sponge", "Sponges up liquids", (decimal)1.99);
            Review             testReview      = new Review("bob", "this is a great sponge", 5);

            //act
            otherController.Create(testProduct);
            testReview.ProductId = testProduct.ProductId;
            controller.Create(testReview);


            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>;

            //assert
            CollectionAssert.Contains(collection, testReview);
        }
Beispiel #6
0
        public void TestDb_Create_AddsToDb()
        {
            DbSetUp();
            ReviewsController controller     = new ReviewsController(db);
            ItemsController   itemController = new ItemsController(dbItem);
            Item testItem = new Item {
                ItemId = 7, Description = "Gummi Bears!", Name = "Gummi Bears", Cost = 1
            };
            Review testReview = new Review {
                ReviewId = 1, Body = "A Review", Rating = 4, UserName = "******", ItemId = 2
            };

            itemController.Create(testItem);
            controller.Create(testReview);
            var collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>;

            CollectionAssert.Contains(collection, testReview);
            db.RemoveAll();
        }
Beispiel #7
0
        public void Mock_PostViewResultCreate_ViewResult()
        {
            // Arrange
            Review testReview = new Review
            {
                ReviewId = 4,
                Author   = "Darwin"
            };

            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Create(testReview) as ViewResult;


            // Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
        }
Beispiel #8
0
        public async Task DeleteGet_NoReview()
        {
            // Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

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

                // Act
                var result = await controller.Delete(id);

                // Assert
                Assert.IsNotNull(result);
                var objResult = result as NotFoundResult;
                Assert.IsNotNull(objResult);
            }
        }
Beispiel #9
0
        public async Task CreateGet_OutOfRange()
        {
            // Arrange
            var repo         = new FakeReviewRepository(TestData.Reviews());
            var purchaseRepo = new FakePurchaseService(TestData.Purchases());

            using (var controller = new ReviewsController(repo, purchaseRepo, new NullLogger <ReviewsController>()))
            {
                var id = -9;

                // Act
                var result = await controller.Create(id);

                // Assert
                Assert.IsNotNull(result);
                var objResult = result as BadRequestObjectResult;
                Assert.IsNotNull(objResult);
            }
        }
        public void Post_DeleteReviewShouldRedirectToHomeForNonExistingReview()
        {
            //Arrange
            var controller = new ReviewsController(null, this.reviewService.Object, null);

            this.reviewService.Setup(r => r.Delete(It.IsAny <int>()))
            .Returns(false);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var result = controller.Delete(ReviewId, CompanyId, true);

            //Assert
            this.AssertRedirectToHome(result);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, WebConstants.Entity.Review, ReviewId));
        }
Beispiel #11
0
        public void Mock_IndexModelContainsReviews_Collection() // Confirms presence of known entry
        {
            // Arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            testReview = new Review();

            testReview.Author     = "Soma";
            testReview.Content    = "Good";
            testReview.Rating     = 2;
            testReview.ReviewId   = 1;
            testReview.PropertyId = 2;
            // Act
            ViewResult    indexView  = controller.Index() as ViewResult;
            List <Review> collection = indexView.ViewData.Model as List <Review>;

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }
        public void TestReviewsCreate()
        {
            //Arrange
            FakeRestaurantRepository fakeRestaurantRepository = new FakeRestaurantRepository();
            FakeReviewRepository     fakeReviewRepository     = new FakeReviewRepository();
            ReviewsController        controller = new ReviewsController(fakeRestaurantRepository, fakeReviewRepository);
            ReviewsCreateVM          vm         = new ReviewsCreateVM(fakeRestaurantRepository);
            string e2RestName = "McD";

            //Act
            var result  = controller.Create(vm) as ActionResult;
            var result2 = controller.Create(1) as ViewResult;
            var data2   = result2.Model as ReviewsCreateVM;

            //Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result2);
            Assert.AreEqual(e2RestName, data2.Restaurants.First(x => x.ID == data2.Review.RestaurantID).Name);
        }
        public void Mock_PostViewResultCreate_ViewResult()
        {
            // Arrange
            Review testReview = new Review
            {
                ReviewId = 1,
                Author   = "Gummi Bear"
            };

            SetUpTheMockDb();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Create(testReview);


            // Assert
            Assert.IsInstanceOfType(resultView, typeof(RedirectToActionResult));
        }
Beispiel #14
0
        public void DB_PostIndexReviews_Review()
        {
            //Arrange
            ReviewsController controller = new ReviewsController(db);
            Review            review1    = new Review();

            review1.ReviewId     = 1;
            review1.Author       = "A";
            review1.Content_Body = "awesome";
            review1.rating       = 1;
            review1.ProductId    = 1;

            //Act
            var           result     = (RedirectToActionResult)controller.Create(review1);
            List <Review> collection = (controller.Index() as ViewResult).ViewData.Model as List <Review>;

            //Assert
            CollectionAssert.Contains(collection, review1);
            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
        public void Mock_PostViewResultCreate_ViewResult()
        {
            // Arrange
            Review testReview = new Review
            {
                ReviewId    = 1,
                Description = "Wash the dog",
                Rating      = 5
            };

            DbSetup2();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Create(testReview) as ViewResult;


            // Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
        }
        public void Mock_GetDetails_ReturnsView()
        {
            // Arrange
            Product testProduct = new Product
            {
                ProductId = 1,
                Name      = "Wash the dog"
            };

            DbSetup2();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Details(testProduct.ProductId) as ViewResult;
            var model      = resultView.ViewData.Model as Product;

            // Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
            Assert.IsInstanceOfType(model, typeof(Product));
        }
Beispiel #17
0
        public async Task Create_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 review = new Review {
                    Content = "This is a test review", PurchaseId = 63, Rating = 3
                };

                // Act
                var result = await controller.Create(review);

                // Assert
                Assert.IsNotNull(result);
                Assert.IsInstanceOfType(result, typeof(OkObjectResult));
            }
        }
        public void GetAllReviewsForRestaurant_DatabaseException_BadData()
        {
            //arrange
            var restaurantId = 1;

            //arrange
            MockRepository.Setup(m => m.DoseRestaurentIdExist(restaurantId))
            .Returns(true);
            MockRepository.Setup(m => m.GetReviewsForRestaurant(restaurantId))
            .Throws(new Exception());
            MockIdentity.Setup(m => m.GetRequestingUserId()).Returns(10);

            var ctrl = new ReviewsController(MockRepository.Object, MockLogger.Object, MockIdentity.Object);

            //act
            var actionResult = ctrl.Get(restaurantId);

            // assert
            Assert.IsInstanceOfType(actionResult, typeof(BadRequestResult));
        }
Beispiel #19
0
        public void DB_CreatesNewEntries_Collection()
        {
            // Arrange
            ProductsController productController = new ProductsController(productDb);
            ReviewsController  reviewController  = new ReviewsController(reviewDb);
            Product            testProduct       = new Product {
                ProductId = 1, Name = "Giant Gummi", Description = "12 oz. gummi bear", Cost = 4.99m, ImageUrl = "https://i.ytimg.com/vi/1CbfG0epWHo/maxresdefault.jpg"
            };
            Review testReview = new Review {
                ReviewId = 1, Title = "Love It!", Author = "Sara", Content_Body = "This is the best gummy bear I have ever had.", Rating = 5, ProductId = 1
            };

            // Act
            productController.Create(testProduct);
            reviewController.Create(testReview);
            var collection = (reviewController.Index() as ViewResult).ViewData.Model as List <Review>;

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }
Beispiel #20
0
        public void Mock_GetDetails_ReturnsView()
        {
            // Arrange
            Review testReview = new Review
            {
                ReviewId = 4,
                Author   = "Darwin"
            };

            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Details(testReview.ReviewId) as ViewResult;
            var model      = resultView.ViewData.Model as Review;

            // Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
            Assert.IsInstanceOfType(model, typeof(Review));
        }
        public void Post_ShouldRedirectToHomeWhenCompanyDoesNotExist()
        {
            //Arrange
            var controller = new ReviewsController(this.fixture.UserManagerMockInstance.Object, null, this.companyService.Object);

            this.companyService.Setup(c => c.Exists(It.IsAny <string>()))
            .Returns(false);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var form   = this.GetReviewForm();
            var result = controller.Add(form);

            //Assert
            this.AssertRedirectToHome(result);
            this.customMessage.Should().Be(WebConstants.Message.InvalidCompany);
        }
        public void Post_EditReviewShouldRedirectToHomeWhenReviewDoesNotExist()
        {
            //Arrange
            var controller = new ReviewsController(null, this.reviewService.Object, null);

            this.reviewService.Setup(r => r.Edit(It.IsAny <int>(), It.IsAny <string>()))
            .Returns(false);

            this.PrepareTempData();

            controller.TempData = this.tempData.Object;

            //Act
            var form   = this.GetReviewForm();
            var result = controller.Edit(ReviewId, form);

            //Assert
            this.AssertRedirectToHome(result);
            this.customMessage.Should().Be(string.Format(WebConstants.Message.NonExistingEntity, WebConstants.Entity.Review, ReviewId));
        }
        public async Task ThrowsBadRequestWhenReviewWasNotCreatedNotFoundReviewId()
        {
            var reviewServiceMock = new Mock <IReviewService>();

            var sut = new ReviewsController(reviewServiceMock.Object);

            var reviewViewModel = new ReviewViewModel()
            {
                Id = 3,
                OriginalDescription = null,
                BusinessUnitId      = 1,
                Rating = 1
            };

            reviewServiceMock.Setup(x => x.CreateReviewAsync(reviewViewModel.OriginalDescription, reviewViewModel.BusinessUnitId, reviewViewModel.Rating)).ReturnsAsync(TestHelpersReviewController.TestReviewDTO01());

            var actionResult = await sut.Create(reviewViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }
        public async Task Succeed()
        {
            var reviewServiceMock = new Mock <IReviewService>();

            var sut = new ReviewsController(reviewServiceMock.Object);

            var reviewViewModel = new ReviewViewModel()
            {
                Id = 1,
                OriginalDescription = "This is first review",
                BusinessUnitId      = 1,
                Rating = 1
            };

            reviewServiceMock.Setup(x => x.CreateReviewAsync(reviewViewModel.OriginalDescription, reviewViewModel.BusinessUnitId, reviewViewModel.Rating)).ReturnsAsync(TestHelpersReviewController.TestReviewDTO01());

            var actionResult = await sut.Create(reviewViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(OkObjectResult));
        }
        public async Task ThrowsBadRequestWhenReviewCreateReturnsArgumentException()
        {
            var reviewServiceMock = new Mock <IReviewService>();

            var sut = new ReviewsController(reviewServiceMock.Object);

            var reviewViewModel = new ReviewViewModel()
            {
                Id = 1,
                OriginalDescription = new string('a', 1000),
                BusinessUnitId      = 1,
                Rating = 1
            };

            reviewServiceMock.Setup(x => x.CreateReviewAsync(reviewViewModel.OriginalDescription, reviewViewModel.BusinessUnitId, reviewViewModel.Rating)).ThrowsAsync(new ArgumentException());

            var actionResult = await sut.Create(reviewViewModel);

            Assert.IsInstanceOfType(actionResult, typeof(BadRequestObjectResult));
        }
        public void Setup()
        {
            product = new Product
            {
                Reviews =
                {
                    new Review(),
                    new Review()
                }
            };

            productRepository = new FakeRepository <Product>(id =>
            {
                product.Id = id;
                return(product);
            });

            reviewRepository = MockRepositoryBuilder.CreateReviewRepository();

            commentRepository = MockRepository.GenerateStub <IRepository <IComment> >();

            var comments = new List <IComment>
            {
                new Comment {
                    Approved = true
                },
                new Comment {
                    Approved = false
                },
                new Review {
                    Approved = true
                },
                new Comment {
                    Approved = true
                }
            }.AsQueryable();

            commentRepository.Stub(r => r.GetAll()).Return(comments);

            controller = new ReviewsController(reviewRepository, productRepository, commentRepository);
        }
        public async Task Index_WithCorrectPage_ShouldReturnViewResultWithValidViewModel()
        {
            const int page          = 3;
            const int totalElements = 20;

            //Arrange
            Mock <IModeratorReviewService> moderatorReviewService = new Mock <IModeratorReviewService>();

            moderatorReviewService
            .Setup(m => m.GetAllListingAsync(page))
            .ReturnsAsync(new List <ReviewAdvancedServiceModel>()
            {
                new ReviewAdvancedServiceModel()
            });

            Mock <IReviewService> reviewService = new Mock <IReviewService>();

            reviewService
            .Setup(r => r.TotalCountAsync(true))
            .ReturnsAsync(totalElements);

            ReviewsController reviewsController = new ReviewsController(moderatorReviewService.Object, reviewService.Object);

            //Act
            var result = await reviewsController.Index(page);

            //Assert
            result.Should().BeOfType <ViewResult>();

            result.As <ViewResult>().Model.Should().BeOfType <PagingElementsViewModel <ReviewAdvancedServiceModel> >();

            PagingElementsViewModel <ReviewAdvancedServiceModel> model = result.As <ViewResult>().Model.As <PagingElementsViewModel <ReviewAdvancedServiceModel> >();

            model.Elements.Should().HaveCount(1);
            model.Pagination.CurrentPage.Should().Be(page);
            model.Pagination.PreviousPage.Should().Be(2);
            model.Pagination.NextPage.Should().Be(4);
            model.Pagination.TotalPages.Should().Be(4);
            model.Pagination.TotalElements.Should().Be(totalElements);
            model.Pagination.PageSize.Should().Be(ReviewPageSize);
        }
        public async Task UpdateReview_ReturnsNoContent_WhenReviewUpdated()
        {
            // arrange
            var controller = new ReviewsController(_context);

            // act
            var result = await controller.UpdateReview(1, new Review {
                Id          = 1,
                Description = "I updated my review!",
                ProgramId   = 6,
                CourseId    = 3,
                SchoolId    = 1,
                Rating      = 4,
                CampusId    = 1,
                InterestId  = 1,
                UsersId     = 1
            });

            // assert
            Assert.IsType <NoContentResult>(result);
        }
        public void Mock_PostViewResultCreate_ViewResult()
        {
            // Arrange
            Review testReview = new Review
            {
                ReviewId    = 1,
                Author      = "Joey Chompers",
                ContentBody = "Great gummis, love them!",
                Rating      = 5
            };

            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            var resultView = controller.Create(testReview) as ViewResult;


            // Assert
            Assert.IsInstanceOfType(resultView, typeof(ViewResult));
        }
        public async Task CreateReview_ReturnsOkObjectResult_WhenInsertingReview()
        {
            // arrange
            var controller = new ReviewsController(_context);

            // act
            var result = await controller.CreateReview(new Review {
                Id          = 4,
                Description = "Good course!",
                ProgramId   = 6,
                CourseId    = 3,
                SchoolId    = 1,
                Rating      = 4,
                CampusId    = 1,
                InterestId  = 1,
                UsersId     = 1
            });

            // assert
            Assert.IsType <OkObjectResult>(result);
        }
        public void PlanetAreaControllerTestsSetup()
        {
            var automapperConfig = new AutoMapperConfig();
            automapperConfig.Execute(typeof(ReviewsController).Assembly);

            var reviewsServiceMock = new Mock<IReviewsService>();
            reviewsServiceMock
                .Setup(x => x.GetById(reviewId))
                .Returns(new Review()
                {
                    Content = reviewContent,
                    Category = new Category() { Name = "Some" }
                });

            reviewsServiceMock
                .Setup(x => x.GetByPageAndCategory(category, page))
                .Returns(new List<Review>()
                {
                    new Review
                    {
                        Content = reviewContent,
                        Category = new Category() { Name = "Some" },
                        GameTitle = gameTitle
                    },
                    new Review
                    {
                        Content = reviewContent,
                        Category = new Category() { Name = "Some" },
                        GameTitle = gameTitle
                    }
                }.AsQueryable());

            var categoriesServiceMock = new Mock<ICategoriesService>();
            
            reviewsController = new ReviewsController(reviewsServiceMock.Object, categoriesServiceMock.Object);
        }