This commit is contained in:
maxim 2025-02-17 16:34:59 +04:00
parent 774921e24b
commit b6f52294be
3 changed files with 36 additions and 9 deletions

View File

@ -11,7 +11,7 @@ using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class OrderDataModel( string id, DateTime dataTime, StatusType status, RoomType roomType) : IValidation
public class OrderDataModel( string id, DateTime dataTime, StatusType status, RoomType roomType, List<ServiceOrderDataModel> serviceOrder ) : IValidation
{
public string Id { get; private set; } = id;
@ -21,6 +21,8 @@ public class OrderDataModel( string id, DateTime dataTime, StatusType status, Ro
public RoomType RoomType { get; private set; } = roomType;
public List<ServiceOrderDataModel> ServiceOrders { get; private set; } = serviceOrder;
public void Validate()
{
if (Id.IsEmpty())
@ -37,5 +39,13 @@ public class OrderDataModel( string id, DateTime dataTime, StatusType status, Ro
if (RoomType == RoomType.None)
throw new ValidationException("Field RoomType is empty");
if(ServiceOrders == null)
{
throw new ValidationException("Field ServiceOrders is empty");
}
if (!ServiceOrders.Any())
{
throw new InvalidOperationException("ServiceOrders should not be empty");
}
}
}

View File

@ -72,6 +72,7 @@ internal class MasterDataModelTests
Assert.That(() => master.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{

View File

@ -12,41 +12,55 @@ namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class OrderDataModelTests
{
List<ServiceOrderDataModel> serviceOrders = new List<ServiceOrderDataModel>
{
new ServiceOrderDataModel("orderId1", "serviceId1", "masterId1", 60),
new ServiceOrderDataModel("orderId2", "serviceId2", "masterId2", 120)
};
[Test]
public void IdIsNullOrEmptyTest()
{
var order = CreateDataModel(string.Empty, DateTime.Now, StatusType.Ready, RoomType.Social);
var order = CreateDataModel(string.Empty, DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var order = CreateDataModel("id", DateTime.Now, StatusType.Ready, RoomType.Social);
var order = CreateDataModel("id", DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DateIsEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), default, StatusType.Ready, RoomType.Social);
var order = CreateDataModel(Guid.NewGuid().ToString(), default, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StatusIsNoneTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.None, RoomType.Social);
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.None, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void RoomTypeIsNoneTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.Ready, RoomType.None);
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.Ready, RoomType.None, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ListServiceOrderIsEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.Ready, RoomType.Social, null);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
@ -55,7 +69,8 @@ public class OrderDataModelTests
var status = StatusType.Ready;
var roomType = RoomType.Social;
var order = CreateDataModel(id, date, status, roomType);
var order = CreateDataModel(id, date, status, roomType, serviceOrders);
Assert.That(() => order.Validate(), Throws.Nothing);
@ -65,11 +80,12 @@ public class OrderDataModelTests
Assert.That(order.Date, Is.EqualTo(date));
Assert.That(order.Status, Is.EqualTo(status));
Assert.That(order.RoomType, Is.EqualTo(roomType));
Assert.That(order.ServiceOrders, Is.EqualTo(serviceOrders));
});
}
private static OrderDataModel CreateDataModel(string id, DateTime date, StatusType status, RoomType roomType)
private static OrderDataModel CreateDataModel(string id, DateTime date, StatusType status, RoomType roomType, List<ServiceOrderDataModel> serviceOrder)
{
return new OrderDataModel(id, date, status, roomType);
return new OrderDataModel(id, date, status, roomType, serviceOrder);
}
}