From fea322f601db20e60f2d8b8e08ababf8acefe4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D1=81=D0=B5=D0=BD=D0=B8=D1=8F?= Date: Thu, 27 Feb 2025 21:37:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=202.=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B8?= =?UTF-8?q?=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82=D0=B2=D0=B0=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0=20=D0=BD=D0=B0?= =?UTF-8?q?=20=D1=81=D0=BA=D0=BB=D0=B0=D0=B4=D0=B5,=20=D0=94=D0=BE=D0=B1?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=83=D1=81=D0=BF=D0=B5=D1=88=D0=BD=D0=BE=D0=B5?= =?UTF-8?q?=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=BE=D0=BD=D0=B5=D0=BD=D1=82=D0=B0?= =?UTF-8?q?=20=D0=B2=20=D1=82=D0=BE=D0=B2=D0=B0=D1=80,=20=D0=B5=D1=81?= =?UTF-8?q?=D0=BB=D0=B8=20=D0=B5=D0=B3=D0=BE=20=D1=85=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B0=D0=B5=D1=82=20=D0=BD=D0=B0=20=D1=81=D0=BA=D0=BB=D0=B0?= =?UTF-8?q?=D0=B4=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductBusinessLogicContract.cs | 2 +- .../StorageBusinessLogicContract .cs | 17 ++++++++++ .../IStorageBusinessLogicContract.cs | 2 ++ .../IStorageStorageContract.cs | 2 ++ .../ProductBusinessLogicTests.cs | 33 +++++++++++++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/NorthBridge/NorthBridgeBusinessLogic/Implementations/ProductBusinessLogicContract.cs b/NorthBridge/NorthBridgeBusinessLogic/Implementations/ProductBusinessLogicContract.cs index 28f348f..12ebe21 100644 --- a/NorthBridge/NorthBridgeBusinessLogic/Implementations/ProductBusinessLogicContract.cs +++ b/NorthBridge/NorthBridgeBusinessLogic/Implementations/ProductBusinessLogicContract.cs @@ -110,7 +110,7 @@ internal class ProductBusinessLogicContract( if (component == null) throw new ArgumentNullException($"Component {componentOnStorage.ComponentId} not found"); - if (componentOnStorage.Count == 0) + if (componentOnStorage.Count <= 0) throw new OutOfStockException(component.ComponentName); ComponentInProductDataModel componentInProduct = new ComponentInProductDataModel(component.Id, productId); diff --git a/NorthBridge/NorthBridgeBusinessLogic/Implementations/StorageBusinessLogicContract .cs b/NorthBridge/NorthBridgeBusinessLogic/Implementations/StorageBusinessLogicContract .cs index f20d0ec..2435f5d 100644 --- a/NorthBridge/NorthBridgeBusinessLogic/Implementations/StorageBusinessLogicContract .cs +++ b/NorthBridge/NorthBridgeBusinessLogic/Implementations/StorageBusinessLogicContract .cs @@ -73,6 +73,23 @@ namespace NorthBridgeBusinessLogic.Implementations _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 GetComponentsFromStorage(string storageId) { var storage = _storageContract.GetStorageById(storageId); diff --git a/NorthBridge/NorthBridgeContract/BusinessLogicsContracts/IStorageBusinessLogicContract.cs b/NorthBridge/NorthBridgeContract/BusinessLogicsContracts/IStorageBusinessLogicContract.cs index 403e4d1..da784cf 100644 --- a/NorthBridge/NorthBridgeContract/BusinessLogicsContracts/IStorageBusinessLogicContract.cs +++ b/NorthBridge/NorthBridgeContract/BusinessLogicsContracts/IStorageBusinessLogicContract.cs @@ -17,6 +17,8 @@ namespace NorthBridgeContract.BusinessLogicsContracts void UpdateComponentCount(string storageId, string componentId, int newCount); + int GetComponentCountFromStorage(string componentId, string storageId); + List GetComponentsFromStorage(string storageId); StorageDataModel GetStorageById(string storageId); diff --git a/NorthBridge/NorthBridgeContract/StoragesContracts/IStorageStorageContract.cs b/NorthBridge/NorthBridgeContract/StoragesContracts/IStorageStorageContract.cs index 4a14f82..9b2f864 100644 --- a/NorthBridge/NorthBridgeContract/StoragesContracts/IStorageStorageContract.cs +++ b/NorthBridge/NorthBridgeContract/StoragesContracts/IStorageStorageContract.cs @@ -21,6 +21,8 @@ namespace NorthBridgeContract.StoragesContracts void UpdateComponentCount(string storageId, string componentId, int newCount); + ComponentOnStorageDataModel GetComponentOnStorage(string storageId, string componentId); + List GetComponentsOnStorage(string storageId); } diff --git a/NorthBridge/NorthBridgeTest/BusinessLogicsContractsTests/ProductBusinessLogicTests.cs b/NorthBridge/NorthBridgeTest/BusinessLogicsContractsTests/ProductBusinessLogicTests.cs index 6d4148a..4c967b3 100644 --- a/NorthBridge/NorthBridgeTest/BusinessLogicsContractsTests/ProductBusinessLogicTests.cs +++ b/NorthBridge/NorthBridgeTest/BusinessLogicsContractsTests/ProductBusinessLogicTests.cs @@ -199,6 +199,39 @@ namespace NorthBridgeTest.BusinessLogicsContractsTests Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf()); _productStorageContract.Verify(x => x.DelElement(It.IsAny()), 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(c => c.ComponentId == componentId && c.ProductId == productId) + ), Times.Once); + } }