Skip to content
Permalink
Browse files

refactoring for tests

  • Loading branch information...
ignatandrei committed Oct 30, 2019
1 parent bcf06fa commit 2112817f929de6941e8c3fbbe113f1083521d855
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29409.12
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfoValutarDOS", "InfoValutarDOS\InfoValutarDOS.csproj", "{5970AD2A-6D01-434C-9F3D-69A32C9E9F47}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "InfoValutarDOS", "InfoValutarDOS\InfoValutarDOS.csproj", "{5970AD2A-6D01-434C-9F3D-69A32C9E9F47}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InfoValutarShared", "InfoValutarShared\InfoValutarShared.csproj", "{9614EE27-D460-40C9-B4B4-8104E7FB1288}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -15,6 +17,10 @@ Global
{5970AD2A-6D01-434C-9F3D-69A32C9E9F47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5970AD2A-6D01-434C-9F3D-69A32C9E9F47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5970AD2A-6D01-434C-9F3D-69A32C9E9F47}.Release|Any CPU.Build.0 = Release|Any CPU
{9614EE27-D460-40C9-B4B4-8104E7FB1288}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9614EE27-D460-40C9-B4B4-8104E7FB1288}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9614EE27-D460-40C9-B4B4-8104E7FB1288}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9614EE27-D460-40C9-B4B4-8104E7FB1288}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -6,4 +6,13 @@
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\InfoValutarShared\InfoValutarShared.csproj" />
</ItemGroup>

</Project>
@@ -1,4 +1,5 @@
using System;
using InfoValutarShared;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -10,40 +11,17 @@ namespace InfoValutarDOS
{
class Program
{
private static readonly HttpClient httpClient=new HttpClient();
static async Task Main(string[] args)
{
var xml = await httpClient.GetStringAsync("https://www.bnr.ro/nbrfxrates.xml");
//Console.WriteLine($"{xml}");
var serializer = new XmlSerializer(typeof(DataSet));
using (var reader = new StringReader(xml))
var nbr = new GetNBRExchange();
var list = nbr.GetActualRates();
await foreach (var e in list)
{
var result = serializer.Deserialize(reader) as DataSet;
var val = result.Body.Cube.First();
var date = val.date;
string orig = "BNR";
var list = new List<ExchangeRates>();
foreach(var item in val.Rate)
{
var exch = new ExchangeRates();
exch.date = date;
exch.ExchangeTo = "RON";
exch.ExchangeFrom= item.currency;
exch.ExchangeValue = item.Value;
if (!string.IsNullOrWhiteSpace(item.multiplier))
{
exch.ExchangeValue = exch.ExchangeValue / (decimal) int.Parse(item.multiplier);
}
list.Add(exch);
}
foreach (var e in list)
{
Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
}

Console.WriteLine($"1 {e.ExchangeFrom} = {e.ExchangeValue} {e.ExchangeTo}");
}


}


}
}
@@ -2,10 +2,11 @@
using System.Collections.Generic;
using System.Text;

namespace InfoValutarDOS
namespace InfoValutarShared
{
class ExchangeRates
public class ExchangeRates
{
public string Bank { get; set; }
public DateTime date { get; set; }
public string ExchangeFrom { get; set; }
public string ExchangeTo { get; set; }
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace InfoValutarShared
{
public class GetNBRExchange
{
private static readonly HttpClient httpClient = new HttpClient();

public async IAsyncEnumerable<ExchangeRates> GetActualRates()
{
var xml = await httpClient.GetStringAsync("https://www.bnr.ro/nbrfxrates.xml");
//Console.WriteLine($"{xml}");
var serializer = new XmlSerializer(typeof(DataSet));
using (var reader = new StringReader(xml))
{
var result = serializer.Deserialize(reader) as DataSet;
var val = result.Body.Cube.First();
var date = val.date;
string orig = "BNR";
foreach (var item in val.Rate)
{
var exch = new ExchangeRates();
exch.Bank = orig;
exch.date = date;
exch.ExchangeTo = "RON";
exch.ExchangeFrom = item.currency;
exch.ExchangeValue = item.Value;
if (!string.IsNullOrWhiteSpace(item.multiplier))
{
exch.ExchangeValue = exch.ExchangeValue / (decimal)int.Parse(item.multiplier);
}
yield return exch;
}


}
}
}
}
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

</Project>
File renamed without changes.

0 comments on commit 2112817

Please sign in to comment.
You can’t perform that action at this time.