public void XmlApiSerializer_DataCoverterDto_NationalBankKz_InValidData_Exception()
        {
            string invalidFileAbsolutePath = Path.GetFullPath("..\\..\\..\\TestData\\NationalBankKz\\invalid_bank_response.xml", Directory.GetCurrentDirectory());
            var    invalidContent          = File.ReadAllText(invalidFileAbsolutePath);

            Assert.Throws <Exception>(() => XmlApiSerializer.DataConverterDto <NationalBankKzDto>(invalidContent));
        }
Exemplo n.º 2
0
        public async Task <IEnumerable <CurrencyRate> > GetCurrencyRatesByDate(DateTime date)
        {
            IEnumerable <CurrencyRate> currencyRates = new List <CurrencyRate>();
            NationalBankKzDto          responseBankClientSerialize = new NationalBankKzDto();

            string responseBankClient = await HttpModule.DownloadData(UrlConfigurator(date));

            responseBankClientSerialize = XmlApiSerializer.DataConverterDto <NationalBankKzDto>(responseBankClient);

            if (responseBankClientSerialize.Error == "введена неверная дата")
            {
                throw new Exception("NationalBankKz - Wrong format date. Error date: " + date);
            }

            if (responseBankClientSerialize.Rates.Count == 0)
            {
                throw new Exception("NationalBankKz - returned error. Date: " + date + ". Add information: " + responseBankClientSerialize.Info);
            }

            currencyRates = responseBankClientSerialize.Rates.Select(currencyItem => new CurrencyRate
            {
                BankId       = BankClientType.NationalBankKz.ToString(),
                CurrencyCode = currencyItem.Code,
                Rate         = currencyItem.Rate / currencyItem.Quantity,
                Timestamp    = date.Date
            });

            return(currencyRates);
        }
        public void XmlApiSerializer_DataCoverterDto_NationalBankKz_ValidData_Success()
        {
            string            validFileAbsolutePath = Path.GetFullPath("..\\..\\..\\TestData\\NationalBankKz\\valid_bank_response.xml", Directory.GetCurrentDirectory());
            string            validContent          = File.ReadAllText(validFileAbsolutePath);
            NationalBankKzDto dtoData = XmlApiSerializer.DataConverterDto <NationalBankKzDto>(validContent);

            Assert.IsType <NationalBankKzDto>(dtoData);
            Assert.Equal(39, dtoData.Rates.Count);
        }