public TestCurrencyExchange() { _repository = new CurrencyExchangeRepository(); _repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); _exchanger = new CurrencyExchanger(_repository); }
public MasterPresenter(IMasterView masterView = null) { this.masterView = masterView; db = new PortalAukcyjnyEntities(); if (IsUserLoggedIn()) { currentUserId = GetCurrentUserId(); } else { currentUserId = Guid.Empty; } currencyRepo = new CurrencyExchangeRepository(db); auctionsRepo = new AuctionsRepository(db); catRepo = new CategoriesRepository(db); offersRepo = new OffersRepository(db); usersRepo = new UsersRepository(db); commentsRepo = new CommentsRepository(db); observersRepo = new ObserversRepository(db); shipmentsRepo = new ShipmentsRepository(db); imagesRepo = new ImagesRepository(db); buyedItemsRepo = new BuyedItemsRepository(db); }
// GET api/values public string Get(string dates, string currency) { CurrencyExchangeRepository repository = new CurrencyExchangeRepository(); var result = repository.GetRateStats(dates.Split(',').Select(s => DateTime.Parse(s.Trim())).ToList(), currency.Split('-')[0], currency.Split('>')[1]); return(result); }
public TestSum() { var repository = new CurrencyExchangeRepository(); var exchanger = new CurrencyExchanger(repository); _calculation = new Calculation(exchanger); repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); }
static Calculation GetCalculation() { var repository = new CurrencyExchangeRepository(); repository.AddExchangeRate(Currency.USD, Currency.CHF, 1.5); var exchanger = new CurrencyExchanger(repository); return(new Calculation(exchanger)); }
public CurrencyExchangeResponseDomainModel ExchangeCurrency(string from, string to) { CurrencyExchangeRepository repository = new CurrencyExchangeRepository(); var temp = repository.ExvhangeCurrency(from, to); return(new CurrencyExchangeResponseDomainModel { Factor = temp.Factor, MessageResponse = temp.MessageResponse }); }
public void AddExchangeRate_USDtoCHF() { var repository = new CurrencyExchangeRepository(); repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); var pair = new CurrencyPair(Currency.USD, Currency.CHF); Assert.IsTrue(Math.Abs(2.0 / 1.0 - repository.Rates[pair]) < double.Epsilon); }
public void AddExchangeRate_CHFtoUSD_GetExchangeRate_CHFtoUSD() { var repository = new CurrencyExchangeRepository(); repository.AddExchangeRate(Currency.USD, Currency.CHF, 2.0 / 1.0); var rate = repository.GetExchangeRate(Currency.CHF, Currency.USD); Assert.IsTrue(Math.Abs(1.0 / 2.0 - rate) < double.Epsilon); }
public void GetAllPossibleCurrenciesTest() { Mock <IEcbDataSource> mock = new Mock <IEcbDataSource>(); mock.Setup(p => p.GetEcbExchangeRatesXml()) .Returns(XElement.Parse(Properties.Resources.xml_EcbSample)); var repo = new CurrencyExchangeRepository(mock.Object); var all = repo.GetAllPossibleCurrencies(); Assert.AreEqual(32, all.Length); }
public void GetLastExchangeRateTest() { Mock <IEcbDataSource> mock = new Mock <IEcbDataSource>(); mock.Setup(p => p.GetEcbExchangeRatesXml()) .Returns(XElement.Parse(Properties.Resources.xml_EcbSample)); var repo = new CurrencyExchangeRepository(mock.Object); double result = repo.GetLastExchangeRate("EUR", "USD"); Assert.AreEqual(1.1317d, result); result = repo.GetLastExchangeRate("USD", "EUR"); Assert.AreEqual(1 / 1.1317d, result); }
public void GetCurrenciesExchangeHistoryTest() { Mock <IEcbDataSource> mock = new Mock <IEcbDataSource>(); mock.Setup(p => p.GetEcbExchangeRatesXml()) .Returns(XElement.Parse(Properties.Resources.xml_EcbSample)); var repo = new CurrencyExchangeRepository(mock.Object); var history = repo.GetCurrenciesExchangeHistory( "USD", "EUR", new DateTime(2015, 02, 01), new DateTime(2015, 03, 01)); Assert.AreEqual(28, history.Length); }
private List <CurrenciesExchanx> mapResponseToEntity(CurrencyLayerResponse responseModel) { using (CurrencyExchangeRepository repository = new CurrencyExchangeRepository()) { List <CurrenciesExchanx> models = new List <CurrenciesExchanx>(); if (responseModel.Success) { foreach (var item in responseModel.Quotes) { string currensySlug = item.Description.Replace(responseModel.Source, ""); models.Add(new CurrenciesExchanx { CreatedBy = "CurrencyFeedJob", CreatedDate = DateTime.Now, ModifiedBy = "CurrencyFeedJob", ModifiedDate = DateTime.Now, OriginalCurrencyId = repository.getIdBySlug(responseModel.Source), TargetCurrencyId = repository.getIdBySlug(currensySlug), Factor = item.Factor }); } } return(models); } }
public CurrencyExchanger(CurrencyExchangeRepository repository) { _repository = repository; }
public async Task Execute(IJobExecutionContext context) { using (CurrencyExchangeRepository repository = new CurrencyExchangeRepository()) { try { LoggesHelper.addLogs("Job triggered."); List <Currency> currencies = repository.getAllCurrencies(); LoggesHelper.addLogs(currencies.Count + " Currencies found in db."); List <CurrenciesExchanx> currenciesFactor = getFactors(currencies); LoggesHelper.addLogs(currenciesFactor.Count + " Factors have been fetched from the api correctly."); await repository.SaveCurrencyExchange(currenciesFactor); LoggesHelper.addLogs(currenciesFactor.Count + " Factors have been successfully added to the CurrencyExchange table in the DB."); } catch (Exception ex) { LoggesHelper.addLogs(ex.Message); } } }