예제 #1
0
        public void SearchLocationCommand_ServiceReternExceptionWithServerErrorResponseModel_ReternErrorMessage(string message, string code)
        {
            //Arrange
            var serverErrorResponse = new ServerErrorResponseModel
            {
                Message = message,
                Code    = code
            };

            string space = " ";

            _locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ThrowsAsync(new ApiException(serverErrorResponse));

            var searchLocationListViewModel = new SearchLocationListViewModel(_locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.SearchLocationCommand.Execute(null);

            //Assert
            Assert.AreEqual($"{serverErrorResponse.Code}{space}{serverErrorResponse.Message}", searchLocationListViewModel.ErrorMessage);
            Assert.IsTrue(searchLocationListViewModel.IsErrorMessageVisible);
            Assert.IsFalse(searchLocationListViewModel.IsListVisible);
        }
예제 #2
0
        public void SearchLocationCommand_ServiceReternException_ApiException()
        {
            //Arrange
            string textOfException = "Text of exception";

            _locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ThrowsAsync(new ApiException(textOfException));

            var searchLocationListViewModel = new SearchLocationListViewModel(_locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.SearchLocationCommand.Execute(null);
        }
예제 #3
0
        public void SearchLocationCommand_ServiceReternLocationObject_AddReternedByServiceLocationObjectToLocationList()
        {
            //Arrange
            _locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <Location>
            {
                _locationKyiv
            });
            var searchLocationListViewModel = new SearchLocationListViewModel(_locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.SearchLocationCommand.Execute(null);
            var locationListResult = searchLocationListViewModel.LocationList;

            //Assert
            Assert.AreEqual(_locationKyiv, locationListResult.FirstOrDefault());
        }
예제 #4
0
        public void SearchLocationCommand_ServiceReternExceptionWithStringMessage_ReternErrorMessage()
        {
            //Arrange
            string textOfException = "Text of exception";
            string space           = " ";

            _locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ThrowsAsync(new ApiException(textOfException));

            var searchLocationListViewModel = new SearchLocationListViewModel(_locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.SearchLocationCommand.Execute(null);

            //Assert
            Assert.AreEqual($"{space}{textOfException}", searchLocationListViewModel.ErrorMessage);
            Assert.IsTrue(searchLocationListViewModel.IsErrorMessageVisible);
            Assert.IsFalse(searchLocationListViewModel.IsListVisible);
        }
예제 #5
0
        public void SearchLocationCommand_ServiceReternLocationList_TheCorrectNumberOfLocationsIsReternedAfterSeveralRequests()
        {
            //Arrange
            var locationList = new List <Location>
            {
                _locationKyiv,
                _locationLviv
            };

            _locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ReturnsAsync(locationList);
            var searchLocationListViewModel = new SearchLocationListViewModel(_locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.SearchLocationCommand.Execute(null);
            var locationListResult = searchLocationListViewModel.LocationList;

            //Assert
            Assert.AreEqual(locationList.Count, locationListResult.Count);
        }
예제 #6
0
        public void LoadItemsCommand_ServiceReternLocationObject_AddReternedByServiceLocationObjectToLocationList(string key, string localizedName, string type)
        {
            //Arrange
            Location location = new Location
            {
                Key                = key,
                LocalizedName      = localizedName,
                Type               = type,
                AdministrativeArea = new AdministrativeArea()
                {
                    LocalizedName = "",
                    LocalizedType = ""
                },
                Country = new Country()
                {
                    ID            = "",
                    LocalizedName = ""
                }
            };

            var locationSearchServiceMoc = new Mock <ILocationSearchService>();


            locationSearchServiceMoc
            .Setup(service => service.GetLocationListByTextAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <Location>
            {
                location
            });

            var searchLocationListViewModel = new SearchLocationListViewModel(locationSearchServiceMoc.Object);

            //Act
            searchLocationListViewModel.LoadItemsCommand.Execute(null);
            var locationListResult = searchLocationListViewModel.LocationList;


            //Assert
            Assert.AreEqual(location, locationListResult.FirstOrDefault());
        }
 public SearchLocationListPage()
 {
     InitializeComponent();
     BindingContext = _viewModel = App.Container.Resolve <SearchLocationListViewModel>();
 }