示例#1
0
        public void Parks_PingReturnsParkDetail()
        {
            Mock <HttpSessionStateBase> mockSession = new Mock <HttpSessionStateBase>();

            mockSession.Object["ParkCode"] = "GND";

            Mock <HttpContextBase> mockContext = new Mock <HttpContextBase>();

            mockContext.Setup(c => c.Session).Returns(mockSession.Object);

            var fakePark = new ParkModel()
            {
                ParkCode = "GND",
                ParkName = "GinaNatalieDan"
            };

            Mock <IParkInfoSqlDAL> mockParkInfo = new Mock <IParkInfoSqlDAL>();

            mockParkInfo.Setup(m => m.GetParkInfo("GND")).Returns(fakePark);
            mockParkInfo.Setup(m => m.GetAllParks()).Returns(new List <ParkModel>()
            {
                fakePark
            });
            ParkController controller = new ParkController(mockParkInfo.Object);

            controller.ControllerContext = new ControllerContext(mockContext.Object, new System.Web.Routing.RouteData(), controller);
            var result = controller.ParkDetail("GND");

            Assert.IsTrue(result is ViewResult);
            var viewResult = result as ViewResult;

            Assert.AreEqual("ParkDetail", viewResult.ViewName);
        }
        public void TestGetParkDetail()
        {
            //Arrange
            ParkMockDAO    parkDAO    = new ParkMockDAO();
            WeatherMockDAO weatherDAO = new WeatherMockDAO();
            ParkController controller = new ParkController(weatherDAO, parkDAO);

            //Act
            Park          park   = parkDAO.GetParkDetail("CVNP");
            IActionResult result = controller.ParkDetail("CVNP");

            //Assert
            ViewResult vr = result as ViewResult;

            Assert.IsNotNull(vr);

            Assert.AreEqual("CVNP", park.ParkCode);
            Assert.AreEqual("Ohio", park.State);
            Assert.AreEqual("Woodland", park.Climate);
        }