From f44c1f25b3dca11b3225e83edc6f9c8d7e24d8df Mon Sep 17 00:00:00 2001 From: Serghei Cebotari Date: Fri, 29 Sep 2023 10:07:41 +0300 Subject: Add Tests --- RhSolutions.Api.Tests/ProductQueryModifierTests.cs | 40 ++++++++++++++++++++++ RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj | 23 +++++++++++++ RhSolutions.Api.Tests/Usings.cs | 1 + 3 files changed, 64 insertions(+) create mode 100644 RhSolutions.Api.Tests/ProductQueryModifierTests.cs create mode 100644 RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj create mode 100644 RhSolutions.Api.Tests/Usings.cs (limited to 'RhSolutions.Api.Tests') diff --git a/RhSolutions.Api.Tests/ProductQueryModifierTests.cs b/RhSolutions.Api.Tests/ProductQueryModifierTests.cs new file mode 100644 index 0000000..32bc140 --- /dev/null +++ b/RhSolutions.Api.Tests/ProductQueryModifierTests.cs @@ -0,0 +1,40 @@ +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Primitives; +using RhSolutions.Api.Services; + +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 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)); + } +} \ No newline at end of file diff --git a/RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj b/RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj new file mode 100644 index 0000000..4ce8b7c --- /dev/null +++ b/RhSolutions.Api.Tests/RhSolutions.Api.Tests.csproj @@ -0,0 +1,23 @@ + + + + net6.0 + enable + enable + + false + + + + + + + + + + + + + + + diff --git a/RhSolutions.Api.Tests/Usings.cs b/RhSolutions.Api.Tests/Usings.cs new file mode 100644 index 0000000..cefced4 --- /dev/null +++ b/RhSolutions.Api.Tests/Usings.cs @@ -0,0 +1 @@ +global using NUnit.Framework; \ No newline at end of file -- cgit v1.2.3