public async Task ShouldFillServersList_WhenInitializeAsync()
        {
            //arrange
            var servers = new ObservableCollection <Server>
            {
                new Server {
                    Country = "Ukraine", Distance = 1000, Number = 1
                },
                new Server {
                    Country = "Ukraine", Distance = 500, Number = 2
                },
                new Server {
                    Country = "Italy", Distance = 500, Number = 1
                },
            };

            _serversServiceMock.Setup(x => x.GetServersAsync(It.IsAny <string>(), It.IsAny <string>())).Returns(Task.FromResult(servers));
            var serversPageViewModel = new ServersPageViewModel(_navigationServiceMock.Object,
                                                                _serversServiceMock.Object, _settingsServiceMock.Object);

            //act
            await serversPageViewModel.InitializeAsync(null);

            //assert
            CollectionAssert.AreEqual(servers, serversPageViewModel.Servers);
        }
        public async Task ShouldNavigateToErrorPageAsync_WhenInitializeAsyncThroException()
        {
            //arrange
            _serversServiceMock.Setup(x => x.GetServersAsync(It.IsAny <string>(), It.IsAny <string>())).Throws <Exception>();
            var serversPageViewModel = new ServersPageViewModel(_navigationServiceMock.Object,
                                                                _serversServiceMock.Object, _settingsServiceMock.Object);

            //act
            await serversPageViewModel.InitializeAsync(null);

            //assert
            _navigationServiceMock.Verify(x => x.NavigateToErrorPageAsync(It.IsAny <NavigationData>()), Times.Once);
        }
Exemple #3
0
        public async Task ShouldNavigateToPreviousPage_WhenOkCommand()
        {
            //arrange
            var errorViewModel = new ErrorPageViewModel(_navigationServiceMock.Object);

            var navigateFromPage = new ServersPageViewModel(_navigationServiceMock.Object, _serversServiceMock.Object,
                                                            _settingsServiceMock.Object);

            await errorViewModel.InitializeAsync(new ErrorPageNavigationData
            {
                NavigatedFromPage = navigateFromPage
            });

            //act
            errorViewModel.OkCommand.Execute(null);

            //assert
            _navigationServiceMock.Verify(x => x.NavigateToPageAsync(navigateFromPage, It.IsAny <NavigationData>()), Times.Once);
        }