DinnersController CreateDinnersControllerAs(string userName)
        {
            var mock = new Mock<ControllerContext>();
            var nerdIdentity = FakeIdentity.CreateIdentity(userName);
            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var controller = new DinnersController(new DinnerRepository(new NerdDinners()), nerdIdentity);
            controller.ControllerContext = mock.Object;

            return controller;
        }
        public void CreateAction_With_New_Dinner_Should_Return_View_And_Repo_Should_Contain_New_Dinner()
        {
            // Arrange
            var mock = new Mock<ControllerContext>();

            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");
            var testData = FakeDinnerData.CreateTestDinners();
            var repository = new FakeDinnerRepository(testData);
            var controller = new DinnersController(repository, nerdIdentity);
            controller.ControllerContext = mock.Object;
            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var dinner = FakeDinnerData.CreateDinner();

            // Act
            ActionResult result = (ActionResult)controller.Create(dinner);

            // Assert
            Assert.AreEqual(102, repository.All.Count());
            Assert.IsInstanceOf<RedirectToRouteResult>(result);
        }
Ejemplo n.º 3
0
        public void CreateAction_With_New_Dinner_Should_Return_View_And_Repo_Should_Contain_New_Dinner()
        {
            // Arrange
            var mock = new Mock<ControllerContext>();
            mock.SetupGet(p => p.HttpContext.User.Identity.Name).Returns("ScottHa");
            mock.SetupGet(p => p.HttpContext.Request.IsAuthenticated).Returns(true);

            var repository = new NhDinnerRepository(Session);

            var controller = new DinnersController(Session, repository);
            controller.ControllerContext = mock.Object;

            var dinner = FakeDinnerData.CreateDinner();

            // Act
            ActionResult result = controller.Create(dinner);

            // Assert
            Assert.AreEqual(101, repository.FindAllDinners().Count());
            Assert.IsInstanceOf(typeof(RedirectToRouteResult), result);
        }
        public void IndexAction_With_Search_Term_Should_Filter()
        {
            // Arrange
            string searchterm = "Dinner we will be searching for (spaghetti)";

            var testData = FakeDinnerData.CreateTestDinners();
            var dinner = FakeDinnerData.CreateDinner();
            dinner.Title = searchterm;
            testData.Add(dinner);
            var repository = new FakeDinnerRepository(testData);
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            var controller = new DinnersController(repository, nerdIdentity);

            // Act
            // Get first page
            ViewResult result = (ViewResult)controller.Index("etti", null);
            PagedList<Dinner> list = result.ViewData.Model as PagedList<Dinner>;

            // Assert
            Assert.AreEqual(searchterm, list.First().Title);
        }
        public void IndexAction_With_Dinner_Just_Started_Should_Show_Dinner()
        {
            // Arrange
            var testData = FakeDinnerData.CreateTestDinners();
            var dinner = FakeDinnerData.CreateDinner();
            dinner.EventDate = DateTime.Now.AddHours(1);
            dinner.Title = "Dinner which just started";
            testData.Add(dinner);
            var repository = new FakeDinnerRepository(testData);
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            var controller = new DinnersController(repository, nerdIdentity);

            // Act
            // Get first page
            ViewResult result = (ViewResult)controller.Index(null, null);
            PagedList<Dinner> list = result.ViewData.Model as PagedList<Dinner>;

            // Assert
            Assert.AreEqual("Dinner which just started", list.First().Title);
        }