aboutsummaryrefslogtreecommitdiff
path: root/RhSolutions.SkuParser.Tests/ProductTests.cs
blob: 12f0944cbe16fb7fa16b5fa9e7fbd202dfe43c23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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!));
	}
}