DinnersController CreateDinnersController()
        {
            var testData   = FakeDinnerData.CreateTestDinners();
            var repository = new FakeDinnerRepository(testData);

            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            return(new DinnersController(repository, nerdIdentity));
        }
Ejemplo n.º 2
0
        RSVPController CreateRSVPControllerAs(string userName)
        {
            var mock         = new Mock <ControllerContext>();
            var nerdIdentity = FakeIdentity.CreateIdentity("SomeUser");

            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var controller = CreateRSVPController();

            controller.ControllerContext = mock.Object;

            return(controller);
        }
        SearchController CreateSearchControllerAs(string userName)
        {
            var mock         = new Mock <ControllerContext>();
            var nerdIdentity = FakeIdentity.CreateIdentity(userName);

            mock.SetupGet(p => p.HttpContext.User.Identity).Returns(nerdIdentity);

            var controller = new SearchController(new DinnerRepository(new NerdDinners()));

            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);
        }
        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.Item1.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);
        }
        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.Item1.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);
        }