Compare commits
9 Commits
799b3f40a2
...
1001c683bf
Author | SHA1 | Date | |
---|---|---|---|
1001c683bf | |||
f1d196da91 | |||
28f85e5c9d | |||
c8d55895bb | |||
eb14b9a82a | |||
be49549723 | |||
fe96662905 | |||
aa330461c6 | |||
b369384931 |
@ -1,30 +1,16 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.Extensions.Primitives;
|
using Microsoft.Extensions.Primitives;
|
||||||
using RhSolutions.Api.Services;
|
using RhSolutions.Api.Services;
|
||||||
|
public abstract class ProductQueryModifierTests
|
||||||
namespace RhSolutions.Api.Tests;
|
|
||||||
|
|
||||||
public class ProductQueryModifierTests
|
|
||||||
{
|
{
|
||||||
private ProductQueryModifierFactory _factory;
|
protected ProductQueryModifierFactory _factory;
|
||||||
|
|
||||||
[SetUp]
|
[SetUp]
|
||||||
public void Setup()
|
public void Setup()
|
||||||
{
|
{
|
||||||
_factory = new ProductQueryModifierFactory();
|
_factory = new ProductQueryModifierFactory();
|
||||||
}
|
}
|
||||||
|
public void Execute(string productType, string query, string modified)
|
||||||
[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()
|
Dictionary<string, StringValues> queryPair = new()
|
||||||
{
|
{
|
||||||
|
31
RhSolutions.Api.Tests/RautitanFittingsTests.cs
Normal file
31
RhSolutions.Api.Tests/RautitanFittingsTests.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
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);
|
||||||
|
}
|
7
RhSolutions.Api/Services/AdapterExternalModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterExternalModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterExternalModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с наружной резьбой";
|
||||||
|
}
|
||||||
|
}
|
7
RhSolutions.Api/Services/AdapterInternalModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterInternalModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterInternalModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с внутренней резьбой";
|
||||||
|
}
|
||||||
|
}
|
39
RhSolutions.Api/Services/AdapterModifier.cs
Normal file
39
RhSolutions.Api/Services/AdapterModifier.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
RhSolutions.Api/Services/AdapterScrewcapModifier.cs
Normal file
7
RhSolutions.Api/Services/AdapterScrewcapModifier.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class AdapterScrewcapModifier : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Переходник с накидной гайкой";
|
||||||
|
}
|
||||||
|
}
|
14
RhSolutions.Api/Services/BlackPipeQueryModifier.cs
Normal file
14
RhSolutions.Api/Services/BlackPipeQueryModifier.cs
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
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"
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
39
RhSolutions.Api/Services/CouplingModifier.cs
Normal file
39
RhSolutions.Api/Services/CouplingModifier.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
36
RhSolutions.Api/Services/ElbowModifier.cs
Normal file
36
RhSolutions.Api/Services/ElbowModifier.cs
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,8 +6,8 @@ namespace RhSolutions.Api.Services
|
|||||||
{
|
{
|
||||||
public class FlexPipeQueryModifier : IProductQueryModifier
|
public class FlexPipeQueryModifier : IProductQueryModifier
|
||||||
{
|
{
|
||||||
protected virtual string diameterPattern { get; } = @"16|20|25|32|40|50|63";
|
protected virtual string diameterPattern { get; } = @"\b(16|20|25|32|40|50|63)\b";
|
||||||
protected virtual string typePattern { get; } = @"(бухт)|(отр)";
|
protected virtual string typePattern { get; } = @"бухт|отр|штанг";
|
||||||
protected virtual string pipeName { get; } = "Flex";
|
protected virtual string pipeName { get; } = "Flex";
|
||||||
protected virtual Dictionary<string, string> diameterNames { get; } = new()
|
protected virtual Dictionary<string, string> diameterNames { get; } = new()
|
||||||
{
|
{
|
||||||
@ -47,13 +47,13 @@ namespace RhSolutions.Api.Services
|
|||||||
if (typeMatches.Count > 0)
|
if (typeMatches.Count > 0)
|
||||||
{
|
{
|
||||||
var type = typeMatches.First().Value;
|
var type = typeMatches.First().Value;
|
||||||
if (type.StartsWith("бухт"))
|
if (type.StartsWith("отр") || type.StartsWith("штанг"))
|
||||||
{
|
{
|
||||||
sb.Append("бухта");
|
sb.Append("прям.отрезки");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sb.Append("прям.отрезки");
|
sb.Append("бухта");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (int.Parse(diameter) < 32)
|
else if (int.Parse(diameter) < 32)
|
||||||
|
@ -10,10 +10,26 @@ public class ProductQueryModifierFactory
|
|||||||
return new SleeveQueryModifier();
|
return new SleeveQueryModifier();
|
||||||
case "Тройник RAUTITAN":
|
case "Тройник RAUTITAN":
|
||||||
return new TPieceQueryModifier();
|
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":
|
case "Flex":
|
||||||
return new FlexPipeQueryModifier();
|
return new FlexPipeQueryModifier();
|
||||||
case "Stabil":
|
case "Stabil":
|
||||||
return new StabilPipeQueryModifier();
|
return new StabilPipeQueryModifier();
|
||||||
|
case "Black":
|
||||||
|
return new BlackPipeQueryModifier();
|
||||||
default:
|
default:
|
||||||
return new BypassQueryModifier();
|
return new BypassQueryModifier();
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ namespace RhSolutions.Api.Services
|
|||||||
{
|
{
|
||||||
public class StabilPipeQueryModifier : FlexPipeQueryModifier
|
public class StabilPipeQueryModifier : FlexPipeQueryModifier
|
||||||
{
|
{
|
||||||
protected override string diameterPattern => @"16|20|25|32|40";
|
protected override string diameterPattern => @"\b(16|20|25|32|40)\b";
|
||||||
protected override string pipeName => "Stabil -PLATINUM";
|
protected override string pipeName => "Stabil -PLATINUM";
|
||||||
protected override Dictionary<string, string> diameterNames => new()
|
protected override Dictionary<string, string> diameterNames => new()
|
||||||
{
|
{
|
||||||
|
7
RhSolutions.Api/Services/ThreadElbowExternal.cs
Normal file
7
RhSolutions.Api/Services/ThreadElbowExternal.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class ThreadElbowExternal : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Угольник-переходник с наружной резьбой";
|
||||||
|
}
|
||||||
|
}
|
7
RhSolutions.Api/Services/ThreadElbowInternal.cs
Normal file
7
RhSolutions.Api/Services/ThreadElbowInternal.cs
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
namespace RhSolutions.Api.Services
|
||||||
|
{
|
||||||
|
public class ThreadElbowInternal : AdapterModifier
|
||||||
|
{
|
||||||
|
protected override string name => "Угольник-переходник с внутренней резьбой";
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user