public void DB_Edit_test()
        {
            ReviewsController  reviewController  = new ReviewsController(db);
            ProductsController productController = new ProductsController(db2);
            Product            testproduct       = new Product("Chips", 2.00, "USA");

            testproduct.ProductId = 1;
            Review testReview = new Review();

            testReview.ReviewId    = 1;
            testReview.Author      = "Ellie";
            testReview.ContentBody = "This is some content from Ellie";
            testReview.Rating      = 3;
            testReview.ProductId   = 1;

            productController.Create(testproduct);
            reviewController.Create(testReview);

            testReview.Author = "Eli";
            reviewController.Edit(testReview);

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

            Assert.AreEqual(testReview.Author, "Eli");
        }
Esempio n. 2
0
        public void DB_EditEntry_Test()
        {
            ReviewsController  controller  = new ReviewsController(reviewDb);
            ProductsController controller2 = new ProductsController(db);

            Product testProduct = new Product();

            testProduct.ProductId = 1;
            testProduct.Name      = "Pepperoni";
            testProduct.Cost      = 12.75;
            testProduct.Country   = "USA";

            controller2.Create(testProduct);

            Review testReview = new Review();

            testReview.Author       = "Jesse";
            testReview.Content_Body = "Wow";
            testReview.Rating       = 4;
            testReview.ProductId    = 1;

            controller.Create(testReview);

            testReview.Author = "Kaili";
            controller.Edit(testReview);

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

            Assert.AreEqual(testReview.Author, "Kaili");
        }
        public async Task Index_WithPageBiggerThanOneAndBiggerThanTotalPages_ShouldReturnToIndex()
        {
            const int page          = 10;
            const int totalElements = 10;

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

            moderatorReviewService
            .Setup(m => m.GetAllListingAsync(page))
            .ReturnsAsync(new List <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 <RedirectToActionResult>();

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
        }
Esempio n. 4
0
        public void Index_Action_Model_Is_Three_Reviews()
        {
            var controller = new ReviewsController(_db);
            var result     = controller.Index() as ViewResult;
            var model      = result.Model as IEnumerable <Review>;

            Assert.AreEqual(3, model.Count());
        }
        public void Mock_GetViewResultIndex_ActionResult() // Confirms route returns view
        {
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            var result = controller.Index(mockProduct.Object.Products.FirstOrDefault().ProductId);

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
 public void Index_displays_unapproved_reviews()
 {
     controller.Index()
     .ReturnsViewResult()
     .ForView("Index")
     .WithModel <IEnumerable <IComment> >()
     .AssertAreEqual(1, x => x.Count());
 }
        public void Mock_GetViewResultIndex_Test() //confirms route returns view
        {
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);

            var result = controller.Index();

            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
Esempio n. 8
0
        public void Mock_GetViewResultIndex_ActionResult()
        {
            DbSetUp();
            ReviewsController controller = new ReviewsController(mock.Object);

            var result = controller.Index();

            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
        public void IndexTest()
        {
            //Arrange
            ReviewsController reviewsController = new ReviewsController();
            //Act
            var result = reviewsController.Index(2);

            //Assert
            Assert.IsNotNull(result);
        }
        public void Mock_IndexModelContainsProducts_Collection()
        {
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            int productId = mockProduct.Object.Products.FirstOrDefault().ProductId;

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

            Assert.IsInstanceOfType(collection, typeof(List <Review>));
        }
Esempio n. 11
0
        public void ReviewIndex()
        {
            // Arrange
            ReviewsController controller = new ReviewsController();

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
        }
Esempio n. 12
0
        public void Mock_GetViewResultIndex_Test()
        {
            DbSetup();
            //Arrange
            var reviewController = new ReviewsController(mock.Object);
            //Act
            var result = reviewController.Index();

            //Assert
            Assert.IsInstanceOfType(result, typeof(IActionResult));
        }
Esempio n. 13
0
        public void Mock_GetListOfReviewIndex_Test()
        {
            DbSetup();
            //Arrange
            var reviewController = new ReviewsController(mock.Object);
            var indexViewResult  = reviewController.Index() as ViewResult;
            //Act
            var result = indexViewResult.ViewData.Model as List <Review>;

            //Assert
            Assert.IsInstanceOfType(result, typeof(List <Review>));
        }
Esempio n. 14
0
        public void Mock_GetViewResultIndex_ActionResult()
        {
            //Arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(reviewMock.Object);

            //Act
            var result = controller.Index();

            //Assert
            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
        public void Mock_GetViewResultIndex_ActionResult() // Confirms route returns view
        {
            //Arrange
            DbSetup2();
            ReviewsController controller = new ReviewsController(mock.Object);

            //Act
            var result = controller.Index();

            //Assert
            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
        public void TestReviewsIndex()
        {
            //Arrange
            FakeRestaurantRepository fakeRestaurantRepository = new FakeRestaurantRepository();
            FakeReviewRepository     fakeReviewRepository     = new FakeReviewRepository();
            ReviewsController        controller = new ReviewsController(fakeRestaurantRepository, fakeReviewRepository);

            //Act
            var result = controller.Index("byRevName") as ViewResult;

            //Assert
            Assert.IsNotNull(result);
        }
Esempio n. 17
0
        public void Mock_ConfirmEntryExists_Test()
        {
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            var testReview = new Review {
                ReviewId = 1, Author = "Jesse", Content_Body = "So good.", Rating = 5, ProductId = 1
            };

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

            CollectionAssert.Contains(collection, testReview);
        }
        public async Task Index_WithPageLessThanOneOrEqualToZero_ShouldReturnToIndex(int page)
        {
            //Arrange
            ReviewsController reviewsController = new ReviewsController(null, null);

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

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

            result.As <RedirectToActionResult>().ActionName.Should().Be("Index");
        }
Esempio n. 19
0
        public void Mock_IndexContainsReviews_Collection()
        {
            DbSetUp();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            review     = new Review {
                ReviewId = 1, Body = "A Review", Rating = 4, UserName = "******"
            };

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

            CollectionAssert.Contains(collection, review);
        }
Esempio n. 20
0
        public void TestMethod1()
        {
            //Arrange
            ReviewsController prodController = new ReviewsController(); // ToDo  - mock  DbContext and pass that in

            // Act
            var result = prodController.Index() as ViewResult;

            // Assert
            Assert.IsNotNull(result);
            //    Assert.IsNotNull(result.Model); // add additional checks on the Model
            Assert.IsTrue(string.IsNullOrEmpty(result.ViewName) || result.ViewName == "Index");
        }
        public void IndexGetViewNotNull()
        {
            // Arrange
            var mock = new Mock <IReviewService>();

            mock.Setup(a => a.GetReviews()).Returns(new List <ReviewDTO>());
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            Assert.That(result, Is.Not.Null);
        }
Esempio n. 22
0
        public void Index_WhenCalled_ReturnsOkResult()
        {
            //Arrange
            var builder = new DbContextOptionsBuilder <ReviewDbContext>()
                          .EnableSensitiveDataLogging()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context     = new ReviewDbContext(builder.Options);
            var _controller = new ReviewsController(context);
            // Act
            var okResult = _controller.Index();

            // Assert
            ViewResult okObjectResult = Assert.IsType <ViewResult>(okResult.Result);
        }
        public void IndexGetViewModelNotNull()
        {
            // Arrange
            var mock = new Mock <IReviewService>();

            mock.Setup(a => a.GetReviews()).Returns(new List <ReviewDTO>());
            ReviewsController controller = new ReviewsController(mock.Object);

            // Act
            ViewResult result = controller.Index() as ViewResult;

            // Assert
            // ReSharper disable once PossibleNullReferenceException
            Assert.That(result.Model, Is.Not.Null);
        }
Esempio n. 24
0
        public void testDb_Delete_RemovesFromDb()
        {
            ReviewsController controller = new ReviewsController(db);


            Review testReview = new Review {
                ReviewId = 2, Body = "A Review", Rating = 4, UserName = "******", ItemId = 1
            };


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

            CollectionAssert.DoesNotContain(collection, testReview);
        }
Esempio n. 25
0
        public void Mock_IndexContainsReviews_Collection()
        {
            //arrange
            DbSetUp();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            review     = new Review {
                ReviewId = 1, Content = "A Review", Rating = 4, Author = "Frank Ngo"
            };

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

            //assert
            CollectionAssert.Contains(collection, review);
        }
Esempio n. 26
0
        public void Mock_ReviewIndexModelContainsReviews_Collection()
        {
            //arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            testReview = new Review {
                ReviewId = 1, Author = "Bob", ContentBody = "This product is great", Rating = 5
            };

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

            //assert
            CollectionAssert.Contains(collection, testReview);
        }
Esempio n. 27
0
        public void Mock_ConfirmEntryIndex_Test()
        {
            DbSetup();
            //Arrange
            var reviewController = new ReviewsController(mock.Object);
            var indexViewResult  = reviewController.Index() as ViewResult;
            var testReview       = new Review()
            {
                ReviewId = 1, Author = "Mike", ContentBody = "Awesome", Rating = "4", ProductId = 1
            };

            //Act
            var collection = indexViewResult.ViewData.Model as List <Review>;

            //Assert
            CollectionAssert.Contains(collection, testReview);
        }
        public void Mock_ConfirmEntry_Test()
        {
            DbSetup();
            ReviewsController controller = new ReviewsController(mock.Object);
            Review            testReview = new Review();

            testReview.ReviewId    = 1;
            testReview.Author      = "Ellie";
            testReview.ContentBody = "This is some content from Ellie";
            testReview.Rating      = 3;
            testReview.ProductId   = 1;

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

            CollectionAssert.Contains(collection, testReview);
        }
Esempio n. 29
0
        public void Mock_IndexModelContainsReviews_Collection()
        {
            // Arrange
            DbSetup();
            ReviewsController controller = new ReviewsController(reviewMock.Object);
            Review            testReview = new Review();

            testReview.Title    = "Love It!";
            testReview.ReviewId = 1;

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

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }
        public void DB_CreatesNewEntries_Collection()
        {
            // Arrange
            ReviewsController controller = new ReviewsController(db);
            Review            testReview = new Review();

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

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

            // Assert
            CollectionAssert.Contains(collection, testReview);
        }