2025-02-26 23:49:16 +04:00
|
|
|
using Moq;
|
|
|
|
using NUnit.Framework;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2025-02-27 02:25:39 +04:00
|
|
|
using System.Linq;
|
2025-02-26 23:49:16 +04:00
|
|
|
using CandyHouseBase.DataModels;
|
|
|
|
using CandyHouseBase.Exceptions;
|
2025-02-27 02:25:39 +04:00
|
|
|
using CandyHouseBase.Extensions;
|
|
|
|
using CandyHouseBase.Implementations;
|
|
|
|
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
2025-02-26 23:49:16 +04:00
|
|
|
using CandyHouseBase.Interfaces.StoragesContracts;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
namespace CandyHouseTests.BusinessLogicsContractsTests
|
|
|
|
{
|
|
|
|
[TestFixture]
|
|
|
|
internal class IngredientBusinessLogicContractTests
|
|
|
|
{
|
|
|
|
private IngredientBusinessLogicContract _ingredientBusinessLogicContract;
|
|
|
|
private Mock<IIngredientStorageContact> _ingredientStorageContact;
|
|
|
|
|
|
|
|
[OneTimeSetUp]
|
|
|
|
public void OneTimeSetUp()
|
|
|
|
{
|
|
|
|
_ingredientStorageContact = new Mock<IIngredientStorageContact>();
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientBusinessLogicContract = new IngredientBusinessLogicContract(
|
|
|
|
_ingredientStorageContact.Object,
|
|
|
|
new Mock<ILogger>().Object
|
|
|
|
);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[SetUp]
|
|
|
|
public void SetUp()
|
|
|
|
{
|
|
|
|
_ingredientStorageContact.Reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAllIngredients_ReturnsListOfRecords_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var ingredients = new List<IngredientDataModel>
|
|
|
|
{
|
2025-02-27 02:25:39 +04:00
|
|
|
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100),
|
|
|
|
new IngredientDataModel(Guid.NewGuid().ToString(), "Flour", "kg", 200),
|
|
|
|
new IngredientDataModel(Guid.NewGuid().ToString(), "Cocoa", "kg", 50)
|
2025-02-26 23:49:16 +04:00
|
|
|
};
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetList()).Returns(ingredients);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var list = _ingredientBusinessLogicContract.GetAllIngredients();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.That(list, Is.Not.Null);
|
|
|
|
Assert.That(list, Is.EquivalentTo(ingredients));
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(list.All(i => Guid.TryParse(i.Id, out _) && !i.Name.IsEmpty() && !i.Unit.IsEmpty() && i.Cost >= 0), Is.True);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAllIngredients_ReturnsEmptyList_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetList()).Returns(new List<IngredientDataModel>());
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var list = _ingredientBusinessLogicContract.GetAllIngredients();
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.That(list, Is.Not.Null);
|
|
|
|
Assert.That(list, Has.Count.EqualTo(0));
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAllIngredients_ReturnsNull_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetList()).Returns((List<IngredientDataModel>)null);
|
|
|
|
|
|
|
|
// Act & Assert
|
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetAllIngredients(), Throws.TypeOf<NullListException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void GetAllIngredients_StorageThrowError_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetAllIngredients(), Throws.TypeOf<StorageException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_ReturnsIngredientById_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var id = Guid.NewGuid().ToString();
|
|
|
|
var ingredient = new IngredientDataModel(id, "Sugar", "kg", 100);
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(ingredient);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var element = _ingredientBusinessLogicContract.GetIngredientByData(id);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.That(element, Is.Not.Null);
|
|
|
|
Assert.That(element.Id, Is.EqualTo(id));
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
|
|
|
Assert.That(!element.Name.IsEmpty());
|
|
|
|
Assert.That(!element.Unit.IsEmpty());
|
|
|
|
Assert.That(element.Cost >= 0);
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_ReturnsIngredientByName_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var name = "Sugar";
|
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), name, "kg", 100);
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementByName(name)).Returns(ingredient);
|
|
|
|
|
|
|
|
// Act
|
|
|
|
var element = _ingredientBusinessLogicContract.GetIngredientByData(name);
|
|
|
|
|
|
|
|
// Assert
|
|
|
|
Assert.That(element, Is.Not.Null);
|
|
|
|
Assert.That(element.Name, Is.EqualTo(name));
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
|
|
|
Assert.That(!element.Unit.IsEmpty());
|
|
|
|
Assert.That(element.Cost >= 0);
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_EmptyData_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(null), Throws.TypeOf<ArgumentNullException>());
|
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_NotFoundById_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var id = Guid.NewGuid().ToString(); // Valid Guid
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns((IngredientDataModel)null);
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(id), Throws.TypeOf<ElementNotFoundException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_NotFoundByName_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var name = "Nonexistent";
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementByName(name)).Returns((IngredientDataModel)null);
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(name), Throws.TypeOf<ElementNotFoundException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementByName(name), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void GetIngredientByData_StorageThrowError_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData("Sugar"), Throws.TypeOf<StorageException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void InsertIngredient_CorrectRecord_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.AddElement(ingredient)).Verifiable();
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act
|
|
|
|
_ingredientBusinessLogicContract.InsertIngredient(ingredient);
|
|
|
|
|
|
|
|
// Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void InsertIngredient_RecordWithExistsData_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.AddElement(ingredient))
|
|
|
|
.Throws(new ElementExistsException("ID", ingredient.Id));
|
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(ingredient), Throws.TypeOf<ElementExistsException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void InsertIngredient_NullRecord_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.AddElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void InsertIngredient_InvalidRecord_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(new IngredientDataModel("", "", "", -1)), Throws.TypeOf<ValidationException>());
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.AddElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void InsertIngredient_StorageThrowError_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
|
|
|
_ingredientStorageContact.Setup(x => x.AddElement(ingredient))
|
2025-02-26 23:49:16 +04:00
|
|
|
.Throws(new StorageException(new InvalidOperationException()));
|
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(ingredient), Throws.TypeOf<StorageException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void UpdateIngredient_CorrectRecord_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient)).Verifiable();
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act
|
|
|
|
_ingredientBusinessLogicContract.UpdateIngredient(ingredient);
|
|
|
|
|
|
|
|
// Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void UpdateIngredient_RecordNotFound_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient))
|
2025-02-27 02:25:39 +04:00
|
|
|
.Throws(new ElementNotFoundException(ingredient.Id));
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(ingredient), Throws.TypeOf<ElementNotFoundException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void UpdateIngredient_NullRecord_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.UpdateElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void UpdateIngredient_InvalidRecord_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(new IngredientDataModel("", "", "", -1)), Throws.TypeOf<ValidationException>());
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.UpdateElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void UpdateIngredient_StorageThrowError_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
|
|
|
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient))
|
2025-02-26 23:49:16 +04:00
|
|
|
.Throws(new StorageException(new InvalidOperationException()));
|
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(ingredient), Throws.TypeOf<StorageException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeleteIngredient_CorrectId_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var id = Guid.NewGuid().ToString();
|
|
|
|
var ingredient = new IngredientDataModel(id, "Sugar", "kg", 100);
|
2025-02-26 23:49:16 +04:00
|
|
|
var flag = false;
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(ingredient);
|
|
|
|
_ingredientStorageContact.Setup(x => x.DeleteElement(id)).Callback(() => { flag = true; });
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act
|
|
|
|
_ingredientBusinessLogicContract.DeleteIngredient(id);
|
|
|
|
|
|
|
|
// Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
Assert.That(flag);
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(Guid.TryParse(ingredient.Id, out _), Is.True);
|
|
|
|
Assert.That(!ingredient.Name.IsEmpty());
|
|
|
|
Assert.That(!ingredient.Unit.IsEmpty());
|
|
|
|
Assert.That(ingredient.Cost >= 0);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void DeleteIngredient_RecordNotFound_ThrowException_Test()
|
|
|
|
{
|
|
|
|
// Arrange
|
2025-02-27 02:25:39 +04:00
|
|
|
var id = Guid.NewGuid().ToString(); // Use valid Guid
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns((IngredientDataModel)null);
|
2025-02-26 23:49:16 +04:00
|
|
|
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(id), Throws.TypeOf<ElementNotFoundException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void DeleteIngredient_StorageThrowError_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
2025-02-27 02:25:39 +04:00
|
|
|
// Arrange
|
|
|
|
var id = Guid.NewGuid().ToString();
|
|
|
|
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(new IngredientDataModel(id, "Sugar", "kg", 100));
|
|
|
|
_ingredientStorageContact.Setup(x => x.DeleteElement(id)).Throws(new StorageException(new InvalidOperationException()));
|
|
|
|
|
2025-02-26 23:49:16 +04:00
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(id), Throws.TypeOf<StorageException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
|
|
|
_ingredientStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void DeleteIngredient_NullOrEmptyId_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
2025-02-26 23:49:16 +04:00
|
|
|
_ingredientStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
2025-02-27 02:25:39 +04:00
|
|
|
public void DeleteIngredient_InvalidId_ThrowException_Test()
|
2025-02-26 23:49:16 +04:00
|
|
|
{
|
|
|
|
// Act & Assert
|
2025-02-27 02:25:39 +04:00
|
|
|
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient("invalid"), Throws.TypeOf<ValidationException>());
|
|
|
|
_ingredientStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
2025-02-26 23:49:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|