예제 #1
0
        public void ReviewIndexViewContainsListOfReviewModels()
        {
            //Arrange
            var mock = new Mock <IReviewRepository>();

            mock.Setup(d => d.Reviews).Returns(new[]
            {
                new Review {
                    Id = 1, EmployeeId = 2
                },
                new Review {
                    Id = 2, EmployeeId = 4
                },
                new Review {
                    Id = 3, EmployeeId = 1
                }
            }.AsQueryable());

            var controller = new ReviewController(mock.Object);

            //Act
            var actual = (List <Review>)controller.Index().Model;

            //Assert
            Assert.IsNotNull(actual);
            Assert.IsInstanceOf <List <Review> >(actual);
        }
예제 #2
0
        public void Review_Index()
        {
            var ctrl   = new ReviewController("reviews.json");
            var result = ctrl.Index();

            Assert.IsNotNull(result);
        }
        public void TestFilledReviews()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new HomeMyDayDbContext(optionsBuilder.Options);

            context.Reviews.Add(new Review()
            {
                Id            = 1,
                Name          = "TestReview",
                Accommodation = new Accommodation()
                {
                    Id = 1, Name = "TestAccommodation"
                },
                Approved = true,
                Date     = DateTime.Now,
                Title    = "Test",
                Text     = "Dit was een goede vakantie!"
            });

            context.SaveChanges();

            IReviewRepository reviewRepository = new EFReviewRepository(context, null);
            IReviewManager    reviewManager    = new ReviewManager(reviewRepository);

            var target = new ReviewController(reviewManager);

            var result = target.Index();
            var model  = result.Model as IEnumerable <ReviewViewModel>;

            Assert.NotNull(model);
            Assert.Equal("TestReview", model.FirstOrDefault().Name);
        }
예제 #4
0
        public void Index_Valid_Data()
        {
            //Arrange
            var reviews = new List <GoodReview>
            {
                new GoodReview {
                    Id = 1, IsVisibleForAll = true
                },
                new GoodReview {
                    Id = 2, IsVisibleForAll = false
                },
                new GoodReview {
                    Id = 3, IsVisibleForAll = true
                }
            };

            foreach (var review in reviews)
            {
                context.Add(review);
            }
            context.SaveChanges();

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

            //Assert
            Assert.IsAssignableFrom <List <GoodReview> >(result);
            Assert.AreEqual(1, ((IEnumerable <GoodReview>)result).Count());
        }
예제 #5
0
        public void GetAllReviews()
        {
            var result = sut.Index(1);

            Assert.IsNotNull(result);

            MockConnection.CloseConnection();
        }
예제 #6
0
        public void Mock_GetViewResultIndex_Test()
        {
            DbSetup();
            ReviewController controller = new ReviewController();

            var result = controller.Index();

            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
예제 #7
0
        public void Index()
        {
            //Arrange
            ReviewController controller = new ReviewController();

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

            // Assert
            Assert.IsNotNull(result);
        }
 private void LoadReviewsGridByBookId(int id)
 {
     try
     {
         List <Review> load = reviewsController.Index().Where(r => r.BookID == id).ToList();
         if (load != null)
         {
             reviewDataGrid.ItemsSource = load;
         }
     }
     catch (Exception e) { }
 }
예제 #9
0
        public void Mock_GetViewResultIndex_ActionResult()
        {
            //Arrange
            Dispose();
            DbSetup();
            ReviewController controller = new ReviewController(mock.Object);

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

            //Assert
            Assert.IsInstanceOfType(result, typeof(ActionResult));
        }
예제 #10
0
        public void IndexGetViewNotNull()
        {
            // Arrange
            var mock = new Mock <IRentService>();

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

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

            // Assert
            Assert.That(result, Is.Not.Null);
        }
예제 #11
0
        public void Review_Index_PageIndex_Four()
        {
            var ctrl   = new ReviewController("reviews.json");
            var result = ctrl.Index(pageNumber: 4) as ViewResult;

            Assert.IsNotNull(result);
            var model = result.Model as ReviewsViewModel;

            Assert.IsNotNull(model);
            Assert.AreEqual(4, model.PageNumber);
            Assert.AreEqual(4, model.PageCount);
            Assert.IsFalse(model.IsNextPageEnabled);
            Assert.IsTrue(model.IsPreviousPageEnabled);
        }
예제 #12
0
        public void IndexGetViewModelNotNull()
        {
            // Arrange
            var mock = new Mock <IRentService>();

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

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

            // Assert
            // ReSharper disable once PossibleNullReferenceException
            Assert.That(result.Model, Is.Not.Null);
        }
예제 #13
0
        public void DB_CreateNewReview_Test()
        {
            ReviewController controller = new ReviewController(db);
            Review           testReview = new Review();

            testReview.ReviewId    = 1;
            testReview.Author      = "Matt";
            testReview.ContentBody = "Best chili I've ever had!";
            testReview.Rating      = 4;
            testReview.ProductId   = 1;

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

            CollectionAssert.Contains(collection, testReview);
        }
예제 #14
0
        public void Mock_ConfirmEntry_Test()
        {
            DbSetup();
            ReviewController controller = new ReviewController(mock.Object);
            Review           testReview = new Review();

            testReview.ReviewId    = 1;
            testReview.Author      = "Lois";
            testReview.ContentBody = "What a wonderful product!";
            testReview.Rating      = 4;
            testReview.ProductId   = 1;

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

            CollectionAssert.Contains(collection, testReview);
        }
        public void TestEmptyReviews()
        {
            var optionsBuilder = new DbContextOptionsBuilder <HomeMyDayDbContext>();

            optionsBuilder.UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new HomeMyDayDbContext(optionsBuilder.Options);
            IReviewRepository reviewRepository = new EFReviewRepository(context, null);
            IReviewManager    reviewManager    = new ReviewManager(reviewRepository);

            var target = new ReviewController(reviewManager);

            var result = target.Index();
            var model  = result.Model as IEnumerable <ReviewViewModel>;

            Assert.NotNull(model);
            Assert.True(!model.Any());
        }
예제 #16
0
        public void Mock_IndexModelContainsProducts_Collection()
        {
            //Arrange
            Dispose();
            DbSetup();
            ReviewController controller = new ReviewController(mock.Object);
            Review           review     = new Review {
                ProductId = 1, Title = "Test Rock", ReviewText = "Yum. Gummy Rock. Igneous Delicious!", UserId = 1, Rating = 5
            };

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

            //Assert
            CollectionAssert.Contains(collection, review);
        }
예제 #17
0
        public void IndexPostViewModelNotNull()
        {
            // Arrange
            var mockRentService = new Mock <IRentService>();

            mockRentService.Setup(a => a.GetReviews()).Returns(new List <ReviewDTO>());

            var controller = new ReviewController(mockRentService.Object);

            controller.ControllerContext = new FakeControllerContext(controller);

            // Act
            PartialViewResult result = controller.Index(new ReviewViewModel()) as PartialViewResult;

            // Assert
            // ReSharper disable once PossibleNullReferenceException
            Assert.That(result.Model, Is.Not.Null);
        }
예제 #18
0
        public void Index_Returns_A_View()
        {
            var result = underTest.Index();

            Assert.IsType <ViewResult>(result);
        }
        public void Index_Returns_A_View()
        {
            var result = sut.Index(1);

            Assert.IsType <ViewResult>(result);
        }