public async Task <QuotationDto> GenerateQuotation(QuotationDto quotationRequest) { //todo input validation var apiRequest = new GetQuotatonRequest { FromCurrencyCode = quotationRequest.FromCurrencyCode, ToCurrencyCode = quotationRequest.ToCurrencyCode, Amount = quotationRequest.Amount }; var apiResponse = await _ofxAPIProxy.GetQuotation(apiRequest); if (apiResponse == null) { throw new Exception("Failed to get a quotation"); } var quotationResponse = quotationRequest; quotationResponse.OFXCustomerRate = apiResponse.CustomerRate; quotationResponse.OFXCustomerAmount = apiResponse.CustomerAmount; if (await this.SaveQuotation(quotationResponse)) { return(quotationResponse); } throw new Exception("Failed to save the quotation"); }
public void GetDataSets_DoesntOverrideExistingObjectsWithNulls_IfTheyAreNotInSpecificRepositories() { //Arrange:QueryDef IEnumerable <AnalysisType> analysisTypes = new AnalysisType[] { AnalysisType.Prices }; AnalysisDataQueryDefinition queryDef = new AnalysisDataQueryDefinition(UTDefaulter.DEFAULT_ASSET_ID, UTDefaulter.DEFAULT_TIMEFRAME_ID) { AnalysisTypes = analysisTypes }; //Arrange:Quotations Mock <IQuotationRepository> quotationRepository = new Mock <IQuotationRepository>(); IEnumerable <QuotationDto> quotationDtos = new QuotationDto[] { utf.getQuotationDto(1), utf.getQuotationDto(2), utf.getQuotationDto(3), utf.getQuotationDto(4) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); //Arrange:Prices Mock <IPriceRepository> priceRepository = new Mock <IPriceRepository>(); IEnumerable <PriceDto> priceDtos = new PriceDto[] { utf.getPriceDto(1), utf.getPriceDto(2), utf.getPriceDto(3), utf.getPriceDto(4) }; priceRepository.Setup(p => p.GetPrices(queryDef)).Returns(priceDtos); //Act IDataSetService service = new DataSetService(); service.InjectQuotationRepository(quotationRepository.Object); service.InjectPriceRepository(priceRepository.Object); var dataSets = service.GetDataSets(queryDef); if (dataSets == null) { throw new Exception("Collection should not be null"); } DataSet baseDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 2); if (baseDataSet == null) { throw new Exception("Base data set shouldn't be null"); } Price basePrice = (baseDataSet == null ? null : baseDataSet.GetPrice()); if (basePrice == null) { throw new Exception("Base price shouldn't be null"); } priceRepository.Setup(q => q.GetPrices(queryDef)).Returns(new PriceDto[] { }); service.InjectPriceRepository(priceRepository.Object); dataSets = service.GetDataSets(queryDef); DataSet comparedDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 2); Price comparedPrice = (comparedDataSet == null ? null : comparedDataSet.GetPrice()); //Assert var areTheSameObject = (basePrice == comparedPrice); Assert.IsTrue(areTheSameObject); }
public async Task <QuotationDto> GenerateQuotation(QuotationDto quotationRequest) { await Task.Delay(1000); var quotationResponse = quotationRequest; quotationResponse.OFXCustomerRate = 0.6M; quotationResponse.OFXCustomerAmount = quotationRequest.Amount * quotationResponse.OFXCustomerRate; return(quotationResponse); }
public void IsInIndexRange_ReturnsFalse_IfStartLimitIsEarlierAndEndLimitIsEarlier() { //Arrange QuotationDto quotation = getDefaultQuotation_ForIsInIndexRangeTest(); //Act var result = quotation.IsInIndexRange(DEFAULT_INDEX_NUMBER - 1, DEFAULT_INDEX_NUMBER - 1); //Assert Assert.IsFalse(result); }
public void IsInIndexRange_ReturnsTrue_IfStartLimitIsEqualAndEndLimitIsLater() { //Arrange QuotationDto quotation = getDefaultQuotation_ForIsInIndexRangeTest(); //Act var result = quotation.IsInIndexRange(DEFAULT_INDEX_NUMBER, DEFAULT_INDEX_NUMBER + 5); //Assert Assert.IsTrue(result); }
public void IsInIndexRange_ReturnsTrue_IfBothDelimitersAreNull() { //Arrange QuotationDto quotation = getDefaultQuotation_ForIsInIndexRangeTest(); //Act var result = quotation.IsInIndexRange(null, null); //Assert Assert.IsTrue(result); }
public void ToDto_ReturnsProperObjecct() { //Arrange Quotation quotation = getDefaultQuotation(); //Act QuotationDto dto = quotation.ToDto(); QuotationDto expectedDto = getDefaultQuotationDto(); //Assert var areEqual = expectedDto.Equals(dto); Assert.IsTrue(areEqual); }
public void FromDto_ReturnsProperObject() { //Arrange QuotationDto dto = getDefaultQuotationDto(); //Act DataSet ds = getDefaultDataSet(); Quotation quotation = Quotation.FromDto(ds, dto); Quotation expectedQuotation = getDefaultQuotation(); //Assert var areEqual = expectedQuotation.Equals(quotation); Assert.IsTrue(areEqual); }
public static Quotation FromDto(QuotationDto dto) { var quotation = new Quotation { AssetId = dto.AssetId, TimeframeId = dto.TimeframeId, Date = dto.Date, DateIndex = dto.DateIndex, Open = dto.Open, High = dto.High, Low = dto.Low, Close = dto.Close }; return(quotation); }
public async Task <ActionResult> GenerateQuotation([FromBody] QuotationDto quotationRequest) { // We can move the input validation into QuotationService // and give more error detail, for example invalid email etc. if (quotationRequest == null || string.IsNullOrWhiteSpace(quotationRequest.FirstName) || string.IsNullOrWhiteSpace(quotationRequest.LastName) || string.IsNullOrWhiteSpace(quotationRequest.FromCurrencyCode) || string.IsNullOrWhiteSpace(quotationRequest.ToCurrencyCode) || quotationRequest.Amount <= 0 || (!string.IsNullOrWhiteSpace(quotationRequest.Email) && !RegexUtilities.IsValidEmail(quotationRequest.Email))) { return(BadRequest()); } return(Ok(await _quotationService.GenerateQuotation(quotationRequest))); }
public void GetDataSets_UseAlwaysExistingInstancesOfObjects_EvenIfThereIsAnotherOneInRepository() { //Arrange:QueryDef IEnumerable <AnalysisType> analysisTypes = new AnalysisType[] { AnalysisType.Prices }; AnalysisDataQueryDefinition queryDef = new AnalysisDataQueryDefinition(1, 1) { AnalysisTypes = analysisTypes }; //Arrange:Quotations Mock <IQuotationRepository> quotationRepository = new Mock <IQuotationRepository>(); IEnumerable <QuotationDto> quotationDtos = new QuotationDto[] { utf.getQuotationDto(1), utf.getQuotationDto(2), utf.getQuotationDto(3), utf.getQuotationDto(4) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); //Arrange:Prices Mock <IPriceRepository> priceRepository = new Mock <IPriceRepository>(); IEnumerable <PriceDto> priceDtos = new PriceDto[] { utf.getPriceDto(1), utf.getPriceDto(2), utf.getPriceDto(3), utf.getPriceDto(4) }; priceRepository.Setup(p => p.GetPrices(queryDef)).Returns(priceDtos); //Act IDataSetService service = new DataSetService(); service.InjectQuotationRepository(quotationRepository.Object); service.InjectPriceRepository(priceRepository.Object); var dataSets = service.GetDataSets(queryDef); DataSet baseDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 2); Quotation stubQuotation = utf.getQuotation(2); stubQuotation.Open = stubQuotation.Open + 3; IEnumerable <Quotation> quotations = new Quotation[] { utf.getQuotation(1), stubQuotation, utf.getQuotation(3), utf.getQuotation(4) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); service.InjectQuotationRepository(quotationRepository.Object); dataSets = service.GetDataSets(queryDef); DataSet comparedDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 2); //Assert var areTheSameObject = (baseDataSet.GetQuotation() == comparedDataSet.GetQuotation()); Assert.IsTrue(areTheSameObject); }
public ActionResult Register(int id, string ruc) { #region TOKEN var sessione = (SessionModel)Session[Resources.Constante.SessionUsuario]; LoginDto oLoginDto = new LoginDto(); oLoginDto.v_UserName = sessione.UserName; oLoginDto.v_Password = sessione.Pass; var validated = _securityBL.ValidateAccess(oLoginDto); if (validated == null) { return(Json("", "application/json", Encoding.UTF8, JsonRequestBehavior.AllowGet)); } #endregion if (id == 0) { var data = new QuotationDto(); var company = _companyBL.CompanyByRuc(ruc, validated.Token).Data; data.CompanyId = company.CompanyId; data.CompanyRuc = company.IdentificationNumber; data.CompanyName = company.Name; data.CompanyDistrictName = company.District; data.CompanyAddress = company.Address; data.FullName = company.ContactName; data.Email = company.Mail; ViewBag.Headquarters = company.companyHeadquarter; ViewBag.DataQuotation = data; } else { var response = _quotationBL.GetQuotation(id, validated.Token); if (response != null) { ViewBag.DataQuotation = response.Data; ViewBag.Headquarters = _companyBL.CompanyDetail(response.Data.CompanyId, validated.Token).Data.companyHeadquarter; } else { var oQuotationDto = new QuotationDto(); ViewBag.DataQuotation = oQuotationDto; } } return(View()); }
public void GetDataSets_ReturnsCollectionWithoutSomeAnalysisType_IfThereIsNoDataForThisType() { //Arrange:QueryDef IEnumerable <AnalysisType> analysisTypes = new AnalysisType[] { AnalysisType.Prices }; AnalysisDataQueryDefinition queryDef = new AnalysisDataQueryDefinition(UTDefaulter.DEFAULT_ASSET_ID, UTDefaulter.DEFAULT_TIMEFRAME_ID) { AnalysisTypes = analysisTypes }; //Arrange:Quotations Mock <IQuotationRepository> quotationRepository = new Mock <IQuotationRepository>(); IEnumerable <QuotationDto> quotationDtos = new QuotationDto[] { utf.getQuotationDto(2), utf.getQuotationDto(3), utf.getQuotationDto(4) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); //Arrange:Prices Mock <IPriceRepository> priceRepository = new Mock <IPriceRepository>(); IEnumerable <PriceDto> priceDtos = new PriceDto[] { utf.getPriceDto(3), utf.getPriceDto(4), utf.getPriceDto(5), utf.getPriceDto(6) }; priceRepository.Setup(p => p.GetPrices(queryDef)).Returns(priceDtos); //Act IDataSetService service = new DataSetService(); service.InjectQuotationRepository(quotationRepository.Object); service.InjectPriceRepository(priceRepository.Object); var dataSets = service.GetDataSets(queryDef); //Assert DataSet ds2 = utf.getDataSet(2); ds2.SetQuotation(utf.getQuotation(ds2)); DataSet ds3 = utf.getDataSet(3); ds3.SetQuotation(utf.getQuotation(ds3)).SetPrice(utf.getPrice(ds3)); DataSet ds4 = utf.getDataSet(4); ds4.SetQuotation(utf.getQuotation(ds4)).SetPrice(utf.getPrice(ds4)); IEnumerable <DataSet> expectedDataSets = new DataSet[] { ds2, ds3, ds4 }; var areEqual = expectedDataSets.HasEqualItems(dataSets); Assert.IsTrue(areEqual); }
public void GetDataSetsWithInitialCollection_ReturnsProperlyFilledAndIndexedArray_IfNullArrayWasPassedAndSomeDataWereAppended() { //Arrange IEnumerable <AnalysisType> analysisTypes = new AnalysisType[] { AnalysisType.Quotations, AnalysisType.Prices }; AnalysisDataQueryDefinition queryDef = new AnalysisDataQueryDefinition(UTDefaulter.DEFAULT_ASSET_ID, UTDefaulter.DEFAULT_TIMEFRAME_ID) { AnalysisTypes = analysisTypes }; Mock <IQuotationRepository> quotationRepository = new Mock <IQuotationRepository>(); Mock <IPriceRepository> priceRepository = new Mock <IPriceRepository>(); //Act IDataSetService service = new DataSetService(); IEnumerable <QuotationDto> quotationDtos = new QuotationDto[] { utf.getQuotationDto(101), utf.getQuotationDto(102), utf.getQuotationDto(103) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); IEnumerable <PriceDto> priceDtos = new PriceDto[] { utf.getPriceDto(101), utf.getPriceDto(102), utf.getPriceDto(103) }; priceRepository.Setup(q => q.GetPrices(queryDef)).Returns(priceDtos); service.InjectQuotationRepository(quotationRepository.Object); service.InjectPriceRepository(priceRepository.Object); DataSet[] result = service.GetDataSets(queryDef, new List <DataSet>()).ToArray(); //Assert DataSet[] expectedDataSets = new DataSet[104]; DataSet ds101 = utf.getDataSet(101); ds101.SetQuotation(utf.getQuotation(ds101)).SetPrice(utf.getPrice(ds101)); DataSet ds102 = utf.getDataSet(102); ds102.SetQuotation(utf.getQuotation(ds102)).SetPrice(utf.getPrice(ds102)); DataSet ds103 = utf.getDataSet(103); ds103.SetQuotation(utf.getQuotation(ds103)).SetPrice(utf.getPrice(ds103)); expectedDataSets[101] = ds101; expectedDataSets[102] = ds102; expectedDataSets[103] = ds103; var areEqual = expectedDataSets.HasEqualItemsInTheSameOrder(result); Assert.IsTrue(areEqual); }
public void GetDataSets_ReturnsCollectionWithExistingItems() { //Arrange:QueryDef IEnumerable <AnalysisType> analysisTypes = new AnalysisType[] { AnalysisType.Prices }; DateTime startDate = new DateTime(2016, 1, 15, 22, 30, 0); DateTime endDate = new DateTime(2016, 1, 15, 22, 50, 0); AnalysisDataQueryDefinition queryDef = new AnalysisDataQueryDefinition(1, 1) { AnalysisTypes = analysisTypes, StartDate = startDate, EndDate = endDate }; //Arrange:Quotations Mock <IQuotationRepository> quotationRepository = new Mock <IQuotationRepository>(); IEnumerable <QuotationDto> quotationDtos = new QuotationDto[] { utf.getQuotationDto(1), utf.getQuotationDto(2), utf.getQuotationDto(3), utf.getQuotationDto(4) }; quotationRepository.Setup(q => q.GetQuotations(queryDef)).Returns(quotationDtos); //Arrange:Prices Mock <IPriceRepository> priceRepository = new Mock <IPriceRepository>(); IEnumerable <PriceDto> priceDtos = new PriceDto[] { utf.getPriceDto(1), utf.getPriceDto(2), utf.getPriceDto(3), utf.getPriceDto(4) }; priceRepository.Setup(p => p.GetPrices(queryDef)).Returns(priceDtos); //Act IDataSetService service = new DataSetService(); service.InjectQuotationRepository(quotationRepository.Object); service.InjectPriceRepository(priceRepository.Object); var dataSets = service.GetDataSets(queryDef); DataSet baseDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 1); queryDef.StartDate = new DateTime(2016, 1, 15, 22, 25, 0); dataSets = service.GetDataSets(queryDef); DataSet comparedDataSet = dataSets.SingleOrDefault(ds => ds.IndexNumber == 1); //Assert var areTheSameObject = (baseDataSet == comparedDataSet); Assert.IsTrue(areTheSameObject); }
public async Task <Boolean> SaveQuotation(QuotationDto quotationDto) { // At the moment, just implement "create" if (quotationDto.Id != 0) { throw new Exception($"Invalid quotationDto id {quotationDto.Id}"); } var fromCurrency = await _currencyService.GetCurrencyByCode(quotationDto.FromCurrencyCode); if (fromCurrency == null) { throw new Exception($"Invalid fromCurrency code {quotationDto.FromCurrencyCode}"); } var toCurrency = await _currencyService.GetCurrencyByCode(quotationDto.ToCurrencyCode); if (toCurrency == null) { throw new Exception($"Invalid ToCurrency code {quotationDto.ToCurrencyCode}"); } var quotation = new Quotation { FirstName = quotationDto.FirstName, LastName = quotationDto.LastName, Email = quotationDto.Email, Phone = quotationDto.Phone, FromCurrency = fromCurrency, ToCurrency = toCurrency, Amount = quotationDto.Amount, OFXCustomerRate = quotationDto.OFXCustomerRate, OFXCustomerAmount = quotationDto.OFXCustomerAmount, CreatedDate = DateTime.Now }; await _dbContext.Quotations.AddAsync(quotation); return(await _dbContext.SaveChangesAsync() > 0); }
public void CopyProperties_AfterwardAllPropertiesAreEqual() { //Arrange var baseItem = new QuotationDto() { QuotationId = 1, PriceDate = new DateTime(2017, 3, 4, 21, 10, 0), AssetId = 1, TimeframeId = 1, OpenPrice = 1.03, HighPrice = 1.04, LowPrice = 1.02, ClosePrice = 1.04, Volume = 100, IndexNumber = 51 }; var comparedItem = new QuotationDto() { QuotationId = 2, PriceDate = new DateTime(2017, 3, 4, 21, 10, 0), AssetId = 2, TimeframeId = 1, OpenPrice = 1.05, HighPrice = 1.02, LowPrice = 1.01, ClosePrice = 1.03, Volume = 103, IndexNumber = 52 }; //Act comparedItem.CopyProperties(baseItem); var areEqual = baseItem.Equals(comparedItem); //Assert Assert.IsTrue(areEqual); }
public async Task <bool> SaveQuotation(QuotationDto quotationDto) { await Task.Delay(1000); return(true); }