Ejemplo n.º 1
0
        public void Index()
        {
            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 stations = new List <Station>();
            var oslos    = new Station {
                StationId = 0, Name = "Oslo S", LineStations = null
            };

            stations.Add(oslos);
            stations.Add(oslos);
            stations.Add(oslos);

            var actionResult = (ViewResult)controller.Index();
            var result       = (List <Station>)actionResult.Model;

            Assert.AreEqual(actionResult.ViewName, "");

            for (var i = 0; i < result.Count; i++)
            {
                Assert.AreEqual(stations[i].StationId, result[i].StationId);
                Assert.AreEqual(stations[i].Name, result[i].Name);
                Assert.AreEqual(stations[i].LineStations, result[i].LineStations);
            }
        }
Ejemplo n.º 2
0
        public void Can_Send_Pagination_View_Model()
        {
            Mock <IStationRepository> mock = new Mock <IStationRepository>();

            mock.Setup(m => m.Stations).Returns(new Station[] {
                new Station {
                    Id = "1", Name = "S1"
                },
                new Station {
                    Id = "2", Name = "S2"
                },
                new Station {
                    Id = "3", Name = "S3"
                },
                new Station {
                    Id = "4", Name = "S4"
                },
                new Station {
                    Id = "5", Name = "S5"
                }
            }.AsQueryable());
            StationsController stationController = new StationsController(mock.Object);

            stationController.PageSize = 3;

            StationListViewModel result     = (StationListViewModel)stationController.Index(2).Model;
            PagingInfo           pagingInfo = result.PagingInfo;

            Assert.AreEqual(pagingInfo.CurrentPage, 2);
            Assert.AreEqual(pagingInfo.ItemsPerPage, 3);
            Assert.AreEqual(pagingInfo.TotalItems, 5);
            Assert.AreEqual(pagingInfo.TotalPages, 2);
        }
Ejemplo n.º 3
0
        public void Can_Paginate()
        {
            //Setup
            Mock <IStationRepository> mock = new Mock <IStationRepository>();

            mock.Setup(m => m.Stations).Returns(new Station[] {
                new Station {
                    Id = "1", Name = "S1", Route = "Troncal"
                },
                new Station {
                    Id = "2", Name = "S2", Route = "Troncal"
                },
                new Station {
                    Id = "3", Name = "S3", Route = "Troncal"
                },
                new Station {
                    Id = "4", Name = "S4", Route = "Different"
                },
                new Station {
                    Id = "5", Name = "S5", Route = "Different"
                }
            }.AsQueryable());
            StationsController stationController = new StationsController(mock.Object);

            stationController.PageSize = 3;

            //Act
            StationListViewModel result = (StationListViewModel)stationController.Index(2).Model;

            //Assert
            Station[] stationArray = result.Stations.ToArray();
            Assert.IsTrue(stationArray.Length == 2);
            Assert.AreEqual(stationArray[0].Name, "S4");
            Assert.AreEqual(stationArray[1].Name, "S5");
        }
Ejemplo n.º 4
0
        public void TestGetIndex()
        {
            // Arrange
            var SessionMock = new TestControllerBuilder();

            var controller = new StationsController(new StationLogic(new StationRepositoryStub()));

            SessionMock.InitializeController(controller);
            controller.Session["LoggedIn"] = true;
            var StationList = new List <Station>
            {
                new Station {
                    StationID = 1, StationName = "Oslo S"
                },
                new Station {
                    StationID = 2, StationName = "Nationaltheatret"
                },
                new Station {
                    StationID = 3, StationName = "Lysaker"
                }
            };

            // ACt
            var result     = (ViewResult)controller.Index();
            var resultList = (List <Station>)result.Model;

            // Assert
            Assert.AreEqual("", result.ViewName);
            for (int i = 0; i < resultList.Count(); i++)
            {
                Assert.AreEqual(StationList[i].StationID, resultList[i].StationID);
                Assert.AreEqual(StationList[i].StationName, resultList[i].StationName);
            }
        }