104 lines
4.1 KiB
C#
104 lines
4.1 KiB
C#
using AyCode.Core.Enums;
|
|
using AyCode.Core.Extensions;
|
|
using AyCode.Core.Loggers;
|
|
using FruitBank.Common;
|
|
using FruitBank.Common.Dtos;
|
|
using FruitBank.Common.Entities;
|
|
using FruitBank.Common.Loggers;
|
|
using FruitBankHybrid.Shared.Services.SignalRs;
|
|
using Newtonsoft.Json;
|
|
using Nop.Core.Domain.Common;
|
|
using Nop.Core.Domain.Orders;
|
|
using Nop.Core.Domain.Payments;
|
|
using System.Linq.Expressions;
|
|
using System.Runtime.Serialization;
|
|
using AyCode.Core.Serializers.Toons;
|
|
|
|
namespace FruitBankHybrid.Shared.Tests;
|
|
|
|
[TestClass]
|
|
public sealed class ToonTests
|
|
{
|
|
private const int CustomerIdAasdDsserverCom = 6; //aasd@dsserver.com
|
|
|
|
private FruitBankSignalRClient _signalRClient = null!;
|
|
|
|
[TestInitialize]
|
|
public void TestInit()
|
|
{
|
|
if (!FruitBankConstClient.BaseUrl.Contains("localhost:")) throw new Exception("NEM LOCALHOST-ON TESZTELÜNK!");
|
|
|
|
_signalRClient = new FruitBankSignalRClient(new List<IAcLogWriterClientBase>
|
|
{
|
|
//new ConsoleLogWriter(AppType.TestUnit, LogLevel.Detail, nameof(FruitBankClientTests)),
|
|
new SignaRClientLogItemWriter(AppType.TestUnit, LogLevel.Detail, nameof(FruitBankClientTests))
|
|
});
|
|
}
|
|
|
|
|
|
[TestMethod]
|
|
public void OrderDtoToToon()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
|
|
Console.WriteLine(toon);
|
|
Assert.IsNotEmpty(toon);
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToonTypes_ShouldNotContainList1OrGenericTypeNames()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
StringAssert.DoesNotMatch(toon, new System.Text.RegularExpressions.Regex(@"List`?1"), "A @meta.types vagy @types szekcióban nem szerepelhet List`1 vagy generikus típusnév.");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToonTypes_ShouldNotContainDuplicateTypeNames()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
var typesLine = toon.Split('\n').FirstOrDefault(x => x.TrimStart().StartsWith("types = ["));
|
|
Assert.IsNotNull(typesLine, "Nem található types lista a @meta szekcióban.");
|
|
var typeNames = typesLine.Substring(typesLine.IndexOf('[') + 1, typesLine.LastIndexOf(']') - typesLine.IndexOf('[') - 1)
|
|
.Split(',').Select(x => x.Trim(' ', '"')).Where(x => !string.IsNullOrWhiteSpace(x)).ToList();
|
|
var duplicates = typeNames.GroupBy(x => x).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
|
|
Assert.IsTrue(duplicates.Count == 0, $"A types listában duplikált típusnév található: {string.Join(", ", duplicates)}");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToonTypes_EachTypeShouldBeDefinedOnceInTypesSection()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
var typeDefLines = toon.Split('\n').Where(x => x.TrimEnd().EndsWith(": \"Object of type") || x.TrimEnd().EndsWith(": enum") || x.TrimEnd().EndsWith(": \"Object of type "));
|
|
var typeNames = typeDefLines.Select(x => x.Trim().Split(':')[0]).ToList();
|
|
var duplicates = typeNames.GroupBy(x => x).Where(g => g.Count() > 1).Select(g => g.Key).ToList();
|
|
Assert.IsTrue(duplicates.Count == 0, $"A @types szekcióban duplikált típusdefiníció található: {string.Join(", ", duplicates)}");
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToonTypes_PropertyTypesShouldNotReferenceList1()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
var lines = toon.Split('\n');
|
|
foreach (var line in lines)
|
|
{
|
|
if (line.Trim().EndsWith(": List`1"))
|
|
{
|
|
Assert.Fail($"Property List`1 típusra hivatkozik: {line.Trim()}");
|
|
}
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
public void ToonTypes_PropertyDescriptions_ShouldNotBeRedundantOrMisleading()
|
|
{
|
|
var toon = AcToonSerializer.SerializeTypeMetadata<OrderDto>();
|
|
var lines = toon.Split('\n');
|
|
foreach (var line in lines)
|
|
{
|
|
if (line.Trim().StartsWith("description:") && line.Contains("Collection of Object for"))
|
|
{
|
|
Assert.Fail($"Redundáns vagy félrevezető description: {line.Trim()}");
|
|
}
|
|
}
|
|
}
|
|
} |