сложно

This commit is contained in:
maxim 2025-03-03 17:22:35 +04:00
parent b6f52294be
commit 381a9e667a
11 changed files with 458 additions and 0 deletions

View File

@ -0,0 +1,27 @@
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class MenuDataModel(string id, string name, string supplyId) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public string SupplyId { get; private set; } = supplyId;
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 (SupplyId.IsEmpty())
throw new ValidationException("Field SupplyId is empty");
}
}

View File

@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class SaleServiceDataModel(string saleId, string serviceId, int count) :
IValidation
{
public string SaleId { get; private set; } = saleId;
public string ServiceId { get; private set; } = serviceId;
public int Count { get; private set; } = count;
public void Validate()
{
if (SaleId.IsEmpty())
throw new ValidationException("Field SaleId is empty");
if (!SaleId.IsGuid())
throw new ValidationException("The value in the field SaleId is not a unique identifier");
if (ServiceId.IsEmpty())
throw new ValidationException("Field ServiceId is empty");
if (!ServiceId.IsGuid())
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
if (Count <= 0)
throw new ValidationException("Field Count is less than or equal to 0");
}
}

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class SupplyDataModel(string id, DateTime date, List<SupplyServiceDataModel> supplyService) : IValidation
{
public string Id { get; private set; } = id;
public DateTime Date { get; private set; } = date;
public List<SupplyServiceDataModel> Services { get; private set; } = supplyService;
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(Date == default)
throw new ValidationException("Field Date is empty");
if (!Services.Any())
{
throw new InvalidOperationException("ServiceOrders should not be empty");
}
}
}

View File

@ -0,0 +1,38 @@
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class SupplyServiceDataModel(string id, string serviceId, int count): IValidation
{
public string Id { get; private set; } = id;
public string ServiceId { get; private set; } = serviceId;
public int Count { get; private set; } = count;
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 (ServiceId.IsEmpty())
{
throw new ValidationException("Field ServiceId is empty");
}
if (!ServiceId.IsGuid())
{
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
}
if ((Count == 0) || (Count < 0))
{
throw new ValidationException("Field Count is less than or equal to 0");
}
}
}

View File

@ -0,0 +1,77 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class MenuDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var menu = CreateDataModel(null, "dasd", "sasda");
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
menu = CreateDataModel(string.Empty, "dasd", "sasda");
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var menu = CreateDataModel("NotAGuid", "TestName", "TestSupplyId");
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void NameIsNullOrEmptyTest()
{
var menu = CreateDataModel(Guid.NewGuid().ToString(), null, "TestSupplyId");
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
menu = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "TestSupplyId");
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplyIdIsNullOrEmptyTest()
{
var menu = CreateDataModel(Guid.NewGuid().ToString(), "TestName", null);
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
menu = CreateDataModel(Guid.NewGuid().ToString(), "TestName", string.Empty);
Assert.That(() => menu.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var name = "TestName";
var supplyId = "TestSupplyId";
var menu = CreateDataModel(id, name, supplyId);
Assert.That(() => menu.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(menu.Id, Is.EqualTo(id));
Assert.That(menu.Name, Is.EqualTo(name));
Assert.That(menu.SupplyId, Is.EqualTo(supplyId));
});
}
private static MenuDataModel CreateDataModel(string id, string name, string supplyId)
{
return new MenuDataModel(id, name, supplyId);
}
}

View File

@ -23,6 +23,9 @@ public class OrderDataModelTests
var order = CreateDataModel(string.Empty, DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(null, DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class SaleServiceDataModelTests
{
[Test]
public void SaleIdIsNullOrEmptyTest()
{
var saleService = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 5);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SaleIdIsNotGuidTest()
{
var saleService = CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 5);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNullOrEmptyTest()
{
var saleService = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 5);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNotGuidTest()
{
var saleService = CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 5);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrEqualToZeroTest()
{
var saleService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
saleService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var saleId = Guid.NewGuid().ToString();
var serviceId = Guid.NewGuid().ToString();
var count = 5;
var saleService = CreateDataModel(saleId, serviceId, count);
Assert.That(() => saleService.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(saleService.SaleId, Is.EqualTo(saleId));
Assert.That(saleService.ServiceId, Is.EqualTo(serviceId));
Assert.That(saleService.Count, Is.EqualTo(count));
});
}
private static SaleServiceDataModel CreateDataModel(string saleId, string serviceId, int count)
{
return new SaleServiceDataModel(saleId, serviceId, count);
}
}

View File

@ -17,6 +17,8 @@ public class ServiceDataModelTests
{
var service = CreateDataModel(string.Empty, "bb", ServiceType.Plastering, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
service = CreateDataModel(null, "bb", ServiceType.Plastering, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]

View File

@ -16,6 +16,8 @@ public class ServiceOrderDataModelTests
{
var serviceOrder = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
serviceOrder = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class SupplyDataModelTests
{
List<SupplyServiceDataModel> supplyService = new List<SupplyServiceDataModel>
{
new SupplyServiceDataModel("id1", "serviceId1", 60),
new SupplyServiceDataModel("id2", "serviceId2", 120)
};
[Test]
public void IdIsNullOrEmptyTest()
{
var slupply = CreateDataModel(null, DateTime.Now, supplyService);
Assert.That(() => slupply.Validate(), Throws.TypeOf<ValidationException>());
slupply = CreateDataModel(string.Empty, DateTime.Now, supplyService);
Assert.That(() => slupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var slupply = CreateDataModel("dwsa", DateTime.Now, supplyService);
Assert.That(() => slupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DateIsNullTest()
{
var slupply = CreateDataModel("1123", default, supplyService);
Assert.That(() => slupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplyServiceListIsNull()
{
var slupply = CreateDataModel("1123", DateTime.Now, null);
Assert.That(() => slupply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var date = DateTime.Now;
var slupply = CreateDataModel(id, date, supplyService);
Assert.That(() => slupply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(slupply.Id, Is.EqualTo(id));
Assert.That(slupply.Date, Is.EqualTo(date));
Assert.That(slupply.Services, Is.EqualTo(supplyService));
});
}
private static SupplyDataModel CreateDataModel(string id, DateTime date, List<SupplyServiceDataModel> supplyService)
{
return new SupplyDataModel(id, date, supplyService);
}
}

View File

@ -0,0 +1,81 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class SupplyServiceDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var supplyService = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
supplyService = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var supplyService = CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNullOrEmptyTest()
{
var supplyService = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
supplyService = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNotGuidTest()
{
var supplyService = CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 10);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrEqualToZeroTest()
{
var supplyService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
supplyService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -5);
Assert.That(() => supplyService.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var serviceId = Guid.NewGuid().ToString();
var count = 10;
var supplyService = CreateDataModel(id, serviceId, count);
Assert.That(() => supplyService.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supplyService.Id, Is.EqualTo(id));
Assert.That(supplyService.ServiceId, Is.EqualTo(serviceId));
Assert.That(supplyService.Count, Is.EqualTo(count));
});
}
private static SupplyServiceDataModel CreateDataModel(string? id, string? serviceId, int count)
{
return new SupplyServiceDataModel(id, serviceId, count);
}
}