54 lines
1.5 KiB
C#
54 lines
1.5 KiB
C#
using Microsoft.Extensions.Logging;
|
|
using StopShopping.Services.Implementions;
|
|
|
|
namespace StopShopping.Services.Test;
|
|
|
|
[TestClass]
|
|
public sealed class SerialNoGeneratorTests
|
|
{
|
|
[ClassInitialize]
|
|
public static void Init(TestContext testContext)
|
|
{
|
|
_serialNoGenerator = new SerialNoGenerator(
|
|
LoggerFactory.Create(options => options.AddConsole()).CreateLogger<SerialNoGenerator>());
|
|
_nanoidGenerator = new NanoidSerialNoGenerator();
|
|
}
|
|
|
|
private static SerialNoGenerator? _serialNoGenerator;
|
|
private static NanoidSerialNoGenerator? _nanoidGenerator;
|
|
|
|
[TestMethod]
|
|
[DataRow(10)]
|
|
public void Gen_Right_Count(int count)
|
|
{
|
|
List<string> serialNos = [];
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
var no = _serialNoGenerator?.GenerateRequestNo();
|
|
if (!string.IsNullOrWhiteSpace(no))
|
|
serialNos.Add(no);
|
|
}
|
|
|
|
serialNos.ForEach(s => Console.WriteLine("{0} - {1}", s, Convert.ToString(long.Parse(s[1..]), toBase: 2)));
|
|
|
|
Assert.HasCount(count, serialNos);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(10)]
|
|
public void Nanoid_Gen_Right_Count(int count)
|
|
{
|
|
List<string> serialNos = [];
|
|
for (var i = 0; i < count; i++)
|
|
{
|
|
var no = _nanoidGenerator?.GenerateRequestNo();
|
|
if (!string.IsNullOrWhiteSpace(no))
|
|
serialNos.Add(no);
|
|
}
|
|
|
|
serialNos.ForEach(s => Console.WriteLine(s));
|
|
|
|
Assert.HasCount(count, serialNos);
|
|
}
|
|
}
|