Лабораторная работа 2. Исправлена логика изменения количества компонента на складе, Добавлен тест на успешное добавление компонента в товар, если его хватает на складе
This commit is contained in:
parent
44691c91e7
commit
fea322f601
@ -110,7 +110,7 @@ internal class ProductBusinessLogicContract(
|
|||||||
if (component == null)
|
if (component == null)
|
||||||
throw new ArgumentNullException($"Component {componentOnStorage.ComponentId} not found");
|
throw new ArgumentNullException($"Component {componentOnStorage.ComponentId} not found");
|
||||||
|
|
||||||
if (componentOnStorage.Count == 0)
|
if (componentOnStorage.Count <= 0)
|
||||||
throw new OutOfStockException(component.ComponentName);
|
throw new OutOfStockException(component.ComponentName);
|
||||||
|
|
||||||
ComponentInProductDataModel componentInProduct = new ComponentInProductDataModel(component.Id, productId);
|
ComponentInProductDataModel componentInProduct = new ComponentInProductDataModel(component.Id, productId);
|
||||||
|
@ -73,6 +73,23 @@ namespace NorthBridgeBusinessLogic.Implementations
|
|||||||
_storageContract.UpdateComponentCount(storageId, componentId, newCount);
|
_storageContract.UpdateComponentCount(storageId, componentId, newCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int GetComponentCountFromStorage(string componentId, string storageId)
|
||||||
|
{
|
||||||
|
var storage = _storageContract.GetStorageById(storageId);
|
||||||
|
var component = _storageContract.GetComponentOnStorage(storageId, componentId);
|
||||||
|
|
||||||
|
if (storage == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Storage not found");
|
||||||
|
}
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Component not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return component.Count;
|
||||||
|
}
|
||||||
|
|
||||||
public List<ComponentOnStorageDataModel> GetComponentsFromStorage(string storageId)
|
public List<ComponentOnStorageDataModel> GetComponentsFromStorage(string storageId)
|
||||||
{
|
{
|
||||||
var storage = _storageContract.GetStorageById(storageId);
|
var storage = _storageContract.GetStorageById(storageId);
|
||||||
|
@ -17,6 +17,8 @@ namespace NorthBridgeContract.BusinessLogicsContracts
|
|||||||
|
|
||||||
void UpdateComponentCount(string storageId, string componentId, int newCount);
|
void UpdateComponentCount(string storageId, string componentId, int newCount);
|
||||||
|
|
||||||
|
int GetComponentCountFromStorage(string componentId, string storageId);
|
||||||
|
|
||||||
List<ComponentOnStorageDataModel> GetComponentsFromStorage(string storageId);
|
List<ComponentOnStorageDataModel> GetComponentsFromStorage(string storageId);
|
||||||
|
|
||||||
StorageDataModel GetStorageById(string storageId);
|
StorageDataModel GetStorageById(string storageId);
|
||||||
|
@ -21,6 +21,8 @@ namespace NorthBridgeContract.StoragesContracts
|
|||||||
|
|
||||||
void UpdateComponentCount(string storageId, string componentId, int newCount);
|
void UpdateComponentCount(string storageId, string componentId, int newCount);
|
||||||
|
|
||||||
|
ComponentOnStorageDataModel GetComponentOnStorage(string storageId, string componentId);
|
||||||
|
|
||||||
List<ComponentOnStorageDataModel> GetComponentsOnStorage(string storageId);
|
List<ComponentOnStorageDataModel> GetComponentsOnStorage(string storageId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +199,39 @@ namespace NorthBridgeTest.BusinessLogicsContractsTests
|
|||||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf<ArgumentNullException>());
|
Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf<ArgumentNullException>());
|
||||||
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
_productStorageContract.Verify(x => x.DelElement(It.IsAny<string>()), Times.Never);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AddComponentToProduct_SuccessfullyAddsComponent()
|
||||||
|
{
|
||||||
|
// Arrange
|
||||||
|
string productId = Guid.NewGuid().ToString();
|
||||||
|
string componentId = Guid.NewGuid().ToString();
|
||||||
|
string storageId = Guid.NewGuid().ToString();
|
||||||
|
var count = 5;
|
||||||
|
|
||||||
|
var componentOnStorage = new ComponentOnStorageDataModel(storageId, componentId, count);
|
||||||
|
|
||||||
|
var component = new ComponentDataModel(
|
||||||
|
componentId,
|
||||||
|
"RAM",
|
||||||
|
ComponentType.RAM,
|
||||||
|
Guid.NewGuid().ToString(),
|
||||||
|
100.50,
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
_componentStorageContract
|
||||||
|
.Setup(cs => cs.GetElementById(componentId))
|
||||||
|
.Returns(component);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
_productBusinessLogicContract.AddComponentToProduct(componentOnStorage, productId);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
_productStorageContract.Verify(ps => ps.AddComponentToProduct(
|
||||||
|
It.Is<ComponentInProductDataModel>(c => c.ComponentId == componentId && c.ProductId == productId)
|
||||||
|
), Times.Once);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user