Пример #1
0
        public void Can_Get_Stations_By_Route()
        {
            //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 = 5;

            //Act
            StationListViewModel result = (StationListViewModel)stationController.ByRoute("Troncal").Model;

            //Assert
            Station[] stationArray = result.Stations.ToArray();
            Assert.IsTrue(stationArray.Length == 3);
            Assert.AreEqual(stationArray[0].Name, "S1");
            Assert.AreEqual(stationArray[1].Name, "S2");
        }
Пример #2
0
        public StationMapPage(StationListViewModel stationViewmodel)
        {
            InitializeComponent();
            viewModel      = stationViewmodel;
            BindingContext = viewModel;

            MoveMapToCurrentPosition();

            Map.HasZoomEnabled   = true;
            Map.HasScrollEnabled = true;
            Map.IsShowingUser    = true;


            /*ToolbarItems.Add(new ToolbarItem("Refresh", "refresh.png", () =>
             * {
             *  Map.Pins.Clear();
             *  AddPinsFromList();
             *  MoveMapToCurrentPosition();
             * }));
             *
             * /*ToolbarItems.Add(new ToolbarItem("Cancel", "cancel.png", () =>
             * {
             *  // :(
             * }));*/

            MessagingCenter.Subscribe <ILocationService, Coordinate>(this, "deviceLocation", (sender, coordinate) =>
            {
                //System.Diagnostics.Debug.WriteLine("Received location: "
                // + coordinate.Latitude + coordinate.Longitude);
                MoveMapToCurrentPosition();
            });
        }
Пример #3
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);
        }
Пример #4
0
        public MainPage()
        {
            InitializeComponent();

            StationListViewModel listViewModel = new StationListViewModel();

            var listPage = new NavigationPage(new StationListPage(listViewModel));

            listPage.Title = "List";


            var mapPage = new NavigationPage(new StationMapPage(listViewModel));

            mapPage.Title = "Map";


            // check if app runs on iOS and set icons accordingly
            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                listPage.Icon = "tab_list.png";
                mapPage.Icon  = "tab_map.png";
                break;
            }


            Children.Add(listPage);
            Children.Add(mapPage);
        }
Пример #5
0
        //
        // GET: /Stations/

        public ViewResult Index(int page = 1)
        {
            StationListViewModel model = new StationListViewModel {
                Stations = stationsRepository.Stations
                           .OrderBy(s => s.Name)
                           .Skip((page - 1) * PageSize)
                           .Take(PageSize),
                PagingInfo = new PagingInfo {
                    CurrentPage  = page,
                    ItemsPerPage = PageSize,
                    TotalItems   = stationsRepository.Stations.Count()
                }
            };

            return(View(model));
        }
Пример #6
0
        public RegionModelSource(AsyncCommand navBack)
        {
            this.NavigateRoot = navBack;

            this.Navigate = new AsyncCommand(async(obj) =>
            {
                if (RoundManager.CurrentRound?.Id == Guid.Empty && this.Id != Guid.Empty)
                {
                    // only set id if the round has yet to begin
                    RoundManager.CurrentRound.RegionId = this.Id;
                    await RoundManager.SaveRoundToDiskAsync();
                }

                var file     = ServiceResolver.Resolve <IFileHandler>();
                var stations = await file.GetFileAsync <StationHandler>(Constants.FileNames.Stations);
                var filtered = stations.Stations.Where(s => s.RegionId == RoundManager.CurrentRound?.RegionId);

                var vm = new StationListViewModel(this, filtered);
                BaseViewModel.Navigator.Navigate(Shared.Navigation.NavigationType.StationSelect, vm);
            });
        }
Пример #7
0
 public StationListPage(StationListViewModel viewmodel)
 {
     InitializeComponent();
     viewModel      = viewmodel;
     BindingContext = viewModel;
 }