313 lines
11 KiB
C#
313 lines
11 KiB
C#
using AyCode.Core.Enums;
|
|
using AyCode.Core.Loggers;
|
|
using AyCode.Utils.Extensions;
|
|
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 FruitBank.Common;
|
|
|
|
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()
|
|
{
|
|
_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;
|
|
await _signalRClient.UpdatePartner(partner);
|
|
|
|
partner = await GetPartnerByIdTest(partnerId);
|
|
Assert.IsTrue(partner.Name == newName);
|
|
|
|
partner.Name = GetOriginalName(partner.Name);
|
|
await _signalRClient.UpdatePartner(partner);
|
|
}
|
|
#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.LicencePlate == newLicencePlate);
|
|
|
|
shipping.LicencePlate = GetOriginalName(shipping.LicencePlate);
|
|
await _signalRClient.UpdateShipping(shipping);
|
|
}
|
|
|
|
#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.Product?.Id == si.ProductId), "shippingItem.Product == null");
|
|
}
|
|
|
|
//[TestMethod]
|
|
//[DataRow(1)]
|
|
[return: NotNull]
|
|
public async Task<ShippingItem> GetShippingItemByIdTest(int shippingItemId)
|
|
{
|
|
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemId);
|
|
|
|
Assert.IsNotNull(shippingItem);
|
|
Assert.IsNotNull(shippingItem.Product, $"shippingItem.Product == null; shippingItem.Id: {shippingItem.ProductId}");
|
|
Assert.IsTrue(shippingItem.Id == shippingItemId);
|
|
|
|
Assert.IsTrue(shippingItem.Quantity > 0, "Quantity == 0");
|
|
Assert.IsTrue(shippingItem.NetWeight > 0, "NetWeight == 0");
|
|
Assert.IsTrue(shippingItem.GrossWeight > 0, "GrossWeight == 0");
|
|
|
|
return shippingItem;
|
|
}
|
|
|
|
[DataTestMethod]
|
|
[DataRow(1)]
|
|
[DataRow(2)]
|
|
//[DataRow(3)]
|
|
//[DataRow(4)]
|
|
public async Task UpdateShippingItemTest(int shippingItemId)
|
|
{
|
|
var originalShippingItem = await GetShippingItemByIdTest(shippingItemId);
|
|
var newName = GetFixtureName(originalShippingItem.Name);
|
|
|
|
var shippingItem = await GetShippingItemByIdTest(shippingItemId);
|
|
shippingItem.Name = newName;
|
|
//shippingItem.MeasuredGrossWeight = 5;
|
|
shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
|
|
|
|
Assert.IsNotNull(shippingItem);
|
|
Assert.IsNotNull(shippingItem.Product);
|
|
Assert.IsTrue(shippingItem.Name == newName);
|
|
Assert.IsTrue(shippingItem.Product.StockQuantity == originalShippingItem.Product!.StockQuantity);
|
|
|
|
shippingItem = await GetShippingItemByIdTest(shippingItemId);
|
|
|
|
Assert.IsTrue(shippingItem.Name == newName);
|
|
Assert.IsTrue(shippingItem.Product!.StockQuantity == originalShippingItem.Product.StockQuantity);
|
|
//Assert.IsTrue(shippingItem.MeasuredGrossWeight is 5);
|
|
|
|
shippingItem.Name = GetOriginalName(shippingItem.Name);
|
|
shippingItem = await _signalRClient.UpdateShippingItem(shippingItem);
|
|
|
|
Assert.IsNotNull(shippingItem);
|
|
Assert.IsNotNull(shippingItem.Product);
|
|
|
|
shippingItem = await GetShippingItemByIdTest(shippingItemId);
|
|
|
|
Assert.IsTrue(shippingItem.Name == originalShippingItem.Name);
|
|
Assert.IsTrue(shippingItem.Product!.StockQuantity == originalShippingItem.Product.StockQuantity);
|
|
}
|
|
|
|
#endregion ShippingItem
|
|
|
|
#region ShippingDocument
|
|
|
|
[TestMethod]
|
|
public async Task GetShippingDocumentsTest()
|
|
{
|
|
var shippingDocuments = await _signalRClient.GetShippingDocuments();
|
|
|
|
Assert.IsNotNull(shippingDocuments);
|
|
Assert.IsTrue(shippingDocuments.Count != 0);
|
|
}
|
|
|
|
//[TestMethod]
|
|
//[DataRow(2)]
|
|
public async Task<ShippingDocument> GetShippingDocumentByIdTest(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 GetShippingDocumentByIdTest(shippingDocumentId);
|
|
var newCountry = GetFixtureName(shippingDocument.Country);
|
|
|
|
shippingDocument.Country = newCountry;
|
|
await _signalRClient.UpdateShippingDocument(shippingDocument);
|
|
|
|
shippingDocument = await GetShippingDocumentByIdTest(shippingDocumentId);
|
|
Assert.IsTrue(shippingDocument.Country == newCountry);
|
|
|
|
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 productDto = await _signalRClient.GetProductDtos();
|
|
|
|
Assert.IsNotNull(productDto);
|
|
Assert.IsTrue(productDto.Count != 0);
|
|
Assert.IsTrue(productDto.All(x => !x.Name.IsNullOrEmpty() && !x.Deleted));
|
|
}
|
|
|
|
#endregion Product
|
|
|
|
#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
|
|
}
|
|
}
|