Exemplo n.º 1
0
        public async Task LoadCommand_CallsAlertService_LoadFailure()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Strict);

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            var viewModel = new CitiesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                citiesRepositoryMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            alertServiceMock.Verify(mock => mock.Alert(
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <Action>()
                                        ), Times.Once());
        }
Exemplo n.º 2
0
        public async Task LoadCommand_SetsItemsCorrectly()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetAll())
            .Returns(new[] { new CityModel {
                                 Id = 1
                             } });

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            var viewModel = new CitiesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                citiesRepositoryMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            Assert.AreEqual(1, viewModel.Items.Count);
        }
Exemplo n.º 3
0
        public async Task LoadCommand_NotCallsAlertService_UpdateSuccessful()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var updateServiceMock = new Mock <IUpdateService>(MockBehavior.Loose);

            var viewModel = new UpdateViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                updateServiceMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            alertServiceMock.Verify(mock => mock.Alert(
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <Action>()
                                        ), Times.Never());
        }
Exemplo n.º 4
0
        public async Task LoadCommand_CallsZipCodesRepositoryWithCorrectData()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            var viewModel = new ZipCodesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.Initialize(new ZipCodesViewModel.Parameter(3));

            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            zipCodesRepositoryMock.Verify(mock => mock.GetAllForCity(
                                              It.Is <int>(item => item == 3)
                                              ), Times.Once());
        }
Exemplo n.º 5
0
        public async Task SelectCommand_NavigatesToCorrectViewModelWithCorrectData()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            zipCodesRepositoryMock.Setup(mock => mock.GetAllForCity(It.IsAny <int>()))
            .Returns(new[] { new ZipCodeModel {
                                 Id = 1
                             } });

            var viewModel = new ZipCodesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            await viewModel.SelectCommand.ExecuteAsync(viewModel.Items.First());

            // assert
            navigationsServiceMock.Verify(mock => mock.Navigate <ZipCodeViewModel, ZipCodeViewModel.Parameter>(
                                              It.Is <ZipCodeViewModel.Parameter>(item => item.ZipCodeId == 1),
                                              It.IsAny <IMvxBundle>()
                                              ), Times.Once());
        }
Exemplo n.º 6
0
        public async Task SelectCommand_NavigatesToCorrectViewModelWithCorrectData()
        {
            // arrange
            var zipCode = new ZipCodeModel
            {
                Id        = 3,
                CityId    = 2,
                Zip       = 123,
                Latitude  = 10,
                Longitude = 20
            };

            var city = new CityModel
            {
                Id   = 2,
                Name = "test"
            };

            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            zipCodesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(zipCode);
            zipCodesRepositoryMock.Setup(mock => mock.GetNearby(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new[] { zipCode });

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(city);

            var viewModel = new ZipCodeViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                zipCodesRepositoryMock.Object,
                citiesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            await viewModel.SelectCommand.ExecuteAsync(viewModel.Nearby.First());

            // assert
            navigationsServiceMock.Verify(mock => mock.Navigate <ZipCodeViewModel, ZipCodeViewModel.Parameter>(
                                              It.Is <ZipCodeViewModel.Parameter>(item => item.ZipCodeId == 3),
                                              It.IsAny <IMvxBundle>()
                                              ), Times.Once());
        }
Exemplo n.º 7
0
        public async Task LoadCommand_CallsZipCodesRepository_LoadNearbyData()
        {
            // arrange
            var zipCode = new ZipCodeModel
            {
                Id        = 3,
                CityId    = 2,
                Zip       = 123,
                Latitude  = 10,
                Longitude = 20
            };

            var city = new CityModel
            {
                Id   = 2,
                Name = "test"
            };

            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            zipCodesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(zipCode);
            zipCodesRepositoryMock.Setup(mock => mock.GetNearby(It.IsAny <int>(), It.IsAny <int>()))
            .Returns(new[] { zipCode });

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(city);

            var viewModel = new ZipCodeViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                zipCodesRepositoryMock.Object,
                citiesRepositoryMock.Object
                );

            // act
            await viewModel.Initialize(new ZipCodeViewModel.Parameter(3));

            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            zipCodesRepositoryMock.Verify(mock => mock.GetNearby(
                                              It.Is <int>(item => item == 3),
                                              It.Is <int>(item => item == Configuration.NearbyZipCodesCount)
                                              ), Times.Once());
        }
Exemplo n.º 8
0
        public async Task LoadCommand_SetsGroupsInCorrectOrder()
        {
            // arrange
            var cities = new[]
            {
                new CityModel
                {
                    Id   = 1,
                    Name = "ACity"
                },
                new CityModel
                {
                    Id   = 2,
                    Name = "ACity2"
                },
                new CityModel
                {
                    Id   = 3,
                    Name = "CCity2"
                }
            };

            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetAll())
            .Returns(cities);

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            var viewModel = new CitiesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                citiesRepositoryMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            Assert.AreEqual(1, viewModel.Items.First().First().Model.Id);
            Assert.AreEqual(2, viewModel.Items.First().Last().Model.Id);
            Assert.AreEqual(3, viewModel.Items.Last().First().Model.Id);
        }
Exemplo n.º 9
0
        public async Task LoadCommand_CallsCityRepository_SetCityData()
        {
            // arrange
            var zipCode = new ZipCodeModel
            {
                Id        = 3,
                CityId    = 2,
                Zip       = 123,
                Latitude  = 10,
                Longitude = 20
            };

            var city = new CityModel
            {
                Id   = 2,
                Name = "test"
            };

            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            zipCodesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(zipCode);

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetById(It.IsAny <int>()))
            .Returns(city);

            var viewModel = new ZipCodeViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                zipCodesRepositoryMock.Object,
                citiesRepositoryMock.Object
                );

            // act
            await viewModel.Initialize(new ZipCodeViewModel.Parameter(3));

            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            Assert.AreEqual(city.Name, viewModel.City);
        }
Exemplo n.º 10
0
        public async Task SelectCommand_CallsAlertService_OneZipCode_ZipCodeNotFound()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            citiesRepositoryMock.Setup(mock => mock.GetAll())
            .Returns(new[] { new CityModel {
                                 Id = 1
                             } });

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            zipCodesRepositoryMock.Setup(mock => mock.GetZipCodesCount(It.IsAny <int>()))
            .Returns(1);
            zipCodesRepositoryMock.Setup(mock => mock.GetFirstForCity(It.IsAny <int>()))
            .Returns <ZipCodeModel>(null);

            var viewModel = new CitiesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                citiesRepositoryMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            await viewModel.SelectCommand.ExecuteAsync(viewModel.Items.First().First());

            // assert
            alertServiceMock.Verify(mock => mock.Alert(
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <string>(),
                                        It.IsAny <Action>()
                                        ), Times.Once());
        }
Exemplo n.º 11
0
        public async Task LoadCommand_CallsUpdateService()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var updateServiceMock = new Mock <IUpdateService>(MockBehavior.Loose);

            var viewModel = new UpdateViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                updateServiceMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            updateServiceMock.Verify(mock => mock.UpdateAsync(
                                         It.IsAny <CancellationToken>()
                                         ), Times.Once());
        }
Exemplo n.º 12
0
        public async Task LoadCommand_NavigatesToCorrectViewModel_UpdateSuccessful()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var updateServiceMock = new Mock <IUpdateService>(MockBehavior.Loose);

            var viewModel = new UpdateViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                updateServiceMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            navigationsServiceMock.Verify(mock => mock.Navigate <CitiesViewModel>(
                                              It.IsAny <IMvxBundle>()
                                              ), Times.Once());
        }
Exemplo n.º 13
0
        public async Task LoadCommand_CallsCitiesRepository()
        {
            // arrange
            var navigationsServiceMock = new Mock <IMvxNavigationService>(MockBehavior.Loose);

            var alertServiceMock = MockHelpers.CreateAlertService();

            var citiesRepositoryMock = new Mock <ICitiesRepository>(MockBehavior.Loose);

            var zipCodesRepositoryMock = new Mock <IZipCodesRepository>(MockBehavior.Loose);

            var viewModel = new CitiesViewModel(
                navigationsServiceMock.Object,
                alertServiceMock.Object,
                citiesRepositoryMock.Object,
                zipCodesRepositoryMock.Object
                );

            // act
            await viewModel.LoadCommand.ExecuteAsync();

            // assert
            citiesRepositoryMock.Verify(mock => mock.GetAll(), Times.Once());
        }