feauture: add warehouse
This commit is contained in:
parent
9c130e1eb4
commit
f49b15c9c4
@ -0,0 +1,46 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class SoftwareSupplyDataModel(string id, int count, string softwareId, string supplyId) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public string SoftwareId { get; private set; } = softwareId;
|
||||
|
||||
public string SupplyId { get; private set; } = supplyId;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidationFieldException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (SoftwareId.isEmpty())
|
||||
throw new ValidationFieldException("Field SoftwareId is empty");
|
||||
|
||||
if (!SoftwareId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field SoftwareId is not a unique identifier");
|
||||
|
||||
if (SupplyId.isEmpty())
|
||||
throw new ValidationFieldException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field SupplyId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationFieldException("Field Count is less than or equal to 0");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class SupplyDataModel(string id, string companyId, DateTime supplyDate, double totalCost, List<SoftwareSupplyDataModel> softwares) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string CompanyId { get; private set; } = companyId;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = supplyDate;
|
||||
|
||||
public List<SoftwareSupplyDataModel> Softwares { get; private set; } = softwares;
|
||||
|
||||
public double TotalCost { get; private set; } = totalCost;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidationFieldException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (CompanyId.isEmpty())
|
||||
throw new ValidationFieldException("Field CompanyId is empty");
|
||||
|
||||
if (!CompanyId.isGuid())
|
||||
throw new ValidationFieldException("The value in the field CompanyId is not a unique identifier");
|
||||
|
||||
if (TotalCost <= 0)
|
||||
throw new ValidationFieldException("Field TotalCost is less than or equal to 0");
|
||||
|
||||
if ((Softwares?.Count ?? 0) == 0)
|
||||
throw new ValidationFieldException("The supply must include softwares");
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using SoftwareInstallationContracts.Extensions;
|
||||
using SoftwareInstallationContracts.Infrastucture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationContracts.DataModels;
|
||||
|
||||
public class WarehouseDataModel(string id, int minCount, int currentCount, DateTime date) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public int MinCount { get; private set; } = minCount;
|
||||
|
||||
public int CurrentCount { get; private set; } = currentCount;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = date;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.isEmpty())
|
||||
throw new ValidationFieldException("Field Id is empty");
|
||||
|
||||
if (!Id.isGuid())
|
||||
throw new ValidationFieldException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (MinCount <= 0)
|
||||
throw new ValidationFieldException("Field MinCount is less than or equal to 0");
|
||||
|
||||
if (CurrentCount <= 0)
|
||||
throw new ValidationFieldException("Field CurrentCount is less than or equal to 0");
|
||||
|
||||
if (CurrentCount < MinCount)
|
||||
throw new ValidationFieldException("Field CurrentCount is less than MinCount");
|
||||
}
|
||||
}
|
@ -54,6 +54,5 @@ internal class SalaryDataModelTests
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate,
|
||||
double workerSalary) => new(workerId, salaryDate, workerSalary);
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime date, double workerSalary) => new(workerId, date, workerSalary);
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
using SoftwareInstallationContracts.DataModels;
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationTests.DataModelsTests;
|
||||
|
||||
internal class SoftwareSupplyDataModelTests
|
||||
{
|
||||
private SoftwareSupplyDataModel softwareSupply;
|
||||
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(null, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
softwareSupply = CreateDataModel(string.Empty, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel("id", 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoftwareIdIsNullOrEmptyTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, null, Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, string.Empty, Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoftwareIdIsNotGuidTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, "softwareId", Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuidTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), "supplyId");
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
string id = Guid.NewGuid().ToString();
|
||||
string softwareId = Guid.NewGuid().ToString();
|
||||
string supplyId = Guid.NewGuid().ToString();
|
||||
int count = 10;
|
||||
softwareSupply = CreateDataModel(id, count, softwareId, supplyId);
|
||||
Assert.That(() => softwareSupply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(softwareSupply.Id, Is.EqualTo(id));
|
||||
Assert.That(softwareSupply.SoftwareId, Is.EqualTo(softwareId));
|
||||
Assert.That(softwareSupply.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(softwareSupply.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static SoftwareSupplyDataModel CreateDataModel(string? id, int count, string? softwareId, string? supplyId)
|
||||
=> new(id, count, softwareId, supplyId);
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
using SoftwareInstallationContracts.DataModels;
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationTests.DataModelsTests;
|
||||
|
||||
internal class SupplyDataModelTests
|
||||
{
|
||||
private SupplyDataModel supply;
|
||||
|
||||
[Test]
|
||||
public void IdIsEmptyTest()
|
||||
{
|
||||
supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
supply = CreateDataModel("Id", Guid.NewGuid().ToString(), DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompanyIdIsEmptyTest()
|
||||
{
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CompanyIdIsNotGuidTest()
|
||||
{
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), "companyId", DateTime.UtcNow, 10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 0, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, -10, CreateSubDataModel());
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SoftwaresIsNullOrEmptyTest()
|
||||
{
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, null);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 10, []);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
string supplyId = Guid.NewGuid().ToString();
|
||||
string companyId = Guid.NewGuid().ToString();
|
||||
double totalCost = 10;
|
||||
DateTime dateTime = DateTime.UtcNow;
|
||||
List<SoftwareSupplyDataModel> softwares = CreateSubDataModel();
|
||||
supply = CreateDataModel(supplyId, companyId, dateTime, totalCost, softwares);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(supplyId));
|
||||
Assert.That(supply.CompanyId, Is.EqualTo(companyId));
|
||||
Assert.That(supply.TotalCost, Is.EqualTo(totalCost));
|
||||
Assert.That(supply.SupplyDate, Is.EqualTo(dateTime));
|
||||
Assert.That(supply.Softwares, Is.EquivalentTo(softwares));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, string? companyId, DateTime supplyDate, double totalCost, List<SoftwareSupplyDataModel> softwares)
|
||||
=> new(id, companyId, supplyDate, totalCost, softwares);
|
||||
|
||||
private static List<SoftwareSupplyDataModel> CreateSubDataModel()
|
||||
=> [new (Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString())];
|
||||
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
using SoftwareInstallationContracts.DataModels;
|
||||
using SoftwareInstallationContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SoftwareInstallationTests.DataModelsTests;
|
||||
|
||||
internal class WarehouseDataModelTests
|
||||
{
|
||||
private WarehouseDataModel warehouse;
|
||||
|
||||
[Test]
|
||||
public void IdIsEmptyTest()
|
||||
{
|
||||
warehouse = CreateDataModel(null, 10, 20, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
warehouse = CreateDataModel(string.Empty, 10, 20, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
warehouse = CreateDataModel("id", 10, 20, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MinCountIsLessOrZeroTest()
|
||||
{
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), 0, 10, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), -10, 10, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CurrentCountIsLessOrZeroTest()
|
||||
{
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), 10, 0, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), 10, -10, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CurrentCountIsLessThanMinCount()
|
||||
{
|
||||
warehouse = CreateDataModel(Guid.NewGuid().ToString(), 10, 0, DateTime.Now);
|
||||
Assert.That(() => warehouse.Validate(), Throws.TypeOf<ValidationFieldException>());
|
||||
}
|
||||
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
string warehouseId = Guid.NewGuid().ToString();
|
||||
int minCount = 10;
|
||||
int currentCount = 10;
|
||||
DateTime date = DateTime.UtcNow;
|
||||
WarehouseDataModel warehouse = CreateDataModel(warehouseId, minCount, currentCount, date);
|
||||
Assert.That(() => warehouse.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(warehouse.Id, Is.EqualTo(warehouseId));
|
||||
Assert.That(warehouse.MinCount, Is.EqualTo(minCount));
|
||||
Assert.That(warehouse.CurrentCount, Is.EqualTo(currentCount));
|
||||
Assert.That(warehouse.ChangeDate, Is.EqualTo(date));
|
||||
});
|
||||
}
|
||||
|
||||
private static WarehouseDataModel CreateDataModel(string? id, int minCount, int currentCount, DateTime date)
|
||||
=> new(id, minCount, currentCount, date);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user