Пример #1
0
        public void TestAddAndRemoveHomes()
        {
            Guid nhid = new Guid("6B696DBE-616C-4421-9011-D080354977B6");
            var context = new ControllerContext();
            context.RouteData.Values.Add("nhid", nhid.ToString());

            var controller = new HomeController();
            controller.ControllerContext = context;

            var result = controller.AddHome("newAddress", 70, -30);
            ViewResult listAction;
            IEnumerable<Home> listOfHomes = null;
            try
            {
                Assert.AreEqual("Homes", ((RedirectToRouteResult)result).RouteValues["action"].ToString());

                listAction = controller.Homes();

                listOfHomes = (IEnumerable<Home>) controller.ViewData.Model;

                Assert.IsTrue(listOfHomes.Any(h => h.AddressFull == "newAddress"));
            } finally
            {

                //Guid homeId;
                if (listOfHomes != null)
                {
                    Guid homeId = listOfHomes.Single(h => h.AddressFull == "newAddress").Id;
                    controller.RemoveHome(homeId);
                    listAction = controller.Homes();
                    listOfHomes = (IEnumerable<Home>)controller.ViewData.Model;
                    Assert.IsFalse(listOfHomes.Any(h => h.AddressFull == "newAddress"));

                    bool isThere = false;
                    try
                    {
                        var home = new HOAHome.Repositories.HomeRepository().Get(homeId);
                        isThere = true;
                    }catch
                    {
                    }
                    Assert.IsFalse(isThere,"Home did not get deleted");
                }

            }
        }
Пример #2
0
        public void ListHomeTest()
        {
            var factory = new FakeRepositoryFactory();
            var controller = new HomeController(factory);
            Guid nhid = Guid.NewGuid();
            var context = new ControllerContext();
            context.RouteData.Values.Add("nhid", nhid.ToString());
            controller.ControllerContext = context;

            factory.MockNeighborhoodRepository.Setup(n => n.GetHomes(nhid)).Returns(TestHomes.ToList());

            var result = controller.Homes();

            factory.MockHomeRepository.VerifyAll();

            // Assert.AreEqual("Homes", result.ViewName);
            Assert.AreEqual(TestHomes.First().AddressFull, ((IList<Home>)result.ViewData.Model).First().AddressFull);
        }
Пример #3
0
        public void AddHomeTest()
        {
            var factory = new FakeRepositoryFactory();
            var controller = new HomeController(factory);
            Guid nhid = Guid.NewGuid();
            var context = new ControllerContext();
            context.RouteData.Values.Add("nhid", nhid.ToString());
            controller.ControllerContext = context;

            var home = new Home();
            factory.MockHomeRepository.Setup(hr => hr.GetOrCreateHome("newAddress", 1, 1)).Returns(home);
            factory.MockHomeRepository.Setup(hr => hr.SaveChanges());

            factory.MockNeighborhoodRepository.Setup(nr => nr.AddHome(nhid, home));
            factory.MockNeighborhoodRepository.Setup(nr => nr.SaveChanges());

            var result = controller.AddHome("newAddress", 1, 1);

            factory.MockHomeRepository.VerifyAll();
            factory.MockNeighborhoodRepository.VerifyAll();

            Assert.AreEqual("Homes", ((RedirectToRouteResult)result).RouteValues["action"].ToString());
        }
Пример #4
0
        private static HomeController GetHomeController(Guid nhid)
        {
            var context = new ControllerContext();
            context.RouteData.Values.Add("nhid", nhid.ToString());

            var controller = new HomeController();
            controller.ControllerContext = context;
            return controller;
        }