74 lines
1.5 KiB
C#
74 lines
1.5 KiB
C#
|
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 ")]
|
||
|
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!));
|
||
|
}
|
||
|
}
|