Compare commits
No commits in common. "1001c683bf9f845a747099de6c2b9e0d5b0b2fb9" and "799b3f40a239b8af547de41222b5565fe2bad954" have entirely different histories.
1001c683bf
...
799b3f40a2
@ -1,26 +1,40 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.Primitives;
|
||||
using RhSolutions.Api.Services;
|
||||
public abstract class ProductQueryModifierTests
|
||||
{
|
||||
protected ProductQueryModifierFactory _factory;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_factory = new ProductQueryModifierFactory();
|
||||
}
|
||||
public void Execute(string productType, string query, string modified)
|
||||
{
|
||||
Dictionary<string, StringValues> queryPair = new()
|
||||
{
|
||||
["query"] = new StringValues(query)
|
||||
};
|
||||
QueryCollection collection = new(queryPair);
|
||||
QueryString expected = new($"?query={Uri.EscapeDataString(modified)}");
|
||||
var modifier = _factory.GetModifier(productType);
|
||||
bool result = modifier.TryQueryModify(collection, out var actual);
|
||||
Assert.True(result);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
namespace RhSolutions.Api.Tests;
|
||||
|
||||
public class ProductQueryModifierTests
|
||||
{
|
||||
private ProductQueryModifierFactory _factory;
|
||||
|
||||
[SetUp]
|
||||
public void Setup()
|
||||
{
|
||||
_factory = new ProductQueryModifierFactory();
|
||||
}
|
||||
|
||||
[TestCase("Монтажная гильза", "Гильза 16", "Монтажная гильза 16")]
|
||||
[TestCase("Монтажная гильза", "Пресс-втулка 20", "Монтажная гильза 20")]
|
||||
public void SleeveTest(string productType, string query, string modified) =>
|
||||
Test(productType, query, modified);
|
||||
|
||||
[TestCase("Тройник RAUTITAN", "Тройник 20-16-16", "Тройник RAUTITAN -PLATINUM 20-16-16")]
|
||||
[TestCase("Тройник RAUTITAN", "Тройник 20x16x16", "Тройник RAUTITAN -PLATINUM 20-16-16")]
|
||||
public void TPieceTest(string productType, string query, string modified) =>
|
||||
Test(productType, query, modified);
|
||||
|
||||
public void Test(string productType, string query, string modified)
|
||||
{
|
||||
Dictionary<string, StringValues> queryPair = new()
|
||||
{
|
||||
["query"] = new StringValues(query)
|
||||
};
|
||||
QueryCollection collection = new(queryPair);
|
||||
QueryString expected = new($"?query={Uri.EscapeDataString(modified)}");
|
||||
var modifier = _factory.GetModifier(productType);
|
||||
bool result = modifier.TryQueryModify(collection, out var actual);
|
||||
Assert.True(result);
|
||||
Assert.That(actual, Is.EqualTo(expected));
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
namespace RhSolutions.Api.Tests;
|
||||
public class RautitanFittingsTests : ProductQueryModifierTests
|
||||
{
|
||||
[TestCase("Гильза 16", "Монтажная гильза 16")]
|
||||
[TestCase("Пресс-втулка 20", "Монтажная гильза 20")]
|
||||
public void SleeveTest(string query, string modified)
|
||||
=> Execute(productType: "Монтажная гильза", query, modified);
|
||||
|
||||
[TestCase("Тройник 20-16-16", "Тройник RAUTITAN -PLATINUM 20-16-16")]
|
||||
[TestCase("Тройник 20x16x16", "Тройник RAUTITAN -PLATINUM 20-16-16")]
|
||||
public void TPieceTest(string query, string modified)
|
||||
=> Execute(productType: "Тройник RAUTITAN", query, modified);
|
||||
|
||||
[TestCase("муфта 20", "Муфта соединительная равнопроходная 20")]
|
||||
[TestCase("переходник 20-16", "Муфта соединительная переходная 20-16")]
|
||||
[TestCase("Соединение труба-труба 20/20, бронза", "Муфта соединительная равнопроходная 20")]
|
||||
public void CouplingTest(string query, string modified)
|
||||
=> Execute(productType: "Муфта соединительная", query, modified);
|
||||
|
||||
[TestCase("Угольник 90°, 40 PX", "Угольник RAUTITAN -PLATINUM 90 40")]
|
||||
public void ElbowTest(string query, string modified)
|
||||
=> Execute(productType: "Угольник RAUTITAN", query, modified);
|
||||
|
||||
[TestCase("Уголок соединительный с ниппелем 20 х 1/2'', бронза", "Угольник-переходник с наружной резьбой 20 1/2")]
|
||||
public void ThreadElbowExternalTest(string query, string modified)
|
||||
=> Execute(productType: "Угольник с наружной резьбой", query, modified);
|
||||
|
||||
[TestCase("Уголок соединительный с муфтой 16 х 1/2\", бронза", "Угольник-переходник с внутренней резьбой 16 1/2")]
|
||||
public void ThreadElbowInternalTest(string query, string modified)
|
||||
=> Execute(productType: "Угольник с внутренней резьбой", query, modified);
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class AdapterExternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с наружной резьбой";
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class AdapterInternalModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с внутренней резьбой";
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public abstract class AdapterModifier : IProductQueryModifier
|
||||
{
|
||||
protected string pattern { get; } =
|
||||
@"(?<Diameter>\b16|20|25|32|40|50|63\b)\D+(?<Thread>\b1\s+1/4|1\s+1/2|1/2|3/4|2|1\b)";
|
||||
protected virtual string name { get; } = string.Empty;
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||
{
|
||||
queryString = QueryString.Empty;
|
||||
var query = collection["query"].ToString();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var matches = Regex.Matches(query, pattern);
|
||||
if (matches.Count < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
var match = matches.First();
|
||||
var diameter = match.Groups["Diameter"].Captures.First();
|
||||
var thread = match.Groups["Thread"].Captures.First();
|
||||
QueryBuilder qb = new()
|
||||
{
|
||||
{"query", $"{name} {diameter} {thread}"}
|
||||
};
|
||||
queryString = qb.ToQueryString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class AdapterScrewcapModifier : AdapterModifier
|
||||
{
|
||||
protected override string name => "Переходник с накидной гайкой";
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class BlackPipeQueryModifier : FlexPipeQueryModifier
|
||||
{
|
||||
protected override string diameterPattern => @"\b(16|20|25)\b";
|
||||
protected override string pipeName => "Black";
|
||||
protected override Dictionary<string, string> diameterNames => new()
|
||||
{
|
||||
["16"] = "16х2,2",
|
||||
["20"] = "20х2,8",
|
||||
["25"] = "25х3,5"
|
||||
};
|
||||
}
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class CouplingModifier : IProductQueryModifier
|
||||
{
|
||||
private string pattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||
{
|
||||
queryString = QueryString.Empty;
|
||||
var query = collection["query"].ToString();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var matches = Regex.Matches(query, pattern);
|
||||
if (matches.Count < 1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
QueryBuilder qb = new();
|
||||
if (matches.Count < 2 || matches.Count > 1 && matches[0].Value == matches[1].Value)
|
||||
{
|
||||
qb.Add("query", $"Муфта соединительная равнопроходная {matches[0]}");
|
||||
}
|
||||
else
|
||||
{
|
||||
qb.Add("query", $"Муфта соединительная переходная {matches[0]}-{matches[1]}");
|
||||
}
|
||||
queryString = qb.ToQueryString();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ElbowModifier : IProductQueryModifier
|
||||
{
|
||||
private string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||||
private string anglePattern { get; } = @"\b(45|90)";
|
||||
public bool TryQueryModify(IQueryCollection collection, out QueryString queryString)
|
||||
{
|
||||
queryString = QueryString.Empty;
|
||||
var query = collection["query"].ToString();
|
||||
if (string.IsNullOrEmpty(query))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var diameter = Regex.Match(query, diameterPattern);
|
||||
if (diameter.Success)
|
||||
{
|
||||
var angle = Regex.Match(query, anglePattern);
|
||||
QueryBuilder qb = new()
|
||||
{
|
||||
{"query", $"Угольник RAUTITAN -PLATINUM {(angle.Success ? angle.Captures.First() : 90)} {diameter.Captures.First()}"}
|
||||
};
|
||||
queryString = qb.ToQueryString();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -4,10 +4,10 @@ using Microsoft.AspNetCore.Http.Extensions;
|
||||
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class FlexPipeQueryModifier : IProductQueryModifier
|
||||
public class FlexPipeQueryModifier : IProductQueryModifier
|
||||
{
|
||||
protected virtual string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||||
protected virtual string typePattern { get; } = @"бухт|отр|штанг";
|
||||
protected virtual string diameterPattern { get; } = @"16|20|25|32|40|50|63";
|
||||
protected virtual string typePattern { get; } = @"(бухт)|(отр)";
|
||||
protected virtual string pipeName { get; } = "Flex";
|
||||
protected virtual Dictionary<string, string> diameterNames { get; } = new()
|
||||
{
|
||||
@ -47,13 +47,13 @@ namespace RhSolutions.Api.Services
|
||||
if (typeMatches.Count > 0)
|
||||
{
|
||||
var type = typeMatches.First().Value;
|
||||
if (type.StartsWith("отр") || type.StartsWith("штанг"))
|
||||
if (type.StartsWith("бухт"))
|
||||
{
|
||||
sb.Append("прям.отрезки");
|
||||
sb.Append("бухта");
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append("бухта");
|
||||
sb.Append("прям.отрезки");
|
||||
}
|
||||
}
|
||||
else if (int.Parse(diameter) < 32)
|
||||
|
@ -10,26 +10,10 @@ public class ProductQueryModifierFactory
|
||||
return new SleeveQueryModifier();
|
||||
case "Тройник RAUTITAN":
|
||||
return new TPieceQueryModifier();
|
||||
case "Переходник на наружную резьбу":
|
||||
return new AdapterExternalModifier();
|
||||
case "Переходник на внутреннюю резьбу":
|
||||
return new AdapterInternalModifier();
|
||||
case "Переходник с накидной гайкой":
|
||||
return new AdapterScrewcapModifier();
|
||||
case "Угольник с наружной резьбой":
|
||||
return new ThreadElbowExternal();
|
||||
case "Угольник с внутренней резьбой":
|
||||
return new ThreadElbowInternal();
|
||||
case "Муфта соединительная":
|
||||
return new CouplingModifier();
|
||||
case "Угольник RAUTITAN":
|
||||
return new ElbowModifier();
|
||||
case "Flex":
|
||||
return new FlexPipeQueryModifier();
|
||||
case "Stabil":
|
||||
return new StabilPipeQueryModifier();
|
||||
case "Black":
|
||||
return new BlackPipeQueryModifier();
|
||||
default:
|
||||
return new BypassQueryModifier();
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class StabilPipeQueryModifier : FlexPipeQueryModifier
|
||||
{
|
||||
protected override string diameterPattern => @"\b(16|20|25|32|40)\b";
|
||||
protected override string diameterPattern => @"16|20|25|32|40";
|
||||
protected override string pipeName => "Stabil -PLATINUM";
|
||||
protected override Dictionary<string, string> diameterNames => new()
|
||||
{
|
||||
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ThreadElbowExternal : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с наружной резьбой";
|
||||
}
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace RhSolutions.Api.Services
|
||||
{
|
||||
public class ThreadElbowInternal : AdapterModifier
|
||||
{
|
||||
protected override string name => "Угольник-переходник с внутренней резьбой";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user