protected override async Task OnInitializedAsync() { Saved = false; Cities = (await CityDataService.GetAllCities()).ToList(); Countries = (await CountryDataService.GetAllCountries()).ToList(); JobCategories = (await JobCategoryDataService.GetAllJobCategories()).ToList(); Offices = (await OfficeDataService.GetAllOffices()).ToList(); Pods = (await PodDataService.GetAllPods()).ToList(); Regions = (await RegionDataService.GetAllRegions()).ToList(); int.TryParse(EmployeeId, out var employeeId); if (employeeId == 0) //new employee is being created { //add some defaults Employee = new Employee { OfficeId = 1, JobCategoryId = 1, RegionId = 3 }; } else { Employee = await EmployeeDataService.GetEmployeeDetails(int.Parse(EmployeeId)); } OfficeId = Employee.OfficeId.ToString(); RegionId = Employee.RegionId.ToString(); PodId = Employee.PodId.ToString(); JobCategoryId = Employee.JobCategoryId.ToString(); }
private void BeforeScenario() { _exampleCityEntities = new List <City>(); _mapperService = new MapperService(); _mockUnitOfWork = new Mock <IUnitOfWork>(); _mockUnitOfWork.Setup(x => x.Complete()).Verifiable(); _mockCityRepository = new Mock <IRepository <CityWeatherContainer, City> >(); _mockCityRepository.Setup(x => x.Read()).Returns(_exampleCityEntities); /* todo: check if this would be okay for the specs. * thought about mocking this, but I don't think a quick REST call is a problem here; * besides specs can be longer running tests that also test integration unlike unit tests. * if the 3rd party API changed and broke our system it would be nice to know about it. * assuming the tests will be run on a machine with an internet connection. :/ * in reality I'd check this with the client. */ _countryService = new CountryRestService(); _weatherService = new WeatherRestService(); _cityDataService = new CityDataService(_mockCityRepository.Object, _mockUnitOfWork.Object, _mapperService); _citySearchDomainService = new CitySearchDomainService(_mapperService, _cityDataService, _weatherService, _countryService); _citySearchController = new CitySearchController(_mapperService, _citySearchDomainService); }
public async Task Test_LoadFromCitiesCorrectly() { //arrange CityDataService mockCityDataService = ServiceMocks.GetMockCityDataService(3); var mockMessenger = new Mock <IMvxMessenger>(); var mockConnectionService = new Mock <IConnectionService>(); var mockDialogService = new Mock <IDialogService>(); //act var searchJourneyViewModel = new SearchJourneyViewModel(mockMessenger.Object, mockCityDataService, mockConnectionService.Object, mockDialogService.Object); await searchJourneyViewModel.LoadCities(); //assert Assert.AreEqual(searchJourneyViewModel.FromCities.Count, 3); }
public static CityDataService GetMockCityDataService(int count) { var list = new List <City>(); var mockexpenseRepository = new Mock <ICityRepository>(); for (int i = 0; i < count; i++) { list.Add(new City { CityId = count }); } mockexpenseRepository.Setup(m => m.GetAllCities()).ReturnsAsync(list); var cityDataService = new CityDataService(mockexpenseRepository.Object); return(cityDataService); }
public void BeforeScenario() { _mockUnitOfWork = new Mock <IUnitOfWork>(); _mockUnitOfWork.Setup(x => x.Complete()).Verifiable(); _mockCityRepository = new Mock <IRepository <CityWeatherContainer, City> >(); _mockCityRepository.Setup(x => x.Read()).Returns(_exampleCityEntities); _mockCityRepository.Setup(x => x.Create(It.IsAny <City>())) .Callback((City city) => _exampleCityEntities.Add(city)); _mapperService = new MapperService(); var cityDataService = new CityDataService( _mockCityRepository.Object, _mockUnitOfWork.Object, _mapperService); var cityDomainService = new CityDomainService(_mapperService, cityDataService); _cityApiController = new CityController(_mapperService, cityDomainService); }
public async Task Test_Initialize() { //arrange CityDataService mockCityDataService = ServiceMocks.GetMockCityDataService(3); var mockMessenger = new Mock <IMvxMessenger>(); var mockConnectionService = new Mock <IConnectionService>(); var a = mockConnectionService.Setup(m => m.CheckOnline()).Returns(true); var mockDialogService = new Mock <IDialogService>(); //act var searchJourneyViewModel = new FakeSearchJourneyViewModel(mockMessenger.Object, mockCityDataService, mockConnectionService.Object, mockDialogService.Object); await searchJourneyViewModel.InitializeAsync(); //assert Assert.IsNotNull(searchJourneyViewModel.FromCities); Assert.IsNotNull(searchJourneyViewModel.ToCities); Assert.IsNotNull(searchJourneyViewModel.SelectedFromCity); Assert.IsNotNull(searchJourneyViewModel.SelectedToCity); Assert.IsNotNull(searchJourneyViewModel.SelectedHour); }
// Add City click event protected void BtnAddCity_Click(object sender, EventArgs e) { bool cityAdded = false; try { // Collect values from form int population = int.Parse(txtPopulation.Text); int medianHouseholdIncome = int.Parse(txtMedianHouseholdIncome.Text); decimal percentOwners = decimal.Parse(txtPercentOwners.Text); decimal percentRenters = decimal.Parse(txtPercentRenters.Text); int medianHomeValue = int.Parse(txtMedianHomeValue.Text); int medianMaleAge = int.Parse(txtMedianMaleAge.Text); int medianFemaleAge = int.Parse(txtMedianFemaleAge.Text); decimal unemploymentRate = decimal.Parse(txtUnemploymentRate.Text); decimal crimeIndex = decimal.Parse(txtCrimeIndex.Text); // Using an object initializer to create new City object CityDataServiceReference.City newCity = new CityDataServiceReference.City { CityName = txtCity.Text, State = txtState.Text, Population = population, MedianHouseholdIncome = medianHouseholdIncome, PercentOwners = percentOwners, PercentRenters = percentRenters, MedianHomeValue = medianHomeValue, MedianMaleAge = medianMaleAge, MedianFemaleAge = medianFemaleAge, UnemploymentRate = unemploymentRate, CrimeIndex = crimeIndex }; // Instantiate web service and add city CityDataService cds = new CityDataService(); cityAdded = cds.AddCity(newCity); if (cityAdded) { IEnumerable <Control> allTextBoxes = GetAllControlsOfType(this, typeof(TextBox)); // Fade out text fields during clear. Really wanted the clear to take place while they were not visible, but I can't get the timing right ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "fadeout", "FadeOutTxts();", true); foreach (TextBox textbox in allTextBoxes) { textbox.Text = ""; } ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "fadein", "FadeInTxts();", true); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "fadeconfirm", "FadeConfirm();", true); } else { ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "fadeduplicate", "FadeDuplicate();", true); } } // Catch invalid value exceptions and specify which field was wrong catch (FormatException fe) { Debug.WriteLine(fe.ToString()); string fieldName = FindInvalidField(); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "invalidvalue", "$('.alert-message').text('The value in the " + fieldName + " field is invalid. Please enter a value that matches the data type indicated');", true); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "fadealert", "FadeAlert();", true); } catch (Exception ex) { Debug.WriteLine(ex.ToString()); ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "Error();", true); } }
public CityManager(FreeLancersEntities entities) : base(entities) { _cityDataService = new CityDataService(entities); }