forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
правки
This commit is contained in:
@@ -10,11 +10,12 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace MagicCarpetContracts.DataModels;
|
namespace MagicCarpetContracts.DataModels;
|
||||||
|
|
||||||
public class AgencyDataModel(string id, TourType tourType, int count) : IValidation
|
public class AgencyDataModel(string id, TourType tourType, int count, List<TourAgencyDataModel> tours) : IValidation
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
public TourType Type { get; private set; } = tourType;
|
public TourType Type { get; private set; } = tourType;
|
||||||
public int Count { get; private set; } = count;
|
public int Count { get; private set; } = count;
|
||||||
|
public List<TourAgencyDataModel> Tours { get; private set; } = tours;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
@@ -26,5 +27,7 @@ public class AgencyDataModel(string id, TourType tourType, int count) : IValidat
|
|||||||
throw new ValidationException("Field Type is empty");
|
throw new ValidationException("Field Type is empty");
|
||||||
if (Count <= 0)
|
if (Count <= 0)
|
||||||
throw new ValidationException("Field Count is less than or equal to 0");
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
if ((Tours?.Count ?? 0) == 0)
|
||||||
|
throw new ValidationException("The sale must include tours");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,13 @@ using static System.Runtime.InteropServices.JavaScript.JSType;
|
|||||||
|
|
||||||
namespace MagicCarpetContracts.DataModels;
|
namespace MagicCarpetContracts.DataModels;
|
||||||
|
|
||||||
public class SuppliesDataModel(string id, TourType tourType, DateTime date, int count) : IValidation
|
public class SuppliesDataModel(string id, TourType tourType, DateTime date, int count, List<TourSuppliesDataModel> tours) : IValidation
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
public TourType Type { get; private set; } = tourType;
|
public TourType Type { get; private set; } = tourType;
|
||||||
public DateTime ProductuionDate { get; private set; } = date;
|
public DateTime ProductuionDate { get; private set; } = date;
|
||||||
public int Count { get; private set; } = count;
|
public int Count { get; private set; } = count;
|
||||||
|
public List<TourSuppliesDataModel> Tours { get; private set; } = tours;
|
||||||
|
|
||||||
public void Validate()
|
public void Validate()
|
||||||
{
|
{
|
||||||
@@ -28,5 +29,7 @@ public class SuppliesDataModel(string id, TourType tourType, DateTime date, int
|
|||||||
throw new ValidationException("Field Type is empty");
|
throw new ValidationException("Field Type is empty");
|
||||||
if (Count <= 0)
|
if (Count <= 0)
|
||||||
throw new ValidationException("Field Count is less than or equal to 0");
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
if ((Tours?.Count ?? 0) == 0)
|
||||||
|
throw new ValidationException("The sale must include tours");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,35 +15,44 @@ internal class AgencyDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(null, TourType.Beach, 1);
|
var model = CreateDataModel(null, TourType.Beach, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
model = CreateDataModel(string.Empty, TourType.Beach, 1);
|
model = CreateDataModel(string.Empty, TourType.Beach, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel("id", TourType.Beach, 1);
|
var model = CreateDataModel("id", TourType.Beach, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TypeIsNoneTest()
|
public void TypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, 1);
|
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CountIsLessOrZeroTest()
|
public void CountIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, 0);
|
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, 0, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, -1);
|
model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, -1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
[Test]
|
||||||
|
public void ToursIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(), TourType.Beach, 1, null);
|
||||||
|
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
sale = CreateDataModel(Guid.NewGuid().ToString(), TourType.Beach, 1, []);
|
||||||
|
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
@@ -51,16 +60,20 @@ internal class AgencyDataModelTests
|
|||||||
var id = Guid.NewGuid().ToString();
|
var id = Guid.NewGuid().ToString();
|
||||||
var type = TourType.Beach;
|
var type = TourType.Beach;
|
||||||
var count = 1;
|
var count = 1;
|
||||||
var model = CreateDataModel(id, type, count);
|
var tours = CreateSubDataModel();
|
||||||
|
var model = CreateDataModel(id, type, count, tours);
|
||||||
Assert.DoesNotThrow(() => model.Validate());
|
Assert.DoesNotThrow(() => model.Validate());
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
Assert.That(model.Id, Is.EqualTo(id));
|
Assert.That(model.Id, Is.EqualTo(id));
|
||||||
Assert.That(model.Type, Is.EqualTo(type));
|
Assert.That(model.Type, Is.EqualTo(type));
|
||||||
Assert.That(model.Count, Is.EqualTo(count));
|
Assert.That(model.Count, Is.EqualTo(count));
|
||||||
|
Assert.That(model.Tours, Is.EqualTo(tours));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AgencyDataModel CreateDataModel(string? id, TourType type, int count)
|
private static AgencyDataModel CreateDataModel(string? id, TourType type, int count, List<TourAgencyDataModel> tours)
|
||||||
=> new AgencyDataModel(id, type, count);
|
=> new AgencyDataModel(id, type, count, tours);
|
||||||
|
private static List<TourAgencyDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,35 +15,43 @@ internal class SuppliesDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(null, TourType.Beach, DateTime.Now, 1);
|
var model = CreateDataModel(null, TourType.Beach, DateTime.Now, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
model = CreateDataModel(string.Empty, TourType.Beach, DateTime.Now, 1);
|
model = CreateDataModel(string.Empty, TourType.Beach, DateTime.Now, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel("id", TourType.Beach, DateTime.Now, 1);
|
var model = CreateDataModel("id", TourType.Beach, DateTime.Now, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void TypeIsNoneTest()
|
public void TypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, 1);
|
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, 1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void CountIsLessOrZeroTest()
|
public void CountIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, 0);
|
var model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, 0, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, -1);
|
model = CreateDataModel(Guid.NewGuid().ToString(), TourType.None, DateTime.Now, -1, CreateSubDataModel());
|
||||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
[Test]
|
||||||
|
public void ToursIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var sale = CreateDataModel(Guid.NewGuid().ToString(), TourType.Beach, DateTime.Now, 1, null);
|
||||||
|
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
sale = CreateDataModel(Guid.NewGuid().ToString(), TourType.Beach, DateTime.Now, 1, []);
|
||||||
|
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void AllFieldsIsCorrectTest()
|
public void AllFieldsIsCorrectTest()
|
||||||
@@ -52,7 +60,8 @@ internal class SuppliesDataModelTests
|
|||||||
var type = TourType.Beach;
|
var type = TourType.Beach;
|
||||||
var date = DateTime.Now;
|
var date = DateTime.Now;
|
||||||
var count = 1;
|
var count = 1;
|
||||||
var model = CreateDataModel(id, type, date, count);
|
var tours = CreateSubDataModel();
|
||||||
|
var model = CreateDataModel(id, type, date, count, tours);
|
||||||
Assert.DoesNotThrow(() => model.Validate());
|
Assert.DoesNotThrow(() => model.Validate());
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
{
|
{
|
||||||
@@ -60,9 +69,12 @@ internal class SuppliesDataModelTests
|
|||||||
Assert.That(model.Type, Is.EqualTo(type));
|
Assert.That(model.Type, Is.EqualTo(type));
|
||||||
Assert.That(model.ProductuionDate, Is.EqualTo(date));
|
Assert.That(model.ProductuionDate, Is.EqualTo(date));
|
||||||
Assert.That(model.Count, Is.EqualTo(count));
|
Assert.That(model.Count, Is.EqualTo(count));
|
||||||
|
Assert.That(model.Tours, Is.EqualTo(tours));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SuppliesDataModel CreateDataModel(string? id, TourType type, DateTime date, int count)
|
private static SuppliesDataModel CreateDataModel(string? id, TourType type, DateTime date, int count, List<TourSuppliesDataModel> tours)
|
||||||
=> new(id, type, date, count);
|
=> new(id, type, date, count, tours);
|
||||||
|
private static List<TourSuppliesDataModel> CreateSubDataModel()
|
||||||
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user