Add MsTests; improvements, fixes, etc...

This commit is contained in:
Loretta 2025-09-09 04:38:08 +02:00
parent 4538c0a4b9
commit 07b4e5f558
12 changed files with 216 additions and 3 deletions

View File

@ -0,0 +1,6 @@
namespace FruitBank.Common.Dtos;
public class CustomerDto
{
}

View File

@ -0,0 +1,6 @@
namespace FruitBank.Common.Dtos;
public class ProductDto
{
}

View File

@ -13,6 +13,10 @@ public class Shipping : MgEntityBase, IShipping
public DateTime ShippingDate { get; set; }
public string LicencePlate { get; set; }
//[Association(ThisKey = nameof(ShippingDocumentId), OtherKey = nameof(ShippingItem.sh))]
//public IEnumerable<Shipping> Shippings { get; set; }
[SkipValuesOnUpdate]
public DateTime Created { get; set; }
public DateTime Modified { get; set; }

View File

@ -2,6 +2,8 @@
using FruitBank.Common.Interfaces;
using LinqToDB.Mapping;
using Mango.Nop.Core.Entities;
using Nop.Core.Domain.Customers;
using Nop.Core.Domain.Orders;
namespace FruitBank.Common.Entities;
@ -10,6 +12,10 @@ namespace FruitBank.Common.Entities;
public class ShippingItem : MgEntityBase, IShippingItem
{
public int Id { get; set; }
//[Association(ThisKey = nameof(ShippingDocumentId), OtherKey = nameof(Shipping.Id))]
//public IEnumerable<Shipping> Shippings { get; set; }
public int ShippingDocumentId { get; set; }
public string Name { get; set; }
public double NetWeight { get; set; }

View File

@ -7,16 +7,25 @@ public interface IFruitBankDataControllerCommon
{
public Task<List<MeasuringModel>?> GetMeasuringModels();
public Task<MeasuringModel?> GetMeasuringModelByShippingId(int shippingId);
#region Partner
public Task<List<Partner>?> GetPartners();
public Task<Partner?> GetPartnerById(int id);
public Task<Partner?> UpdatePartner(Partner partner);
#endregion Partner
#region Shipping
public Task<List<Shipping>?> GetShippings();
public Task<Shipping?> GetShippingById(int id);
#endregion Shipping
public Task<List<ShippingItem>?> GetShippingItem();
#region ShippingItem
public Task<List<ShippingItem>?> GetShippingItems();
public Task<ShippingItem?> GetShippingItemById(int id);
#endregion ShippingItem
#region ShippingDocument
public Task<List<ShippingDocument>?> GetShippingDocuments();
public Task<ShippingDocument?> GetShippingDocumentById(int id);
#endregion ShippingDocument
}

View File

@ -11,6 +11,7 @@ public class SignalRTags : AcSignalRTags
public const int GetPartners = 20;
public const int GetPartnerById = 21;
public const int UpdatePartner = 25;
public const int GetShippings = 40;
public const int GetShippingById = 41;

View File

@ -0,0 +1,128 @@
using AyCode.Core.Consts;
using AyCode.Core.Enums;
using AyCode.Core.Loggers;
using FruitBank.Common.Entities;
using FruitBank.Common.Loggers;
using FruitBankHybrid.Shared.Services.SignalRs;
namespace FruitBankHybrid.Shared.Tests
{
[TestClass]
public sealed class FruitBankClientTests
{
private FruitBankSignalRClient _signalRClient = null!;
[TestInitialize]
public void TestInit()
{
_signalRClient = new FruitBankSignalRClient(new List<IAcLogWriterClientBase>
{
//new ConsoleLogWriter(AppType.TestUnit, LogLevel.Detail, nameof(FruitBankClientTests)),
new SignaRClientLogItemWriter(AppType.TestUnit, LogLevel.Detail, nameof(FruitBankClientTests))
});
}
#region Partner
[TestMethod]
public async Task GetPartnersTest()
{
var partners = await _signalRClient.GetPartners();
Assert.IsNotNull(partners);
Assert.IsTrue(partners.Any());
}
//[DataTestMethod]
//[DataRow(1)]
public async Task<Partner> GetPartnerByIdTest(int partnerId)
{
var partner = await _signalRClient.GetPartnerById(partnerId);
Assert.IsNotNull(partner);
Assert.IsTrue(partner.Id == partnerId);
return partner;
}
[DataTestMethod]
[DataRow(2)]
public async Task UpdatePartnerTest(int partnerId)
{
var partner = await GetPartnerByIdTest(partnerId);
const string fixture = "_test.temp";
var newName = $"{partner.Name.Replace(fixture, string.Empty)}{fixture}";
partner.Name = newName;
await _signalRClient.UpdatePartner(partner);
partner = await GetPartnerByIdTest(partnerId);
Assert.IsTrue(partner.Name == newName);
partner.Name = partner.Name.Replace(fixture, string.Empty);
await _signalRClient.UpdatePartner(partner);
}
#endregion Partner
#region Shipping
[TestMethod]
public async Task GetShippingsTest()
{
var shippings = await _signalRClient.GetShippings();
Assert.IsNotNull(shippings);
Assert.IsTrue(shippings.Any());
}
[TestMethod]
public async Task GetShippingByIdTest()
{
var shipping = await _signalRClient.GetShippingById(1);
Assert.IsNotNull(shipping);
Assert.IsTrue(shipping.Id == 1);
}
#endregion Shipping
#region ShippingItem
[TestMethod]
public async Task GetShippingItemsTest()
{
var shippingItems = await _signalRClient.GetShippingItems();
Assert.IsNotNull(shippingItems);
Assert.IsTrue(shippingItems.Any());
}
[TestMethod]
public async Task GetShippingItemByIdTest()
{
var shippingItem = await _signalRClient.GetShippingItemById(1);
Assert.IsNotNull(shippingItem);
Assert.IsTrue(shippingItem.Id == 1);
}
#endregion ShippingItem
#region ShippingDocument
[TestMethod]
public async Task GetShippingDocumentsTest()
{
var shippingDocuments = await _signalRClient.GetShippingDocuments();
Assert.IsNotNull(shippingDocuments);
Assert.IsTrue(shippingDocuments.Any());
}
[TestMethod]
public async Task GetShippingDocumentByIdTest()
{
var shippingDocument = await _signalRClient.GetShippingDocumentById(1);
Assert.IsNotNull(shippingDocument);
Assert.IsTrue(shippingDocument.Id == 1);
}
#endregion ShippingDocument
}
}

View File

@ -0,0 +1,33 @@
<Project Sdk="MSTest.Sdk/3.6.4">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<!--
Displays error on console in addition to the log file. Note that this feature comes with a performance impact.
For more information, visit https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-integration-dotnet-test#show-failure-per-test
-->
<TestingPlatformShowTestsFailure>true</TestingPlatformShowTestsFailure>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\FruitBank.Common\FruitBank.Common.csproj" />
<ProjectReference Include="..\FruitBankHybrid.Shared.Common\FruitBankHybrid.Shared.Common.csproj" />
<ProjectReference Include="..\FruitBankHybrid.Shared\FruitBankHybrid.Shared.csproj" />
</ItemGroup>
<ItemGroup>
<Reference Include="AyCode.Core">
<HintPath>..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Core.dll</HintPath>
</Reference>
<Reference Include="AyCode.Entities">
<HintPath>..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Entities.dll</HintPath>
</Reference>
<Reference Include="AyCode.Services">
<HintPath>..\..\..\..\Aycode\Source\AyCode.Core\AyCode.Services.Server\bin\FruitBank\Debug\net9.0\AyCode.Services.dll</HintPath>
</Reference>
</ItemGroup>
</Project>

View File

@ -0,0 +1 @@
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]

View File

@ -34,25 +34,37 @@ namespace FruitBankHybrid.Shared.Services.SignalRs
public Task<List<Partner>?> GetPartners()
=> GetAllAsync<List<Partner>>(SignalRTags.GetPartners);
#region Partner
public Task<Partner?> GetPartnerById(int id)
=> GetByIdAsync<Partner?>(SignalRTags.GetPartnerById, id);
public Task<Partner?> UpdatePartner(Partner partner)
=>PostDataAsync<Partner>(SignalRTags.UpdatePartner, partner);
#endregion Partner
#region Shipping
public Task<List<Shipping>?> GetShippings()
=> GetAllAsync<List<Shipping>>(SignalRTags.GetShippings);
public Task<Shipping?> GetShippingById(int id)
=> GetByIdAsync<Shipping?>(SignalRTags.GetShippingById, id);
#endregion Shipping
public Task<List<ShippingItem>?> GetShippingItem()
#region ShippingItem
public Task<List<ShippingItem>?> GetShippingItems()
=> GetAllAsync<List<ShippingItem>>(SignalRTags.GetShippingItems);
public Task<ShippingItem?> GetShippingItemById(int id)
=> GetByIdAsync<ShippingItem?>(SignalRTags.GetShippingItemById, id);
#endregion ShippingItem
#region ShippingDocument
public Task<List<ShippingDocument>?> GetShippingDocuments()
=> GetAllAsync<List<ShippingDocument>>(SignalRTags.GetShippingDocuments);
public Task<ShippingDocument?> GetShippingDocumentById(int id)
=> GetByIdAsync<ShippingDocument?>(SignalRTags.GetShippingDocumentById, id);
#endregion ShippingDocument
}
}

View File

@ -10,6 +10,7 @@
<ProjectReference Include="..\FruitBank.Common.Server\FruitBank.Common.Server.csproj" />
<ProjectReference Include="..\FruitBank.Common\FruitBank.Common.csproj" />
<ProjectReference Include="..\FruitBankHybrid.Shared.Common\FruitBankHybrid.Shared.Common.csproj" />
<ProjectReference Include="..\FruitBankHybrid.Shared\FruitBankHybrid.Shared.csproj" />
<ProjectReference Include="..\FruitBankHybrid.Web.Client\FruitBankHybrid.Web.Client.csproj" />
<PackageReference Include="MessagePack" Version="3.1.4" />
<PackageReference Include="MessagePack.Annotations" Version="3.1.4" />

View File

@ -16,6 +16,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FruitBank.Common", "FruitBa
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FruitBank.Common.Server", "FruitBank.Common.Server\FruitBank.Common.Server.csproj", "{AD3AB968-A79F-485C-8B3E-B6917A5E4C71}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FruitBankHybrid.Shared.Tests", "FruitBankHybrid.Shared.Tests\FruitBankHybrid.Shared.Tests.csproj", "{BE107917-831F-45E6-87F3-96D1DF418309}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -51,6 +53,10 @@ Global
{AD3AB968-A79F-485C-8B3E-B6917A5E4C71}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD3AB968-A79F-485C-8B3E-B6917A5E4C71}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD3AB968-A79F-485C-8B3E-B6917A5E4C71}.Release|Any CPU.Build.0 = Release|Any CPU
{BE107917-831F-45E6-87F3-96D1DF418309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BE107917-831F-45E6-87F3-96D1DF418309}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BE107917-831F-45E6-87F3-96D1DF418309}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BE107917-831F-45E6-87F3-96D1DF418309}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE