public async Task <StopAreaViewModel> CreateViewModelAsync(IStopArea stopArea)
        {
            var viewModel = new StopAreaViewModel();

            await UpdateViewModelAsync(stopArea, viewModel);

            return(viewModel);
        }
        public Task UpdateViewModelAsync(IStopArea stopArea, StopAreaViewModel stopAreaViewModel)
        {
            stopAreaViewModel.StopAreaId = stopArea.StopAreaId;
            stopAreaViewModel.Name       = stopArea.Name;
            stopAreaViewModel.X          = stopArea.X;
            stopAreaViewModel.Y          = stopArea.Y;
            stopAreaViewModel.Distance   = stopArea.Distance;

            return(Task.CompletedTask);
        }
        public async Task UpdateViewModels()
        {
            var loggerMock = new Mock <ILogger <DepartureBoardViewModel> >();

            var threadDispatcherMock = new Mock <IThreadDispatcher>();

            threadDispatcherMock
            .Setup(x => x.InvokeOnMainThreadAsync(It.IsAny <Action>()))
            .Returns <Action>(arg => Task.Run(arg));

            threadDispatcherMock
            .Setup(x => x.InvokeOnMainThreadAsync(It.IsAny <Func <Task> >()))
            .Returns <Func <Task> >(arg => arg());

            var stopAreaViewModelFactoryMock = new Mock <IStopAreaViewModelFactory>();

            stopAreaViewModelFactoryMock
            .Setup(x => x.CreateViewModelAsync(It.IsAny <IStopArea>()))
            .Returns <IStopArea>(x => Task.FromResult(new StopAreaViewModel()
            {
                StopAreaId = x.StopAreaId
            }));

            var stopPointViewModelFactoryMock = new Mock <IStopPointViewModelFactory>();

            stopPointViewModelFactoryMock
            .Setup(x => x.CreateViewModelAsync(It.IsAny <StopPoint>()))
            .Returns <StopPoint>(x => Task.FromResult(new StopPointViewModel()
            {
                Name = x.Name
            }));

            var departureViewModelFactoryMock = new Mock <IDepartureViewModelFactory>();

            departureViewModelFactoryMock
            .Setup(x => x.CreateViewModelAsync(It.IsAny <Departure>()))
            .Returns <Departure>(x => Task.FromResult(new DepartureViewModel()
            {
                RunNo = x.RunNo, Time = x.DepartureTime
            }));

            var deviationViewModelFactoryMock = new Mock <IDeviationViewModelFactory>();

            deviationViewModelFactoryMock
            .Setup(x => x.CreateViewModelAsync(It.IsAny <Deviation>()))
            .Returns <Deviation>(x => Task.FromResult(new DeviationViewModel()
            {
                ShortText = x.ShortText
            }));

            var viewModel = new DepartureBoardViewModel(
                loggerMock.Object,
                threadDispatcherMock.Object,
                stopAreaViewModelFactoryMock.Object,
                stopPointViewModelFactoryMock.Object,
                departureViewModelFactoryMock.Object,
                deviationViewModelFactoryMock.Object);

            var data = new IStopArea[]
            {
                new StopAreaInternal
                {
                    StopAreaId = 1,
                    StopPoints = new StopPoint[]
                    {
                        new StopPoint {
                            Name       = "A",
                            Departures = new List <Departure>
                            {
                                new Departure {
                                    RunNo         = 11,
                                    DepartureTime = DateTime.Now
                                },
                                new Departure {
                                    RunNo         = 12,
                                    DepartureTime = DateTime.Now.AddMinutes(2)
                                },
                                new Departure {
                                    RunNo         = 13,
                                    DepartureTime = DateTime.Now.AddMinutes(3)
                                },
                                new Departure {
                                    RunNo         = 14,
                                    DepartureTime = DateTime.Now.AddMinutes(4)
                                }
                            }
                        },
                        new StopPoint {
                            Name       = "B",
                            Departures = new List <Departure>
                            {
                                new Departure {
                                    RunNo         = 21,
                                    DepartureTime = DateTime.Now.AddMinutes(1)
                                },
                                new Departure {
                                    RunNo         = 22,
                                    DepartureTime = DateTime.Now.AddMinutes(2)
                                },
                                new Departure {
                                    RunNo         = 23,
                                    DepartureTime = DateTime.Now.AddMinutes(3)
                                },
                                new Departure {
                                    RunNo         = 24,
                                    DepartureTime = DateTime.Now.AddMinutes(4)
                                }
                            }
                        },
                    }
                },
                new StopAreaInternal
                {
                    StopAreaId = 2,
                    StopPoints = new StopPoint[]
                    {
                        new StopPoint {
                            Name       = "A",
                            Departures = new List <Departure>
                            {
                                new Departure {
                                    RunNo         = 31,
                                    DepartureTime = DateTime.Now.AddMinutes(1)
                                },
                                new Departure {
                                    RunNo         = 32,
                                    DepartureTime = DateTime.Now.AddMinutes(2)
                                },
                                new Departure {
                                    RunNo         = 33,
                                    DepartureTime = DateTime.Now.AddMinutes(3)
                                },
                                new Departure {
                                    RunNo         = 34,
                                    DepartureTime = DateTime.Now.AddMinutes(4)
                                }
                            }
                        },
                    }
                }
            };

            await viewModel.UpdateAsync(data);

            stopAreaViewModelFactoryMock
            .Verify(x => x.CreateViewModelAsync(It.IsAny <IStopArea>()), Times.Exactly(2));

            stopPointViewModelFactoryMock
            .Verify(x => x.CreateViewModelAsync(It.IsAny <StopPoint>()), Times.Exactly(3));

            departureViewModelFactoryMock
            .Verify(x => x.CreateViewModelAsync(It.IsAny <Departure>()), Times.Exactly(12));

            var data2 = new IStopArea[]
            {
                new StopAreaInternal
                {
                    StopAreaId = 2,
                    StopPoints = new StopPoint[]
                    {
                        new StopPoint {
                            Name       = "A",
                            Departures = new List <Departure>
                            {
                                new Departure {
                                    RunNo         = 31,
                                    DepartureTime = DateTime.Now.AddMinutes(10)
                                },
                                new Departure {
                                    RunNo         = 32,
                                    DepartureTime = DateTime.Now.AddMinutes(20)
                                },
                                new Departure {
                                    RunNo         = 33,
                                    DepartureTime = DateTime.Now.AddMinutes(30)
                                },
                                new Departure {
                                    RunNo         = 34,
                                    DepartureTime = DateTime.Now.AddMinutes(40)
                                }
                            }
                        },
                    }
                },
            };

            await viewModel.UpdateAsync(data2);

            departureViewModelFactoryMock
            .Verify(x => x.UpdateViewModelAsync(It.IsAny <Departure>(), It.IsAny <DepartureViewModel>()), Times.Exactly(4));

            Assert.True(viewModel.Count == 1);
        }