Compare commits
2 Commits
Task_8
...
Task_1Hard
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21258b1c31 | ||
| 9730a641c4 |
@@ -0,0 +1,33 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SupplyCocktailDataModel(string? supplyId, string? cocktailId, int count) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (CocktailId.IsEmpty())
|
||||
throw new ValidationException("Field CocktailId is empty");
|
||||
|
||||
if (!CocktailId.IsGuid())
|
||||
throw new ValidationException("The value in the field CocktailId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class SupplyDataModel(string? id, DateTime dateTime, List<SupplyCocktailDataModel> cocktails) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = dateTime;
|
||||
|
||||
public List<SupplyCocktailDataModel> Cocktails { get; private set; } = cocktails;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (SupplyDate.Date > DateTime.Now)
|
||||
throw new ValidationException($"It is impossible to supply things in the future");
|
||||
|
||||
if ((Cocktails?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The components must include products");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class WarehouseCocktailDataModel(string? warehouseId, string? cocktailId, int count) : IValidation
|
||||
{
|
||||
public string WarehouseId { get; private set; } = warehouseId;
|
||||
|
||||
public string CocktailId { get; private set; } = cocktailId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WarehouseId.IsEmpty())
|
||||
throw new ValidationException("Field WarehouseId is empty");
|
||||
|
||||
if (!WarehouseId.IsGuid())
|
||||
throw new ValidationException("The value in the field WarehouseId is not a unique identifier");
|
||||
|
||||
if (CocktailId.IsEmpty())
|
||||
throw new ValidationException("Field CocktailId is empty");
|
||||
|
||||
if (!CocktailId.IsGuid())
|
||||
throw new ValidationException("The value in the field CocktailId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
using SquirrelContract.Exceptions;
|
||||
using SquirrelContract.Extensions;
|
||||
using SquirrelContract.Infastructure;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace SquirrelContract.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string? id, string name, List<WarehouseCocktailDataModel> cocktails) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
public List<WarehouseCocktailDataModel> Cocktails { get; private set; } = cocktails;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
|
||||
if ((Cocktails?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The cocktails must include drinks");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyCocktailDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel("SupplyId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNotGuidTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), "ComponentId", 10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supplyCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var count = 5;
|
||||
var supplyCocktail = CreateDataModel(supplyId, cocktailId, count);
|
||||
Assert.That(() => supplyCocktail.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyCocktail.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(supplyCocktail.CocktailId, Is.EqualTo(cocktailId));
|
||||
Assert.That(supplyCocktail.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyCocktailDataModel CreateDataModel(string? supplyId, string? cocktailId, int count) =>
|
||||
new(supplyId, cocktailId, count);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(null, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supply = CreateDataModel(string.Empty, DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var supply = CreateDataModel("id", DateTime.Now, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailsIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, null);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, []);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DateIsNotCorrectTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now.AddDays(5), CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var date = DateTime.Now;
|
||||
var cocktails = CreateSubDataModel();
|
||||
var supply = CreateDataModel(supplyId, date, cocktails);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
||||
Assert.That(supply.SupplyDate, Is.EqualTo(date));
|
||||
Assert.That(supply.Cocktails, Is.EquivalentTo(cocktails));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, DateTime date, List<SupplyCocktailDataModel> cocktails) =>
|
||||
new(id, date, cocktails);
|
||||
|
||||
private static List<SupplyCocktailDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseCocktailDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WarehouseIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel("id", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailIdIsNotGuidTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), "id", 10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouseCocktail = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var cocktailId = Guid.NewGuid().ToString();
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var count = 5;
|
||||
var warehouseCocktail = CreateDataModel(warehouseId, cocktailId, count);
|
||||
Assert.That(() => warehouseCocktail.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouseCocktail.WarehouseId, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouseCocktail.CocktailId, Is.EqualTo(cocktailId));
|
||||
Assert.That(warehouseCocktail.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseCocktailDataModel CreateDataModel(string? storageId, string? cocktailId, int count) =>
|
||||
new(storageId, cocktailId, count);
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using SquirrelContract.DataModels;
|
||||
using SquirrelContract.Exceptions;
|
||||
|
||||
namespace SquirrelTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(null, "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(string.Empty, "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var warehouse = CreateDataModel("id", "name", CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WarehouseNameIsEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), null, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, CreateSubDataModel());
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CocktailsIsNullOrEmptyTest()
|
||||
{
|
||||
var warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", null);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), "name", []);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var warehouseId = Guid.NewGuid().ToString();
|
||||
var warehouseName = "name";
|
||||
var cocktails = CreateSubDataModel();
|
||||
var warehouse = CreateDataModel(warehouseId, warehouseName, cocktails);
|
||||
Assert.That(() => warehouse.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouse.Id, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouse.Name, Is.EqualTo(warehouseName));
|
||||
Assert.That(warehouse.Cocktails, Is.EquivalentTo(cocktails));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, string? storageName, List<WarehouseCocktailDataModel> cocktails) =>
|
||||
new(id, storageName, cocktails);
|
||||
|
||||
private static List<WarehouseCocktailDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), "name", 1)];
|
||||
}
|
||||
Reference in New Issue
Block a user