Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
with
1,081 additions
and 9 deletions.
- +3 −0 CashQuotes.sln
- +11 −3 Services/QuoteService/QuoteService.csproj
- +17 −1 Services/QuoteService/Services/Rbc/QueryBuilder.cs
- +19 −1 Services/QuoteService/Services/Rbc/QuoteDataProvider.cs
- +45 −1 Services/QuoteService/Services/Rbc/QuoteService.cs
- +45 −0 Services/QuoteService/Utils/ConvertHelper.cs
- +23 −0 Services/QuoteService/Utils/ExtensionMethods.cs
- +31 −0 Services/QuoteService/Utils/RequestHelper.cs
- +4 −0 Services/QuoteService/packages.config
- +875 −0 Tests/Tests.Unit/MockData/test-data.html
- +4 −1 Tests/Tests.Unit/Tests.Unit.csproj
- +4 −2 Tests/Tests.Unit/Utils/MockQuoteDataProvider.cs
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Globalization; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace QuoteService.Utils | ||
{ | ||
public class ConvertHelper | ||
{ | ||
public static readonly CultureInfo DefaultCultureInfo = new CultureInfo("ru-RU"); | ||
|
||
public static decimal? ConvertDecimal(string text) | ||
{ | ||
if (string.IsNullOrEmpty(text)) | ||
return null; | ||
|
||
return Decimal.Parse(text, new NumberFormatInfo { NumberDecimalSeparator = "." }); | ||
} | ||
|
||
public static DateTime ConvertDate(string date) | ||
{ | ||
var result = DateTime.MinValue; | ||
if (string.IsNullOrEmpty(date)) | ||
return result; | ||
|
||
DateTime.TryParse(date, DefaultCultureInfo, DateTimeStyles.None, out result); | ||
|
||
return result; | ||
} | ||
|
||
public static TimeSpan ConvertTime(string time) | ||
{ | ||
var result = TimeSpan.MinValue; | ||
if (string.IsNullOrEmpty(time)) | ||
return result; | ||
|
||
TimeSpan.TryParse(time, DefaultCultureInfo, out result); | ||
|
||
return result; | ||
} | ||
|
||
} | ||
} |
@@ -0,0 +1,23 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net; | ||
using HtmlAgilityPack; | ||
|
||
namespace QuoteService.Utils | ||
{ | ||
public static class HtmlNodeListExtensionMethods | ||
{ | ||
public static HtmlNode GetHtmlNodeByClass<T>(this IList<T> list, string className) where T : HtmlNode | ||
{ | ||
return list.FirstOrDefault(c => c.Attributes["class"] != null && c.Attributes["class"].Value == className); | ||
} | ||
|
||
public static string ExtractTextForHtmlNodeByClass<T>(this IList<T> list, string className) where T : HtmlNode | ||
{ | ||
var item = list.GetHtmlNodeByClass(className); | ||
|
||
return item != null ? WebUtility.HtmlDecode(item.InnerText) : string.Empty; | ||
} | ||
|
||
} | ||
} |
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace QuoteService.Utils | ||
{ | ||
public class RequestHelper | ||
{ | ||
internal static bool TryGetUri(string uriString, out Uri uri) | ||
{ | ||
// Note that this app has both "Internet (Client)" and "Home and Work Networking" capabilities set, | ||
// since the user may provide URIs for servers located on the internet or intranet. If apps only | ||
// communicate with servers on the internet, only the "Internet (Client)" capability should be set. | ||
// Similarly if an app is only intended to communicate on the intranet, only the "Home and Work | ||
// Networking" capability should be set. | ||
if (!Uri.TryCreate(uriString.Trim(), UriKind.Absolute, out uri)) | ||
{ | ||
return false; | ||
} | ||
|
||
if (uri.Scheme != "http" && uri.Scheme != "https") | ||
{ | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} | ||
} |
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="HtmlAgilityPack" version="1.4.9" targetFramework="portable-net451+win81+wpa81" /> | ||
</packages> |
Oops, something went wrong.