1
0

75 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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!));
}
}