aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Tests/ProductTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'RhSolutions.SkuParser.Tests/ProductTests.cs')
-rw-r--r--RhSolutions.SkuParser.Tests/ProductTests.cs75
1 files changed, 75 insertions, 0 deletions
diff --git a/RhSolutions.SkuParser.Tests/ProductTests.cs b/RhSolutions.SkuParser.Tests/ProductTests.cs
new file mode 100644
index 0000000..12f0944
--- /dev/null
+++ b/RhSolutions.SkuParser.Tests/ProductTests.cs
@@ -0,0 +1,75 @@
+namespace RhSolutions.SkuParser.Tests;
+
+public class ProductTests
+{
+ [TestCase("12222221001")]
+ [TestCase("12222223001")]
+ [TestCase("160001-001")]
+ public void SimpleParse(string value)
+ {
+ Assert.True(Product.TryParse(value, out _));
+ }
+
+ [TestCase("string 12222221001")]
+ [TestCase("12222223001 string")]
+ [TestCase("string 160001-001")]
+ [TestCase("160001-001 string ")]
+ [TestCase("11096641001 Трубка РЕХАУ из. нерж. стали для подкл. радиатора, Г-образная 16/250")]
+ public void AdvancedParse(string value)
+ {
+ Assert.True(Product.TryParse(value, out _));
+ }
+
+ [TestCase("11600011001")]
+ [TestCase("160001-001")]
+ public void ProductIsCorrect(string value)
+ {
+ if (Product.TryParse(value, out Product? product))
+ {
+ Assert.That(product!.Sku, Is.EqualTo("11600011001"));
+ }
+ else
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ }
+
+ [TestCase("1222222001")]
+ [TestCase("12222225001")]
+ public void NotParses(string value)
+ {
+ Assert.False(Product.TryParse(value, out _));
+ }
+
+ [Test]
+ public void ProductEquality()
+ {
+ string value = "12222223001";
+ Product.TryParse(value, out Product? first);
+ Product.TryParse(value, out Product? second);
+ if (first == null || second == null)
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ else
+ {
+ Assert.True(first.Equals(second));
+ }
+ }
+
+ [Test]
+ public void HashTest()
+ {
+ string value = "12222223001";
+ HashSet<Product> set = new();
+ if (Product.TryParse(value, out var product))
+ {
+ set.Add(product!);
+ }
+ else
+ {
+ Assert.Fail($"Parsing failed on {value}");
+ }
+ Assert.True(set.Contains(product!));
+ }
+} \ No newline at end of file