public void Setup() { //Create Repo _fakeSmsRepo = new Mock <IGenericRepository <Int32, Sms> >(); //Create unitOfWork and add Repo _fakeUnitOfWork = new Mock <IUnitOfWork>(); _fakeUnitOfWork.Setup(x => x.Repositories).Returns(new Dictionary <string, Object>()); _fakeUnitOfWork.Object.Repositories.Add(typeof(Sms).Name, _fakeSmsRepo.Object); //Repositories mapped by entity names in unitOfWork(for detail check UnitOfWork.cs) _fakeUnitOfWork.Object.Repositories.Add(typeof(Country).Name, _fakeCountryRepo.Object); //Repositories mapped by entity names in unitOfWork(for detail check UnitOfWork.cs) //Will work for first line of SendSms List <Country> countries; using (var op = new CountryOperations()) { countries = op.GetAll(); _fakeCountryRepo.Setup(r => r.FindBy(x => x.Cc == toParameter.Substring(1, 2))).Returns(countries.Find(x => x.Cc == toParameter)); } //get real smses from db and add it to repo memory //unit tests should not go to database, all logic should be in memory. using (var op = new SmsOperations()) { _realGetSentSmsResult = op.GetSentSms(dateFrom, dateTo, skip, take); _fakeSmsRepo.Setup(r => r.FilterBy(x => x.DateTime >= dateFrom && x.DateTime <= dateTo).ToList()) .Returns(op.GetAll().FindAll(x => x.DateTime >= dateFrom && x.DateTime <= dateTo).ToList()); } //put mocked unitOfWork to the operation _smsOperations = new SmsOperations(_fakeUnitOfWork.Object); }
public async Task <List <Country> > Get() { //Added non-blocking code for scalability return(await Task <List <Country> > .Run(() => { using (var op = new CountryOperations()) { return op.GetAll(); } })); }
public async Task ListCountries() { var test = CreateHttpTest() .ExpectUriPath("countries") .ResponseBodyFromFile("country/country_list.json"); var expected = test.ResponseBody <IList <Country> >(); var operations = new CountryOperations(test.HttpClient, BaseUri, ClientId, ClientSecret, ReloadlyEnvironment.Sandbox); var actual = await operations.ListAsync(); VerifyList(expected, actual); }
public async Task GetCountryByCode() { var test = CreateHttpTest() .ExpectUriPath("countries/CC") .ResponseBodyFromFile("country/country.json"); var expected = test.ResponseBody <Country>(); var operations = new CountryOperations(test.HttpClient, BaseUri, ClientId, ClientSecret, ReloadlyEnvironment.Sandbox); var actual = await operations.GetByCodeAsync("CC"); Verify(expected, actual); }
private async void CustomersTestForm_Shown(object sender, EventArgs e) { try { CountryComboBox.DataSource = await CountryOperations.CountriesWithSelectAsync(); _customerItems = await CustomerOperations.GetCustomersAsync(); ExportByCountryButton.Enabled = true; } catch (Exception ex) { MessageBox.Show($"Failed to load data\n{ex.Message}"); } }
public void Setup() { //Create Repo _fakeCountryRepo = new Mock <IGenericRepository <Int32, Country> >(); //Create unitOfWork and add Repo _fakeUnitOfWork = new Mock <IUnitOfWork>(); _fakeUnitOfWork.Setup(x => x.Repositories).Returns(new Dictionary <string, Object>()); _fakeUnitOfWork.Object.Repositories.Add(typeof(Country).Name, _fakeCountryRepo.Object); //Repositories mapped by entity names in unitOfWork(for detail check UnitOfWork.cs) //put mocked unitOfWork to the operation _countryOperations = new CountryOperations(_fakeUnitOfWork.Object); //get real countries from db and add it to repo memory //unit tests should not go to database, all logic should be in memory. using (var op = new CountryOperations()) { this._realCountries = op.GetAll(); } _fakeCountryRepo.Setup(r => r.All().ToList()).Returns(this._realCountries); }