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 SurveyController_DetailsAction_ReturnDetailsView() { //Arrange Mock <IWeatherDAO> mockIWeatherDAO = new Mock <IWeatherDAO>(); Mock <IParkDAO> mockIParkDAO = new Mock <IParkDAO>(); ParkController controller = new ParkController(mockIParkDAO.Object, mockIWeatherDAO.Object); // Weird stuff var httpContextMock = new Mock <HttpContextBase>(); var sessionMock = new Mock <HttpSessionStateBase>(); sessionMock.Setup(n => n["TempUnit"]).Returns('F'); httpContextMock.Setup(n => n.Session).Returns(sessionMock.Object); sessionMock.Setup(n => n["ShouldUnitChange"]).Returns(false); httpContextMock.Setup(n => n.Session).Returns(sessionMock.Object); controller.ControllerContext = new ControllerContext(httpContextMock.Object, new RouteData(), controller); //Act // Cast ActionResult to ViewResult string paraString = "CVNP"; ViewResult result = controller.Details(paraString) as ViewResult; //Assert Assert.AreEqual("Details", result.ViewName); mockIWeatherDAO.Verify(m => m.GetForcast(paraString)); //verify that our test called GetForcast on the Mock IWeatherDAL }
public void HomeController() { //PArk controller test var controller = new ParkController(parkDAL, weatherDAL); //Index Action should return index view var result = controller.Index() as ViewResult; Assert.AreEqual("Index", result.ViewName); }
public void HomeController_IndexAction_ReturnIndexView() { //Arrange ParkController controller = new ParkController(); //Act ViewResult result = controller.Index() as ViewResult; //Assert Assert.AreEqual("Index", result.ViewName); }
public void TestGetAllParks() { //Arrange ParkMockDAO parkDAO = new ParkMockDAO(); WeatherMockDAO weatherDAO = new WeatherMockDAO(); ParkController controller = new ParkController(weatherDAO, parkDAO); //Act IList <Park> parks = parkDAO.GetAllParks(); //Assert Assert.AreEqual(parks.Count, 5, "Testing the number of Parks returned"); }
public void Parks_PingReturnsParkView() { Mock <IParkInfoSqlDAL> mockParkInfo = new Mock <IParkInfoSqlDAL>(); mockParkInfo.Setup(m => m.GetAllParks()); ParkController controller = new ParkController(mockParkInfo.Object); var result = controller.Parks(); Assert.IsTrue(result is ViewResult); var viewResult = result as ViewResult; Assert.AreEqual("Parks", viewResult.ViewName); }
public void ParkController_IndexAction_ReturnIndexView() { //Arrange Mock <IWeatherDAO> mockIWeatherDAO = new Mock <IWeatherDAO>(); Mock <IParkDAO> mockIParkDAO = new Mock <IParkDAO>(); ParkController controller = new ParkController(mockIParkDAO.Object, mockIWeatherDAO.Object); //Act // Cast ActionResult to ViewResult ViewResult result = controller.Index() as ViewResult; //Assert Assert.AreEqual("Index", result.ViewName); mockIParkDAO.Verify(m => m.GetAllParks()); //verify that our test called GetAllParks on the Mock IParkDAL }
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); }
public void TestMethod1() { ParkController _pcontroller = new ParkController(_restApiContext); Ticket ticket = new Ticket(); ticket.Id = 2; var t = _pcontroller.Post(ticket); LoginController _lcontroller = new LoginController(); RestApi2.Login login = new RestApi2.Login(); login.id = 1; login.password = "******"; login.username = "******"; var a = _lcontroller.Post(login); var b = a; }
public void ParkController_ChangeTemperatureUnit_ChangesSessionAndReturnsRedirect() { //Arrange Mock <IWeatherDAO> mockIWeatherDAO = new Mock <IWeatherDAO>(); Mock <IParkDAO> mockIParkDAO = new Mock <IParkDAO>(); ParkController controller = new ParkController(mockIParkDAO.Object, mockIWeatherDAO.Object); string parameterString = "Boya!"; // More Weird stuff var httpContextMock = new Mock <HttpContextBase>(); var sessionMock = new Mock <HttpSessionStateBase>(); // sessionMock.Setup(n => n["ShouldUnitChange"]).Returns(false); httpContextMock.Setup(n => n.Session).Returns(sessionMock.Object); controller.ControllerContext = new ControllerContext(httpContextMock.Object, new RouteData(), controller); //Act RedirectToRouteResult result = controller.ChangeTemperatureUnit(parameterString) as RedirectToRouteResult; //Assert Assert.IsNotNull(result); Assert.AreEqual("Details", result.RouteValues["action"]); }