Add new tests, improvments

This commit is contained in:
Loretta 2025-09-14 07:57:10 +02:00
parent 1c666c7ac7
commit f55f12dfd0
1 changed files with 75 additions and 15 deletions

View File

@ -10,8 +10,13 @@ namespace FruitBankHybrid.Shared.Tests
[TestClass] [TestClass]
public sealed class FruitBankClientTests public sealed class FruitBankClientTests
{ {
private const string Fixture = "_test.temp";
private FruitBankSignalRClient _signalRClient = null!; 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] [TestInitialize]
public void TestInit() public void TestInit()
{ {
@ -30,7 +35,7 @@ namespace FruitBankHybrid.Shared.Tests
var partners = await _signalRClient.GetPartners(); var partners = await _signalRClient.GetPartners();
Assert.IsNotNull(partners); Assert.IsNotNull(partners);
Assert.IsTrue(partners.Any()); Assert.IsTrue(partners.Count != 0);
} }
//[DataTestMethod] //[DataTestMethod]
@ -51,8 +56,7 @@ namespace FruitBankHybrid.Shared.Tests
{ {
var partner = await GetPartnerByIdTest(partnerId); var partner = await GetPartnerByIdTest(partnerId);
const string fixture = "_test.temp"; var newName = GetFixtureName(partner.Name);
var newName = $"{partner.Name.Replace(fixture, string.Empty)}{fixture}";
partner.Name = newName; partner.Name = newName;
await _signalRClient.UpdatePartner(partner); await _signalRClient.UpdatePartner(partner);
@ -60,10 +64,9 @@ namespace FruitBankHybrid.Shared.Tests
partner = await GetPartnerByIdTest(partnerId); partner = await GetPartnerByIdTest(partnerId);
Assert.IsTrue(partner.Name == newName); Assert.IsTrue(partner.Name == newName);
partner.Name = partner.Name.Replace(fixture, string.Empty); partner.Name = GetOriginalName(partner.Name);
await _signalRClient.UpdatePartner(partner); await _signalRClient.UpdatePartner(partner);
} }
#endregion Partner #endregion Partner
#region Shipping #region Shipping
@ -86,9 +89,9 @@ namespace FruitBankHybrid.Shared.Tests
Assert.IsTrue(shippings.All(s => !s.IsAllMeasured)); Assert.IsTrue(shippings.All(s => !s.IsAllMeasured));
} }
[TestMethod] //[TestMethod]
[DataRow(1)] //[DataRow(1)]
public async Task GetShippingByIdTest(int shippingId) public async Task<Shipping> GetShippingByIdTest(int shippingId)
{ {
var shipping = await _signalRClient.GetShippingById(shippingId); var shipping = await _signalRClient.GetShippingById(shippingId);
@ -98,6 +101,25 @@ namespace FruitBankHybrid.Shared.Tests
Assert.IsTrue(shipping.Id == shippingId); Assert.IsTrue(shipping.Id == shippingId);
Assert.IsTrue(shipping.ShippingDocuments.All(s => s.ShippingId == 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))); 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 #endregion Shipping
@ -113,14 +135,33 @@ namespace FruitBankHybrid.Shared.Tests
Assert.IsTrue(shippingItems.Any()); Assert.IsTrue(shippingItems.Any());
} }
[TestMethod] //[TestMethod]
[DataRow(1)] //[DataRow(1)]
public async Task GetShippingItemByIdTest(int shippingItemeId) public async Task<ShippingItem> GetShippingItemByIdTest(int shippingItemeId)
{ {
var shippingItem = await _signalRClient.GetShippingItemById(shippingItemeId); var shippingItem = await _signalRClient.GetShippingItemById(shippingItemeId);
Assert.IsNotNull(shippingItem); Assert.IsNotNull(shippingItem);
Assert.IsTrue(shippingItem.Id == shippingItemeId); Assert.IsTrue(shippingItem.Id == shippingItemeId);
return shippingItem;
}
[DataTestMethod]
[DataRow(1)]
public async Task UpdateShippingItemTest(int shippingItemId)
{
var shippingItem = await GetShippingItemByIdTest(shippingItemId);
var newName = GetFixtureName(shippingItem.Name);
shippingItem.Name = newName;
await _signalRClient.UpdateShippingItem(shippingItem);
shippingItem = await GetShippingItemByIdTest(shippingItemId);
Assert.IsTrue(shippingItem.Name == newName);
shippingItem.Name = GetOriginalName(shippingItem.Name);
await _signalRClient.UpdateShippingItem(shippingItem);
} }
#endregion ShippingItem #endregion ShippingItem
@ -133,17 +174,36 @@ namespace FruitBankHybrid.Shared.Tests
var shippingDocuments = await _signalRClient.GetShippingDocuments(); var shippingDocuments = await _signalRClient.GetShippingDocuments();
Assert.IsNotNull(shippingDocuments); Assert.IsNotNull(shippingDocuments);
Assert.IsTrue(shippingDocuments.Any()); Assert.IsTrue(shippingDocuments.Count != 0);
} }
[TestMethod] //[TestMethod]
[DataRow(2)] //[DataRow(2)]
public async Task GetShippingDocumentByIdTest(int shippingDocumentId) public async Task<ShippingDocument> GetShippingDocumentByIdTest(int shippingDocumentId)
{ {
var shippingDocument = await _signalRClient.GetShippingDocumentById(shippingDocumentId); var shippingDocument = await _signalRClient.GetShippingDocumentById(shippingDocumentId);
Assert.IsNotNull(shippingDocument); Assert.IsNotNull(shippingDocument);
Assert.IsTrue(shippingDocument.Id == shippingDocumentId); 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 #endregion ShippingDocument