@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class StorageDataModel : IValidation
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public string Title { get; set; }
|
||||
public StorageType StorageType { get; set; }
|
||||
public List<IngredientDataModel> Ingredients { get; set; }
|
||||
|
||||
public StorageDataModel(string id, string title, StorageType storageType, List<IngredientDataModel> ingredients)
|
||||
{
|
||||
Id = id;
|
||||
Title = title;
|
||||
StorageType = storageType;
|
||||
Ingredients = ingredients;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Invalid Id format");
|
||||
if (Title.IsEmpty()) throw new ValidationException("Field Title is empty");
|
||||
if (!Enum.IsDefined(typeof(StorageType), StorageType))
|
||||
throw new ValidationException($"Invalid StorageType: {StorageType}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class StorageIngredientDataModel : IValidation
|
||||
{
|
||||
public string StorageId { get; set; }
|
||||
public string IngredientId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public StorageIngredientDataModel(string storageId, string ingredientId, int quantity)
|
||||
{
|
||||
StorageId = storageId;
|
||||
IngredientId = ingredientId;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (StorageId.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!StorageId.IsGuid()) throw new ValidationException("Field Id is not a valid GUID");
|
||||
if (IngredientId.IsEmpty()) throw new ValidationException("Field IngredientId is empty");
|
||||
if (!IngredientId.IsGuid()) throw new ValidationException("Field IngredientId is not a valid GUID");
|
||||
if (Quantity <= 0) throw new ValidationException("Field Quantity must be greater than zero");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class SupplyDataModel : IValidation
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public DateTime Date { get; set; }
|
||||
public int TotalQuantity { get; set; }
|
||||
public decimal TotalPrice { get; set; }
|
||||
|
||||
public List<IngredientDataModel> Ingredients { get; set; }
|
||||
|
||||
public SupplyDataModel(string id, DateTime date, int quantity, decimal totalPrice,
|
||||
List<IngredientDataModel> ingredients)
|
||||
{
|
||||
Id = id;
|
||||
Date = date;
|
||||
TotalQuantity = quantity;
|
||||
TotalPrice = totalPrice;
|
||||
Ingredients = ingredients;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Supply ID cannot be null or empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Supply ID must be a valid GUID");
|
||||
if (Date == default) throw new ValidationException("Supply date cannot be null");
|
||||
if (TotalQuantity <= 0) throw new ValidationException("Supply quantity must be greater than zero");
|
||||
if (TotalPrice < 0) throw new ValidationException("Supply total price cannot be negative");
|
||||
if (Ingredients == null || Ingredients.Count == 0)
|
||||
throw new ValidationException("Supply must have at least one ingredient");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class SupplyIngredientDataModel : IValidation
|
||||
{
|
||||
public string SupplyId { get; set; }
|
||||
public string IngredientId { get; set; }
|
||||
public int Quantity { get; set; }
|
||||
|
||||
public SupplyIngredientDataModel(string supplyId, string ingredientId, int quantity)
|
||||
{
|
||||
SupplyId = supplyId;
|
||||
IngredientId = ingredientId;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty()) throw new ValidationException("Supply ID cannot be null or empty");
|
||||
if (!SupplyId.IsGuid()) throw new ValidationException("Supply ID is not a valid GUID");
|
||||
if (IngredientId.IsEmpty()) throw new ValidationException("Ingredient ID cannot be null or empty");
|
||||
if (!IngredientId.IsGuid()) throw new ValidationException("Ingredient ID is not a valid GUID");
|
||||
if (Quantity <= 0) throw new ValidationException("Quantity must be a positive number");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
namespace CandyHouseBase.Enums
|
||||
{
|
||||
public enum StorageType
|
||||
{
|
||||
Fridge,
|
||||
Shelf,
|
||||
Cabinet
|
||||
}
|
||||
}
|
||||
@@ -162,10 +162,6 @@
|
||||
<Compile Include="DataModelsTests\ProductDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\RecipeDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\SalaryDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\StorageDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\StorageIngredientDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\SupplyDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\SupplyIngredientDataModelTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class StorageDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateStorageDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var title = "Main Warehouse";
|
||||
var storageType = StorageType.Fridge;
|
||||
var ingredients = new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
};
|
||||
|
||||
var storage = new StorageDataModel(id, title, storageType, ingredients);
|
||||
|
||||
Assert.AreEqual(id, storage.Id);
|
||||
Assert.AreEqual(title, storage.Title);
|
||||
Assert.AreEqual(storageType, storage.StorageType);
|
||||
Assert.AreEqual(ingredients, storage.Ingredients);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var storage = new StorageDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Main Warehouse",
|
||||
StorageType.Fridge,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.DoesNotThrow(() => storage.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyId_ShouldThrowValidationException()
|
||||
{
|
||||
var storage = new StorageDataModel(
|
||||
"",
|
||||
"Main Warehouse",
|
||||
StorageType.Fridge,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => storage.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var storage = new StorageDataModel(
|
||||
"invalid-guid",
|
||||
"Main Warehouse",
|
||||
StorageType.Fridge,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => storage.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyTitle_ShouldThrowValidationException()
|
||||
{
|
||||
var storage = new StorageDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"",
|
||||
StorageType.Fridge,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => storage.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidStorageType_ShouldThrowValidationException()
|
||||
{
|
||||
var storage = new StorageDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Main Warehouse",
|
||||
(StorageType)999,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => storage.Validate());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class StorageIngredientDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateStorageIngredientDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var storageId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var quantity = 5;
|
||||
|
||||
var storageIngredient = new StorageIngredientDataModel(storageId, ingredientId, quantity);
|
||||
|
||||
Assert.AreEqual(storageId, storageIngredient.StorageId);
|
||||
Assert.AreEqual(ingredientId, storageIngredient.IngredientId);
|
||||
Assert.AreEqual(quantity, storageIngredient.Quantity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
10);
|
||||
|
||||
Assert.DoesNotThrow(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyStorageId_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
"",
|
||||
Guid.NewGuid().ToString(),
|
||||
10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidStorageIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
"invalid-guid",
|
||||
Guid.NewGuid().ToString(),
|
||||
10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyIngredientId_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"",
|
||||
10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidIngredientIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"not-a-guid",
|
||||
10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NonPositiveQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
0);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var storageIngredient = new StorageIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
-5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => storageIngredient.Validate());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SupplyDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateSupplyDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var date = DateTime.Now;
|
||||
var totalQuantity = 100;
|
||||
var totalPrice = 150.75m;
|
||||
var ingredients = new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
};
|
||||
|
||||
var supply = new SupplyDataModel(id, date, totalQuantity, totalPrice, ingredients);
|
||||
|
||||
Assert.AreEqual(id, supply.Id);
|
||||
Assert.AreEqual(date, supply.Date);
|
||||
Assert.AreEqual(totalQuantity, supply.TotalQuantity);
|
||||
Assert.AreEqual(totalPrice, supply.TotalPrice);
|
||||
Assert.AreEqual(ingredients, supply.Ingredients);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
50,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.DoesNotThrow(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyId_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
"",
|
||||
DateTime.Now,
|
||||
50,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
"not-a-guid",
|
||||
DateTime.Now,
|
||||
50,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_DefaultDate_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
default(DateTime),
|
||||
50,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NonPositiveQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
0,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeTotalPrice_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
50,
|
||||
-10.50m,
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10)
|
||||
});
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NullIngredients_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
50,
|
||||
75.25m,
|
||||
null);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyIngredients_ShouldThrowValidationException()
|
||||
{
|
||||
var supply = new SupplyDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
50,
|
||||
75.25m,
|
||||
new List<IngredientDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => supply.Validate());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SupplyIngredientDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateSupplyIngredientDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var quantity = 10;
|
||||
|
||||
var supplyIngredient = new SupplyIngredientDataModel(supplyId, ingredientId, quantity);
|
||||
|
||||
Assert.AreEqual(supplyId, supplyIngredient.SupplyId);
|
||||
Assert.AreEqual(ingredientId, supplyIngredient.IngredientId);
|
||||
Assert.AreEqual(quantity, supplyIngredient.Quantity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
5);
|
||||
|
||||
Assert.DoesNotThrow(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptySupplyId_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
"",
|
||||
Guid.NewGuid().ToString(),
|
||||
5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidSupplyIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
"invalid-guid",
|
||||
Guid.NewGuid().ToString(),
|
||||
5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_EmptyIngredientId_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"",
|
||||
5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidIngredientIdFormat_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"not-a-guid",
|
||||
5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NonPositiveQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
0);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var supplyIngredient = new SupplyIngredientDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
-3);
|
||||
|
||||
Assert.Throws<ValidationException>(() => supplyIngredient.Validate());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user