test fix
This commit is contained in:
@@ -120,7 +120,63 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
[Test]
|
||||
public void Try_DelElement_WhenRecordDoesNotExist_ThrowsElementNotFoundException()
|
||||
{
|
||||
Assert.That(() => _storageStorageContract.DelElement(Guid.NewGuid().ToString()), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _storageStorageContract.DelElement(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenEnoughInOneStorage_ReturnsTrue()
|
||||
{
|
||||
var storage =
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 10, [(_product.Id, 10)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.True);
|
||||
var updated = GetStorageFromDatabaseById(storage.Id);
|
||||
Assert.That(updated!.Count, Is.EqualTo(5));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenExactlyEnough_RemovesStorage_ReturnsTrue()
|
||||
{
|
||||
var storage =
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 5, [(_product.Id, 5)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.True);
|
||||
var deleted = GetStorageFromDatabaseById(storage.Id);
|
||||
Assert.That(deleted, Is.Null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenNotEnoughInStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), _product.ProductType, 2, [(_product.Id, 2)]);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 5)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Try_CheckComponents_WhenNoMatchingStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Chocolate, 10); // другой тип
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 1)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
[Test]
|
||||
public void Try_CheckComponents_InCorrectProductTypeStorage_ReturnsFalse()
|
||||
{
|
||||
InsertStorageToDatabaseAndReturn(Guid.NewGuid().ToString(), ProductType.Cake, 10);
|
||||
var sale = new SaleDataModel(Guid.NewGuid().ToString(), "emp", null, 0, DiscountType.None, 0, false,
|
||||
[new SaleProductDataModel(Guid.NewGuid().ToString(), _product.Id, 1)]);
|
||||
var result = _storageStorageContract.CheckComponents(sale);
|
||||
Assert.That(result, Is.False);
|
||||
}
|
||||
|
||||
private Product InsertProductToDatabaseAndReturn(string id, string name, ProductType type)
|
||||
@@ -131,16 +187,19 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
return product;
|
||||
}
|
||||
|
||||
private Storage InsertStorageToDatabaseAndReturn(string id, ProductType type, int count, List<(string, int)>? products = null)
|
||||
private Storage InsertStorageToDatabaseAndReturn(string id, ProductType type, int count,
|
||||
List<(string, int)>? products = null)
|
||||
{
|
||||
var storage = new Storage { Id = id, Type = type, Count = count, Products = [] };
|
||||
if (products is not null)
|
||||
{
|
||||
foreach (var elem in products)
|
||||
{
|
||||
storage.Products.Add(new ProductStorage { StorageId = storage.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
storage.Products.Add(new ProductStorage
|
||||
{ StorageId = storage.Id, ProductId = elem.Item1, Count = elem.Item2 });
|
||||
}
|
||||
}
|
||||
|
||||
CandyHouseDbContext.Agencies.Add(storage);
|
||||
CandyHouseDbContext.SaveChanges();
|
||||
return storage;
|
||||
@@ -212,4 +271,4 @@ internal class StorageStorageContractTests : BaseStorageContractTest
|
||||
{
|
||||
return CandyHouseDbContext.Agencies.FirstOrDefault(x => x.Id == id);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user