667 lines
30 KiB
C#
667 lines
30 KiB
C#
using AyCode.Core.Enums;
|
|
using AyCode.Core.Loggers;
|
|
using AyCode.Utils.Extensions;
|
|
using FruitBank.Common;
|
|
using FruitBank.Common.Dtos;
|
|
using FruitBank.Common.Entities;
|
|
using FruitBank.Common.Interfaces;
|
|
using FruitBank.Common.Loggers;
|
|
using FruitBankHybrid.Shared.Services.SignalRs;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using System.Runtime.InteropServices.JavaScript;
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
// ReSharper disable CompareOfFloatsByEqualityOperator
|
|
|
|
namespace FruitBankHybrid.Shared.Tests
|
|
{
|
|
[TestClass]
|
|
public sealed class FruitBankClientTests
|
|
{
|
|
private const int CustomerIdAasdDsserverCom = 6;//aasd@dsserver.com
|
|
private const string Fixture = "_test.temp";
|
|
|
|
private FruitBankSignalRClient _signalRClient = null!;
|
|
|
|
private static string GetFixtureName(string name) => $"{GetOriginalName(name)}{Fixture}";
|
|
private static string GetOriginalName(string name) => name.Replace(Fixture, string.Empty);
|
|
|
|
[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))
|
|
});
|
|
}
|
|
|
|
#region Partner
|
|
|
|
[TestMethod]
|
|
public async Task GetPartnersTest()
|
|
{
|
|
var partners = await _signalRClient.GetPartners();
|
|
|
|
Assert.IsNotNull(partners);
|
|
Assert.IsTrue(partners.Count != 0);
|
|
}
|
|
|
|
//[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);
|
|
|
|
var newName = GetFixtureName(partner.Name);
|
|
|
|
partner.Name = newName;
|
|
partner = await _signalRClient.UpdatePartner(partner);
|
|
|
|
Assert.IsNotNull(partner);
|
|
Assert.IsTrue(partner.Name == newName);
|
|
|
|
partner.Name = GetOriginalName(partner.Name);
|
|
partner = await _signalRClient.UpdatePartner(partner);
|
|
|
|
Assert.IsNotNull(partner);
|
|
Assert.IsTrue(partner.Id == partnerId);
|
|
}
|
|
#endregion Partner
|
|
|
|
#region Shipping
|
|
[TestMethod]
|
|
public async Task GetShippingsTest()
|
|
{
|
|
var shippings = await _signalRClient.GetShippings();
|
|
|
|
Assert.IsNotNull(shippings);
|
|
Assert.IsTrue(shippings.Count != 0);
|
|
}
|
|
|
|
[TestMethod]
|
|
public async Task GetNotMeasuredShippingsTest()
|
|
{
|
|
var shippings = await _signalRClient.GetNotMeasuredShippings();
|
|
|
|
Assert.IsNotNull(shippings);
|
|
var ShippingMeasuredDateAddDay = 1000; //dfd
|
|
Assert.IsTrue(shippings.All(s => !s.IsAllMeasured || s.MeasuredDate != null || s.MeasuredDate < DateTime.Now.AddDays(ShippingMeasuredDateAddDay)));
|
|
}
|
|
|
|
//[TestMethod]
|
|
//[DataRow(1)]
|
|
public async Task<Shipping> GetShippingByIdTest(int shippingId)
|
|
{
|
|
var shipping = await _signalRClient.GetShippingById(shippingId);
|
|
|
|
Assert.IsNotNull(shipping);
|
|
Assert.IsNotNull(shipping.ShippingDocuments);
|
|
|
|
Assert.IsTrue(shipping.Id == shippingId);
|
|
Assert.IsTrue(shipping.ShippingDocuments.All(s => s.ShippingId == shippingId));
|
|
Assert.IsTrue(shipping.ShippingDocuments.All(sd => sd.ShippingItems != null && sd.ShippingItems.Any(si => si.ShippingDocumentId == sd.Id)));
|
|
|
|
return shipping;
|
|
}
|
|
|
|
[DataTestMethod]
|
|
[DataRow(1)]
|
|
public async Task UpdateShippingTest(int shippingId)
|
|
{
|
|
var shipping = await GetShippingByIdTest(shippingId);
|
|
var newLicencePlate = GetFixtureName(shipping.LicencePlate);
|
|
|
|
shipping.LicencePlate = newLicencePlate;
|
|
await _signalRClient.UpdateShipping(shipping);
|
|
|
|
shipping = await GetShippingByIdTest(shippingId);
|
|
|
|
Assert.IsTrue(shipping.Id == shippingId);
|
|
Assert.IsTrue(shipping.LicencePlate == newLicencePlate);
|
|
|
|
shipping.LicencePlate = GetOriginalName(shipping.LicencePlate);
|
|
await _signalRClient.UpdateShipping(shipping);
|
|
|
|
Assert.IsTrue(shipping.Id == shippingId);
|
|
}
|
|
|
|
#endregion Shipping
|
|
|
|
#region ShippingItem
|
|
|
|
[TestMethod]
|
|
public async Task GetShippingItemsTest()
|
|
{
|
|
var shippingItems = await _signalRClient.GetShippingItems();
|
|
|
|
Assert.IsNotNull(shippingItems);
|
|
Assert.IsTrue(shippingItems.Count != 0);
|
|
|
|
Assert.IsTrue(shippingItems.All(si => si.ProductDto?.Id == si.ProductId), "shippingItem.Product == null");
|
|
|
|
Assert.IsTrue(shippingItems.All(x => double.Round(x.ShippingItemPallets!.Where(sp => sp.IsMeasured).Sum(sp => sp.GrossWeight), 1) == x.MeasuredGrossWeight));
|
|
Assert.IsTrue(shippingItems.All(x => double.Round(x.ShippingItemPallets!.Where(sp => sp.IsMeasured).Sum(sp => sp.NetWeight), 1) == x.MeasuredNetWeight));
|
|
|
|
await ValidateProductValues(shippingItems.Where(si => si.ProductId.GetValueOrDefault(0) > 0).GroupBy(x => x.ProductId!.Value, si => si).ToDictionary(k => k.Key, v => v.ToList()));
|
|
|
|
var rnd = new Random();
|
|
foreach (var shippingItem in shippingItems)
|
|
{
|
|
await UpdateShippingItemAsync(shippingItem.Id, rnd.Next(-10, 10), rnd.NextDouble() + rnd.Next(-3, 3), rnd.NextDouble() + rnd.Next(-5, 5), rnd.NextDouble() + rnd.Next(-1, 1));
|
|
}
|
|
|
|
shippingItems = await _signalRClient.GetShippingItems();
|
|
Assert.IsNotNull(shippingItems);
|
|
|
|
await ValidateProductValues(shippingItems.Where(si => si.ProductId.GetValueOrDefault(0) > 0).GroupBy(x => x.ProductId!.Value, si => si).ToDictionary(k => k.Key, v => v.ToList()));
|
|
}
|
|
|
|
private async Task ValidateProductValues(Dictionary<int, List<ShippingItem>> shippingItemsByProductId)
|
|
{
|
|
foreach (var (key, shippingItems) in shippingItemsByProductId)
|
|
{
|
|
var productDto = await _signalRClient.GetProductDtoById(key);
|
|
|
|
Assert.IsNotNull(productDto);
|
|
Assert.IsTrue(shippingItems.Where(si => si.ProductId == productDto.Id).All(si => si.ProductDto!.StockQuantity == productDto.StockQuantity));
|
|
|
|
var shippingItemSumQnty = shippingItems.Where(x => x.IsMeasured && x.ProductId == productDto.Id).Sum(x => x.MeasuredQuantity);
|
|
Assert.IsTrue(shippingItemSumQnty == productDto.StockQuantity, $"{productDto}; shippingItemSum Quantity: {shippingItemSumQnty} == {productDto.StockQuantity}");
|
|
|
|
if (!productDto.IsMeasurable) continue;
|
|
|
|
//var shippingItemSumWeight = double.Round(shippingItems.Where(x => x.IsMeasured && x.ProductId == productDto.Id).Sum(x => x.MeasuredNetWeight), 1);
|
|
//Assert.IsTrue(shippingItemSumWeight == productDto!.NetWeight, $"{productDto}; shippingItemSum NetWeight: {shippingItemSumWeight} == {productDto.NetWeight}");
|
|
|
|
//shippingItemSumWeight = double.Round(shippingItems.Where(x => x.IsMeasured && x.ProductId == productDto.Id).Sum(x => x.MeasuredGrossWeight), 1);
|
|
}
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(1, true)]
|
|
[DataRow(2, true)]
|
|
[DataRow(3, false)]
|
|
[DataRow(4, false)]
|
|
public async Task GetShippingItemByIdTest(int shippingItemId, bool shippingDocumentFileExcepted)
|
|
{
|
|
var shippingItem = await GetShippingItemByIdAsync(shippingItemId);
|
|
|
|
if (shippingDocumentFileExcepted) Assert.IsTrue(shippingItem.ShippingDocument?.ShippingDocumentToFiles?.FirstOrDefault()?.ShippingDocumentFile?.Id == 1);
|
|
else
|
|
{
|
|
Assert.IsNotNull(shippingItem.ShippingDocument);
|
|
Assert.IsTrue(shippingItem.ShippingDocument.ShippingDocumentToFiles?.Count == 0);
|
|
}
|
|
}
|
|
|
|
[return: NotNull]
|
|
public async Task<ShippingItem> GetShippingItemByIdAsync(int shippingItemId)
|
|
{
|
|
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemId);
|
|
|
|
Assert.IsNotNull(shippingItem, $"shippingItemId: {shippingItemId}");
|
|
|
|
if (shippingItem.IsMeasurable) Assert.IsNotNull(shippingItem.Pallet, $"shippingItem.Pallet == null; shippingItem.PalletId: {shippingItem.PalletId}");
|
|
|
|
Assert.IsNotNull(shippingItem.ProductDto, $"shippingItem.Product == null; shippingItem.ProductId: {shippingItem.ProductId}");
|
|
Assert.IsTrue(shippingItem.Id == shippingItemId);
|
|
|
|
Assert.IsTrue(shippingItem.QuantityOnDocument > 0, "QuantityOnDocument == 0");
|
|
Assert.IsTrue(shippingItem.NetWeightOnDocument > 0, "NetWeightOnDocument == 0");
|
|
Assert.IsTrue(shippingItem.GrossWeightOnDocument > 0, "GrossWeightOnDocument == 0");
|
|
|
|
return shippingItem;
|
|
}
|
|
|
|
[DataTestMethod]
|
|
[DataRow(1, 1, 0, 1, 0)]
|
|
[DataRow(1, -1, -2.137563300001, -33.75238200001, 2.12545)]
|
|
[DataRow(1, 1, 2.137563300001, 390.75238200001, 2.12545)]
|
|
[DataRow(1, 1, 20.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(2, -1, -20.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(2, -1, 20.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(3, 1, 2.137563300001, 1.75238200001, 2.12545)]
|
|
[DataRow(3, 1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(4, 13, 2.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(5, 1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
[DataRow(5, -1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
public async Task UpdateShippingItemTest(int shippingItemId, int incQuantity, double incPalletWeight, double incGrossWeight, double incTare)
|
|
{
|
|
Assert.IsTrue(true);
|
|
return;
|
|
await UpdateShippingItemAsync(shippingItemId, incQuantity, incPalletWeight, incGrossWeight, incTare);
|
|
}
|
|
|
|
public async Task UpdateShippingItemAsync(int shippingItemId, int incQuantity, double incPalletWeight, double incGrossWeight, double incTare)
|
|
{
|
|
incPalletWeight = double.Round(incPalletWeight, 0);
|
|
Console.WriteLine($"params: {shippingItemId}; {incQuantity}; {incPalletWeight}; {incGrossWeight}; {incTare}");
|
|
|
|
var originalShippingItem = await GetShippingItemByIdAsync(shippingItemId);
|
|
Console.WriteLine($"{originalShippingItem}");
|
|
|
|
var productDto = await GetProductDtoByIdAsync(originalShippingItem.ProductId!.Value, originalShippingItem.IsMeasurable);
|
|
|
|
Assert.IsTrue(originalShippingItem.IsMeasurable == productDto.IsMeasurable);
|
|
Console.WriteLine($"{productDto}; NetWeight: {productDto.NetWeight}");
|
|
|
|
var shippingItemPallet = originalShippingItem.ShippingItemPallets!.FirstOrDefault();
|
|
|
|
if (shippingItemPallet == null)
|
|
{
|
|
shippingItemPallet = new ShippingItemPallet { ShippingItemId = originalShippingItem.Id, PalletWeight = originalShippingItem.Pallet?.Weight ?? 0 };
|
|
originalShippingItem.ShippingItemPallets!.Add(shippingItemPallet);
|
|
}
|
|
|
|
Assert.IsNotNull(shippingItemPallet);
|
|
|
|
var nullResultIsValid = originalShippingItem.IsMeasured && !originalShippingItem.IsValidMeasuringValues();
|
|
nullResultIsValid = nullResultIsValid || originalShippingItem.ShippingItemPallets!.Any(x => !x.IsValidMeasuringValues(productDto.IsMeasurable));
|
|
nullResultIsValid = nullResultIsValid || originalShippingItem.ShippingItemPallets!.Any(x => !x.IsValidSafeMeasuringValues());
|
|
|
|
var originalPalletNetWeight = shippingItemPallet.NetWeight;
|
|
|
|
shippingItemPallet.TrayQuantity += incQuantity;
|
|
shippingItemPallet.GrossWeight += incGrossWeight;
|
|
shippingItemPallet.PalletWeight += incPalletWeight;
|
|
shippingItemPallet.TareWeight += incTare;
|
|
|
|
var incNetWeight = productDto.IsMeasurable ? double.Round(shippingItemPallet.NetWeight - originalPalletNetWeight, 1) : 0;
|
|
|
|
//shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
|
|
var dbShippingItemPallet = await _signalRClient.UpdateShippingItemPallet(shippingItemPallet);
|
|
|
|
//A szerver oldal 0-ra állítja a shippingItemPallet weight-eket, ha nem mérhető! - J.
|
|
if (!productDto.IsMeasurable)
|
|
{
|
|
shippingItemPallet.GrossWeight = 0;
|
|
shippingItemPallet.PalletWeight = 0;
|
|
shippingItemPallet.TareWeight = 0;
|
|
}
|
|
|
|
if (nullResultIsValid || !shippingItemPallet.IsValidSafeMeasuringValues())
|
|
{
|
|
Assert.IsNull(dbShippingItemPallet);
|
|
return;
|
|
}
|
|
|
|
//if (dbShippingItemPallet == null) return;
|
|
|
|
Assert.IsNotNull(dbShippingItemPallet);
|
|
Assert.IsTrue(dbShippingItemPallet.TareWeight == shippingItemPallet.TareWeight);
|
|
Assert.IsTrue(dbShippingItemPallet.TrayQuantity == shippingItemPallet.TrayQuantity);
|
|
Assert.IsTrue(dbShippingItemPallet.GrossWeight == shippingItemPallet.GrossWeight);
|
|
Assert.IsTrue(dbShippingItemPallet.PalletWeight == shippingItemPallet.PalletWeight);
|
|
Assert.IsTrue(dbShippingItemPallet.ShippingItemId == shippingItemPallet.ShippingItemId);
|
|
Assert.IsTrue(dbShippingItemPallet.NetWeight == double.Round(originalPalletNetWeight + incNetWeight, 1));
|
|
|
|
var shippingItem = await _signalRClient.GetShippingItemById(dbShippingItemPallet.ShippingItemId);
|
|
|
|
Assert.IsNotNull(shippingItem);
|
|
Assert.IsNotNull(shippingItem.ProductDto);
|
|
Assert.IsNotNull(shippingItem.ShippingItemPallets);
|
|
|
|
Assert.IsTrue(shippingItem.IsMeasurable == productDto.IsMeasurable);
|
|
|
|
//var incNetWeight = productDto.IsMeasurable ? double.Round(dbShippingItemPallet.NetWeight - originalPalletNetWeight, 1) : 0;
|
|
incGrossWeight = productDto.IsMeasurable ? double.Round(incGrossWeight, 1) : 0;
|
|
|
|
var isMeasuredPalletsCount = shippingItem.ShippingItemPallets!.Count(x => x.IsMeasured);
|
|
|
|
Assert.IsTrue(shippingItem.MeasuredNetWeight == double.Round(originalShippingItem.MeasuredNetWeight + incNetWeight, 1));
|
|
Assert.IsTrue(shippingItem.IsMeasured == (shippingItem.ShippingItemPallets!.All(x => x.IsMeasured) && shippingItem.MeasuringCount == isMeasuredPalletsCount));
|
|
|
|
if (shippingItem.IsMeasured)
|
|
{
|
|
Assert.IsTrue(shippingItem.IsValidMeasuringValues());
|
|
Assert.IsTrue(shippingItem.MeasuringCount == isMeasuredPalletsCount);
|
|
Assert.IsTrue(shippingItem.ProductDto.StockQuantity == originalShippingItem.ProductDto!.StockQuantity + incQuantity);
|
|
Assert.IsTrue(shippingItem.ProductDto.IncomingQuantity == productDto.IncomingQuantity - incQuantity);
|
|
|
|
var dbProductDto = await GetProductDtoByIdAsync(originalShippingItem.ProductId!.Value, shippingItem.IsMeasurable);
|
|
|
|
Assert.IsTrue(dbProductDto.StockQuantity == productDto.StockQuantity + incQuantity);
|
|
Assert.IsTrue(dbProductDto.IncomingQuantity == productDto.IncomingQuantity - incQuantity);
|
|
Assert.IsTrue(dbProductDto.NetWeight == double.Round(productDto.NetWeight + (shippingItem.IsMeasurable ? incNetWeight : 0), 1));
|
|
}
|
|
else
|
|
{
|
|
incQuantity = 0;
|
|
incNetWeight = 0;
|
|
incGrossWeight = 0;
|
|
|
|
Assert.IsTrue(shippingItem.MeasuringCount > isMeasuredPalletsCount);
|
|
}
|
|
|
|
Assert.IsTrue(shippingItem.MeasuredQuantity == originalShippingItem.MeasuredQuantity + incQuantity);
|
|
|
|
Assert.IsTrue(shippingItem.ShippingItemPallets!.All(x => x.IsValidSafeMeasuringValues()));
|
|
Assert.IsTrue(shippingItem.ShippingItemPallets!.All(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)));
|
|
|
|
Assert.IsTrue(shippingItem.MeasuredNetWeight == double.Round(originalShippingItem.MeasuredNetWeight + (shippingItem.IsMeasurable ? incNetWeight : 0), 1));
|
|
Assert.IsTrue(shippingItem.MeasuredGrossWeight == double.Round(originalShippingItem.MeasuredGrossWeight + (shippingItem.IsMeasurable ? incGrossWeight : 0), 1));
|
|
}
|
|
|
|
#endregion ShippingItem
|
|
|
|
#region ShippingDocument
|
|
|
|
[TestMethod]
|
|
public async Task GetShippingDocumentsTest()
|
|
{
|
|
var shippingDocuments = await _signalRClient.GetShippingDocuments();
|
|
|
|
Assert.IsNotNull(shippingDocuments);
|
|
Assert.IsTrue(shippingDocuments.Count != 0);
|
|
Assert.IsTrue(shippingDocuments.Any(x => x.ShippingDocumentToFiles?.Count > 0));
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(2, true)]
|
|
[DataRow(3, false)]
|
|
[DataRow(4, false)]
|
|
public async Task GetShippingDocumentByIdTest(int shippingDocumentId, bool shippingDocumentFileExcepted)
|
|
{
|
|
var shippingDocument = await GetShippingDocumentByIdAsync(shippingDocumentId);
|
|
|
|
if (shippingDocumentFileExcepted) Assert.IsTrue(shippingDocument.ShippingDocumentToFiles?.FirstOrDefault()?.ShippingDocumentFile?.Id == 1);
|
|
else
|
|
{
|
|
Assert.IsTrue(shippingDocument.ShippingDocumentToFiles?.Count == 0);
|
|
}
|
|
}
|
|
|
|
[return: NotNull]
|
|
public async Task<ShippingDocument> GetShippingDocumentByIdAsync(int shippingDocumentId)
|
|
{
|
|
var shippingDocument = await _signalRClient.GetShippingDocumentById(shippingDocumentId);
|
|
|
|
Assert.IsNotNull(shippingDocument);
|
|
Assert.IsTrue(shippingDocument.Id == shippingDocumentId);
|
|
|
|
return shippingDocument;
|
|
}
|
|
|
|
[DataTestMethod]
|
|
[DataRow(2)]
|
|
public async Task UpdateShippingDocumentTest(int shippingDocumentId)
|
|
{
|
|
var shippingDocument = await GetShippingDocumentByIdAsync(shippingDocumentId);
|
|
var newCountry = GetFixtureName(shippingDocument.Country);
|
|
|
|
shippingDocument.Country = newCountry;
|
|
await _signalRClient.UpdateShippingDocument(shippingDocument);
|
|
|
|
shippingDocument = await GetShippingDocumentByIdAsync(shippingDocumentId);
|
|
|
|
Assert.IsTrue(shippingDocument.Country == newCountry);
|
|
Assert.IsTrue(shippingDocument.ShippingDocumentToFiles?.FirstOrDefault()?.ShippingDocumentFile?.Id == 1);
|
|
|
|
shippingDocument.Country = GetOriginalName(shippingDocument.Country);
|
|
await _signalRClient.UpdateShippingDocument(shippingDocument);
|
|
}
|
|
|
|
#endregion ShippingDocument
|
|
|
|
#region Customer
|
|
|
|
[TestMethod]
|
|
public async Task GetMeasuringUsersTest()
|
|
{
|
|
var users = await _signalRClient.GetMeasuringUsers();
|
|
|
|
Assert.IsNotNull(users);
|
|
Assert.IsTrue(users.Count != 0);
|
|
Assert.IsTrue(users.All(x => !x.Email.IsNullOrEmpty() && !x.Deleted));
|
|
}
|
|
|
|
//[TestMethod]
|
|
//[DataRow(CustomerIdAasdDsserverCom)]
|
|
//public async Task GetCustomerRolesByCustomerIdTest(int customerId)
|
|
//{
|
|
// var customerRoles = await _signalRClient.GetCustomerRolesByCustomerId(customerId);
|
|
|
|
// Assert.IsNotNull(customerRoles);
|
|
// Assert.IsTrue(customerRoles.Count > 0);
|
|
// Assert.IsTrue(customerRoles.Any(cr => cr.SystemName == "Measuring"));
|
|
//}
|
|
|
|
#endregion Customer
|
|
|
|
#region Product
|
|
|
|
[TestMethod]
|
|
public async Task GetProductDtosTest()
|
|
{
|
|
var productDtos = await _signalRClient.GetProductDtos();
|
|
|
|
Assert.IsNotNull(productDtos);
|
|
Assert.IsTrue(productDtos.Count != 0);
|
|
Assert.IsTrue(productDtos.All(x => !x.Name.IsNullOrEmpty() && !x.Deleted));
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow(1, true)]
|
|
[DataRow(5, true)]
|
|
//[DataRow(6, false)]
|
|
[DataRow(33, true)]
|
|
[DataRow(64, false)]
|
|
[DataRow(7, true)]
|
|
public async Task GetProductDtoByIdTest(int productId, bool isMeasurableExcepted)
|
|
{
|
|
await GetProductDtoByIdAsync(productId, isMeasurableExcepted);
|
|
}
|
|
|
|
public async Task<ProductDto> GetProductDtoByIdAsync(int productId, bool isMeasurableExcepted)
|
|
{
|
|
var productDto = await _signalRClient.GetProductDtoById(productId);
|
|
|
|
Assert.IsNotNull(productDto);
|
|
|
|
//if (productDto.Id == 6) return productDto;
|
|
|
|
if (isMeasurableExcepted) Assert.IsTrue(productDto.HasMeasuringValues(), $"{productDto} {productDto.IsMeasurable}, {productDto.NetWeight}");
|
|
else
|
|
{
|
|
Assert.IsTrue(productDto.Id > 0);
|
|
Assert.IsTrue(productDto.StockQuantity >= 0);
|
|
Assert.IsTrue(productDto.NetWeight == 0);
|
|
|
|
Assert.IsFalse(productDto.IsMeasurable);
|
|
}
|
|
|
|
return productDto;
|
|
}
|
|
|
|
#endregion Product
|
|
|
|
#region OrderItem
|
|
|
|
[DataTestMethod]
|
|
[DataRow(1)]
|
|
public async Task GetOrderDtoByIdTest(int orderId) => await GetOrderDtoByIdAsync(orderId);
|
|
|
|
[return: NotNull]
|
|
public async Task<OrderDto> GetOrderDtoByIdAsync(int orderId)
|
|
{
|
|
var orderDto = await _signalRClient.GetOrderDtoById(orderId);
|
|
|
|
ValidateOrderDto(orderId, orderDto);
|
|
|
|
return orderDto!;
|
|
}
|
|
|
|
private static bool ValidateOrderDto(int orderId, [NotNullWhen(true)] OrderDto? orderDto)
|
|
{
|
|
Assert.IsNotNull(orderDto, $"orderId: {orderId}");
|
|
Assert.IsNotNull(orderDto.Customer);
|
|
|
|
Assert.IsTrue(orderDto.Id == orderId);
|
|
Assert.IsTrue(orderDto.OrderItemDtos.Count > 0);
|
|
|
|
Assert.IsTrue(orderDto.OrderItemDtos.All(oi => oi.ProductDto != null));
|
|
|
|
return true;
|
|
}
|
|
|
|
//[DataTestMethod]
|
|
//[DataRow(1, -1, -2.137563300001, -333.75238200001, 2.12545)]
|
|
//[DataRow(1, 1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(1, 1, 20.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(2, -1, -20.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(2, -1, 20.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(3, 1, 2.137563300001, 1.75238200001, 2.12545)]
|
|
//[DataRow(3, 1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(4, 13, 2.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(5, 1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
//[DataRow(5, -1, 2.137563300001, 3.75238200001, 2.12545)]
|
|
//public async Task UpdateOrderItemTest(int shippingItemId, int incQuantity, double incPalletWeight, double incGrossWeight, double incTare)
|
|
//{
|
|
// Assert.IsTrue(true);
|
|
// return;
|
|
// await UpdateOrderItemAsync(shippingItemId, incQuantity, incPalletWeight, incGrossWeight, incTare);
|
|
//}
|
|
|
|
//public async Task UpdateOrderItemAsync(int shippingItemId, int incQuantity, double incPalletWeight, double incGrossWeight, double incTare)
|
|
//{
|
|
//var originalShippingItem = await GetShippingItemByIdAsync(shippingItemId);
|
|
// var productDto = await GetProductDtoByIdAsync(originalShippingItem.ProductId!.Value, originalShippingItem.IsMeasurable);
|
|
|
|
// Assert.IsTrue(originalShippingItem.IsMeasurable == productDto.IsMeasurable);
|
|
|
|
// var shippingItem = await GetShippingItemByIdAsync(shippingItemId);
|
|
|
|
// var shippingItemPallet = shippingItem.ShippingItemPallets!.FirstOrDefault();
|
|
|
|
// if (shippingItemPallet == null)
|
|
// {
|
|
// shippingItemPallet = new ShippingItemPallet { ShippingItemId = shippingItem.Id, PalletWeight = shippingItem.Pallet?.Weight ?? 0 };
|
|
// shippingItem.ShippingItemPallets!.Add(shippingItemPallet);
|
|
// }
|
|
|
|
// Assert.IsNotNull(shippingItemPallet);
|
|
|
|
// var nullResultIsValid = shippingItem.IsMeasured && !shippingItem.IsValidMeasuringValues();
|
|
// nullResultIsValid = nullResultIsValid || shippingItem.ShippingItemPallets!.Any(x => !x.IsValidMeasuringValues(productDto.IsMeasurable));
|
|
// nullResultIsValid = nullResultIsValid || shippingItem.ShippingItemPallets!.Any(x => !x.IsValidSafeMeasuringValues());
|
|
|
|
// shippingItemPallet.TrayQuantity += incQuantity;
|
|
// shippingItemPallet.GrossWeight += incGrossWeight;
|
|
// shippingItemPallet.PalletWeight += incPalletWeight;
|
|
// shippingItemPallet.TareWeight += incTare;
|
|
|
|
// //shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
|
|
// var dbShippingItemPallet = await _signalRClient.UpdateShippingItemPallet(shippingItemPallet);
|
|
|
|
// //A szerver oldal 0-ra állítja a shippingItemPallet weight-eket, ha nem mérhető! - J.
|
|
// if (!productDto.IsMeasurable)
|
|
// {
|
|
// shippingItemPallet.GrossWeight = 0;
|
|
// shippingItemPallet.PalletWeight = 0;
|
|
// shippingItemPallet.TareWeight = 0;
|
|
// }
|
|
|
|
// if (nullResultIsValid || !shippingItemPallet.IsValidSafeMeasuringValues())
|
|
// {
|
|
// Assert.IsNull(dbShippingItemPallet);
|
|
// return;
|
|
// }
|
|
|
|
// Assert.IsNotNull(dbShippingItemPallet);
|
|
// Assert.IsTrue(dbShippingItemPallet.TareWeight == shippingItemPallet.TareWeight);
|
|
// Assert.IsTrue(dbShippingItemPallet.TrayQuantity == shippingItemPallet.TrayQuantity);
|
|
// Assert.IsTrue(dbShippingItemPallet.GrossWeight == shippingItemPallet.GrossWeight);
|
|
// Assert.IsTrue(dbShippingItemPallet.PalletWeight == shippingItemPallet.PalletWeight);
|
|
// Assert.IsTrue(dbShippingItemPallet.ShippingItemId == shippingItemPallet.ShippingItemId);
|
|
|
|
// shippingItem = await _signalRClient.GetShippingItemById(dbShippingItemPallet.ShippingItemId);
|
|
|
|
// Assert.IsNotNull(shippingItem);
|
|
// Assert.IsNotNull(shippingItem.ProductDto);
|
|
// Assert.IsNotNull(shippingItem.ShippingItemPallets);
|
|
// Assert.IsTrue(shippingItem.IsMeasurable == productDto.IsMeasurable);
|
|
|
|
// incGrossWeight = productDto.IsMeasurable ? double.Round(incGrossWeight, 1) : 0;
|
|
// var incNetWeight = productDto.IsMeasurable ? double.Round((incGrossWeight - incPalletWeight) - (incQuantity * incTare), 1) : 0;
|
|
|
|
// var isMeasuredPalletsCount = shippingItem.ShippingItemPallets!.Count(x => x.IsMeasured);
|
|
|
|
// Assert.IsTrue(shippingItem.IsMeasured == (shippingItem.ShippingItemPallets!.All(x => x.IsMeasured) && shippingItem.MeasuringCount == isMeasuredPalletsCount));
|
|
|
|
// if (shippingItem.IsMeasured)
|
|
// {
|
|
// Assert.IsTrue(shippingItem.IsValidMeasuringValues());
|
|
// Assert.IsTrue(shippingItem.MeasuringCount == isMeasuredPalletsCount);
|
|
// Assert.IsTrue(shippingItem.ProductDto.StockQuantity == originalShippingItem.ProductDto!.StockQuantity + incQuantity);
|
|
// Assert.IsTrue(shippingItem.ProductDto.IncomingQuantity == productDto.IncomingQuantity - incQuantity);
|
|
|
|
// var dbProductDto = await GetProductDtoByIdAsync(originalShippingItem.ProductId!.Value, shippingItem.IsMeasurable);
|
|
|
|
// Assert.IsTrue(dbProductDto.StockQuantity == productDto.StockQuantity + incQuantity);
|
|
// Assert.IsTrue(dbProductDto.IncomingQuantity == productDto.IncomingQuantity - incQuantity);
|
|
// Assert.IsTrue(dbProductDto.NetWeight == double.Round(productDto.NetWeight + (shippingItem.IsMeasurable ? incNetWeight : 0), 1));
|
|
|
|
// }
|
|
// else
|
|
// {
|
|
// incQuantity = 0;
|
|
// incNetWeight = 0;
|
|
// incGrossWeight = 0;
|
|
|
|
// Assert.IsTrue(shippingItem.MeasuringCount > isMeasuredPalletsCount);
|
|
// }
|
|
|
|
// Assert.IsTrue(shippingItem.MeasuredQuantity == originalShippingItem.MeasuredQuantity + incQuantity);
|
|
|
|
// Assert.IsTrue(shippingItem.ShippingItemPallets!.All(x => x.IsValidSafeMeasuringValues()));
|
|
// Assert.IsTrue(shippingItem.ShippingItemPallets!.All(x => x.IsValidMeasuringValues(shippingItem.IsMeasurable)));
|
|
|
|
// Assert.IsTrue(shippingItem.MeasuredNetWeight == double.Round(originalShippingItem.MeasuredNetWeight + (shippingItem.IsMeasurable ? incNetWeight : 0), 1));
|
|
// Assert.IsTrue(shippingItem.MeasuredGrossWeight == double.Round(originalShippingItem.MeasuredGrossWeight + (shippingItem.IsMeasurable ? incGrossWeight : 0), 1));
|
|
//}
|
|
#endregion OrderItem
|
|
|
|
#region Login
|
|
[TestMethod]
|
|
[DataRow("aasd@dsserver.com", "Asdasd123456")]
|
|
public async Task LoginMeasuringUserTest_TrueIfHasCustomerDto(string email, string password)
|
|
{
|
|
var loginModelResponse = await _signalRClient.LoginMeasuringUser(email, password);
|
|
|
|
Assert.IsNotNull(loginModelResponse);
|
|
Assert.IsNotNull(loginModelResponse.CustomerDto, loginModelResponse.ErrorMessage);
|
|
|
|
Assert.IsTrue(loginModelResponse.CustomerDto.Email == email, loginModelResponse.ErrorMessage);
|
|
}
|
|
|
|
[TestMethod]
|
|
[DataRow("adam.g@aycode.com", "123")]
|
|
public async Task LoginMeasuringUserTest_TrueIfHasNotCustomerDto(string email, string password)
|
|
{
|
|
var loginModelResponse = await _signalRClient.LoginMeasuringUser(email, password);
|
|
|
|
Assert.IsNotNull(loginModelResponse);
|
|
Assert.IsNull(loginModelResponse.CustomerDto);
|
|
|
|
Assert.IsFalse(loginModelResponse.ErrorMessage.IsNullOrWhiteSpace());
|
|
Console.WriteLine($"Succes: {loginModelResponse.ErrorMessage}");
|
|
}
|
|
#endregion Login
|
|
}
|
|
}
|