public void TestGetAdd()
        {
            // Arrange
            var controller = new StationsController(new StationLogic(new StationRepositoryStub()));

            // ACt
            var result = (ViewResult)controller.Add();

            // Assert
            Assert.AreEqual("", result.ViewName);
        }
        public void TestPostAddValidationError()
        {
            // Arrange
            var controller = new StationsController(new StationLogic(new StationRepositoryStub()));

            controller.ViewData.ModelState.AddModelError("StationName", "Station name should be provided!");
            var NewStation = new Station();

            // ACt
            var result = (ViewResult)controller.Add(NewStation);

            // Assert
            Assert.AreEqual("", result.ViewName);
        }
        public void TestPostAddDBError()
        {
            // Arrange
            var controller = new StationsController(new StationLogic(new StationRepositoryStub()));
            var NewStation = new Station {
                StationID = 0, StationName = ""
            };

            // ACt
            var result = (ViewResult)controller.Add(NewStation);

            // Assert
            Assert.AreEqual("", result.ViewName);
        }
        public void TestPostAdd()
        {
            // Arrange
            var controller = new StationsController(new StationLogic(new StationRepositoryStub()));
            var NewStation = new Station {
                StationID = 4, StationName = "Sandvika"
            };

            // ACt
            var result = (RedirectToRouteResult)controller.Add(NewStation);

            // Assert
            Assert.AreEqual("", result.RouteName);
            Assert.AreEqual("Index", result.RouteValues.Values.First());
        }
Beispiel #5
0
        public void Add_Post()
        {
            var station = new Station {
                StationId = 1, Name = "Oslo S", LineStations = null
            };

            var controller  = new StationsController(new StationBLL(new StationRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            var actionResult = (RedirectToRouteResult)controller.Add(station);

            Assert.IsNotNull(actionResult, "Not a redirect result");
            Assert.IsFalse(actionResult.Permanent);
            Assert.AreEqual("Index", actionResult.RouteValues["Action"]);
        }
Beispiel #6
0
        public void Add()
        {
            var station = new Station {
                StationId = 1, Name = "Oslo S", LineStations = null
            };

            var controller  = new StationsController(new StationBLL(new StationRepositoryStab()));
            var sessionMock = new TestControllerBuilder();

            sessionMock.InitializeController(controller);
            controller.Session["AuthenticatedUser"] = new DbUser
            {
                Username = "******",
                Password = null,
                Salt     = null
            };
            var actionResult = (ViewResult)controller.Add();

            Assert.AreEqual("", actionResult.ViewName);
            var stationRet = (Station)actionResult.Model;

            Assert.AreEqual(1, station.StationId);
        }