aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.Tests
diff options
context:
space:
mode:
authorSerghei Cebotari <serghei@cebotari.ru>2023-12-08 23:14:56 +0300
committerSerghei Cebotari <serghei@cebotari.ru>2023-12-08 23:14:56 +0300
commitf448cccbebaf9c6cc92f5576cb89e8918b1beec9 (patch)
treee319a8e8e0e4f763d852ae66479f71f67311a9cd /RhSolutions.Tests
parente6546254baf8130638aa0dee12f247769da4e308 (diff)
Add RhSolutions.ProductSku project
Diffstat (limited to 'RhSolutions.Tests')
-rw-r--r--RhSolutions.Tests/RhSolutions.Tests.csproj1
-rw-r--r--RhSolutions.Tests/SkuTests.cs171
2 files changed, 172 insertions, 0 deletions
diff --git a/RhSolutions.Tests/RhSolutions.Tests.csproj b/RhSolutions.Tests/RhSolutions.Tests.csproj
index 8c6b442..b1491cb 100644
--- a/RhSolutions.Tests/RhSolutions.Tests.csproj
+++ b/RhSolutions.Tests/RhSolutions.Tests.csproj
@@ -15,6 +15,7 @@
<ItemGroup>
<ProjectReference Include="..\RhSolutions.AddIn\RhSolutions.AddIn.csproj" />
+ <ProjectReference Include="..\RhSolutions.ProductSku\RhSolutions.ProductSku.csproj" />
</ItemGroup>
</Project>
diff --git a/RhSolutions.Tests/SkuTests.cs b/RhSolutions.Tests/SkuTests.cs
new file mode 100644
index 0000000..ab9a1c2
--- /dev/null
+++ b/RhSolutions.Tests/SkuTests.cs
@@ -0,0 +1,171 @@
+using RhSolutions.Models;
+
+namespace RhSolutions.Tests;
+
+public class SkuTests
+{
+ [Fact]
+ public void EqualityTest()
+ {
+ Product p1 = new("11600011001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ Product p2 = new("11600011001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ Product p3 = new("11600013001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ Assert.True(p1.Equals(p2));
+ Assert.False(p1.Equals(p3));
+ }
+
+ [Fact]
+ public void ProductHashCodeTest()
+ {
+ Product p1 = new("11600011001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ Product p2 = new("11600011001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ Product p3 = new("11600013001")
+ {
+ Name = "Test",
+ ProductLines = new List<string>
+ {
+ "TestLine"
+ },
+ IsOnWarehouse = true,
+ ProductMeasure = Measure.Kg,
+ DeliveryMakeUp = 100.0,
+ Price = 1000
+ };
+
+ int hash1 = p1.GetHashCode();
+ int hash2 = p2.GetHashCode();
+ int hash3 = p3.GetHashCode();
+ Assert.True(hash1 == hash2);
+ Assert.False(hash1 == hash3);
+ }
+
+ [Fact]
+ public void SkuEqualityTest()
+ {
+ ProductSku sku1 = new("160001", "001");
+ ProductSku sku2 = new("11600011001");
+ Assert.True(sku1.Equals(sku2));
+ }
+
+ [Fact]
+ public void SkuHashCodeTest()
+ {
+ ProductSku sku1 = new("160001", "001");
+ ProductSku sku2 = new("11600011001");
+ int hash1 = sku1.GetHashCode();
+ int hash2 = sku2.GetHashCode();
+ Assert.True(hash1 == hash2);
+ }
+
+ [Theory]
+ [InlineData("12222221333")]
+ [InlineData("222222-333")]
+ [InlineData("222222 333")]
+ [InlineData("string 12222221333")]
+ [InlineData("12222221333 string")]
+ [InlineData("string 12222221333 string")]
+ [InlineData("string 222222-333")]
+ [InlineData("222222-333 string")]
+ [InlineData("string 222222-333 string")]
+ [InlineData("string 222222 333")]
+ [InlineData("222222 333 string")]
+ [InlineData("string 222222 333 string")]
+ public void StandardSkuParseTest(string line)
+ {
+ Assert.True(ProductSku.TryParse(line, out var skus));
+ Assert.True(skus.First().Article == "222222"
+ && skus.First().Variant == "333"
+ && skus.First().Delimiter == '1');
+ }
+
+ [Theory]
+ [InlineData("12222223444")]
+ [InlineData("string 12222223444")]
+ [InlineData("12222223444 string")]
+ [InlineData("string 12222223444 string")]
+ public void NewSkuParseTest(string line)
+ {
+ Assert.True(ProductSku.TryParse(line, out var skus));
+ Assert.True(skus.First().Article == "222222"
+ && skus.First().Variant == "444"
+ && skus.First().Delimiter == '3');
+ }
+
+ [Theory]
+ [InlineData("160001-001 11384611001 160002 002 11600033003")]
+ public void MultipleParseTest(string line)
+ {
+ Assert.True(ProductSku.TryParse(line, out var skus));
+ Assert.Equal(4, skus.Count());
+ }
+
+ [Theory]
+ [InlineData("160001 001")]
+ [InlineData("160001*001")]
+ [InlineData("160001001")]
+ [InlineData("31600011001")]
+ public void DoesntParse(string line)
+ {
+ Assert.False(ProductSku.TryParse(line, out _));
+ }
+} \ No newline at end of file