done(корректировка кода)
This commit is contained in:
parent
2adcba7625
commit
3e31339857
@ -38,7 +38,7 @@ public class SupplierDataModel(string id, string fio, string email, double disco
|
|||||||
throw new ValidationException("Field Email is empty");
|
throw new ValidationException("Field Email is empty");
|
||||||
|
|
||||||
if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
if (!Regex.IsMatch(Email, @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$"))
|
||||||
throw new ValidationException("Field Email is not a phone number");
|
throw new ValidationException("Field Email is not a email");
|
||||||
|
|
||||||
if (DiscountSize < 0)
|
if (DiscountSize < 0)
|
||||||
throw new ValidationException("Field DiscountSize is less than zero");
|
throw new ValidationException("Field DiscountSize is less than zero");
|
||||||
|
@ -44,6 +44,6 @@ public class SupplyDataModel(string id, string supplierId, int sum, DateTime sup
|
|||||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||||
|
|
||||||
if ((Crops?.Count ?? 0) == 0)
|
if ((Crops?.Count ?? 0) == 0)
|
||||||
throw new ValidationException("The sale must include products");
|
throw new ValidationException("The sale must include crops");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,11 @@ internal class CropDataModelsTests
|
|||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
var crop = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
crop = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name",
|
crop = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,18 +28,18 @@ internal class CropDataModelsTests
|
|||||||
public void IdIsNotGuid()
|
public void IdIsNotGuid()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel("Id", Guid.NewGuid().ToString(), "name",
|
var crop = CreateDataModel("Id", Guid.NewGuid().ToString(), "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void HarvestIdIsNullOrEmptyTest()
|
public void HarvestIdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
var crop = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
crop = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name",
|
crop = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ internal class CropDataModelsTests
|
|||||||
public void HarvestIdIsNotGuid()
|
public void HarvestIdIsNotGuid()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), "Id", "name",
|
var crop = CreateDataModel(Guid.NewGuid().ToString(), "Id", "name",
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ internal class CropDataModelsTests
|
|||||||
public void CropNameIsEmptyTest()
|
public void CropNameIsEmptyTest()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
||||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,11 +63,11 @@ internal class CropDataModelsTests
|
|||||||
public void PriceIsLessOrZeroTest()
|
public void PriceIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||||
0, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
0, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||||
-10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
-10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ internal class CropDataModelsTests
|
|||||||
public void CropTypeIsNoneTest()
|
public void CropTypeIsNoneTest()
|
||||||
{
|
{
|
||||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||||
10, 9, 8, CropType.None, true, DateTime.UtcNow, false);
|
10, CropType.None, true, DateTime.UtcNow, false);
|
||||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,8 +92,8 @@ internal class CropDataModelsTests
|
|||||||
var isActual = true;
|
var isActual = true;
|
||||||
var replenishmentDate = DateTime.UtcNow.AddDays(-1);
|
var replenishmentDate = DateTime.UtcNow.AddDays(-1);
|
||||||
var isDeleted = false;
|
var isDeleted = false;
|
||||||
var crop = CreateDataModel(cropId, harvestId, cropName, price, prevPrice,
|
var crop = CreateDataModel(cropId, harvestId, cropName, price, cropType, isActual,
|
||||||
prevPrevPrice, cropType, isActual, replenishmentDate, isDeleted);
|
replenishmentDate, isDeleted, prevPrice, prevPrevPrice);
|
||||||
|
|
||||||
Assert.That(() => crop.Validate(), Throws.Nothing);
|
Assert.That(() => crop.Validate(), Throws.Nothing);
|
||||||
Assert.Multiple(() =>
|
Assert.Multiple(() =>
|
||||||
@ -111,9 +111,8 @@ internal class CropDataModelsTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static CropDataModel CreateDataModel(string? id, string? harvestId,
|
private static CropDataModel CreateDataModel(string? id, string? harvestId, string? cropName,
|
||||||
string? cropName, double price, double? prevPrice, double? prevPrevPrice,
|
double price, CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted,
|
||||||
CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted)
|
double? prevPrice = null, double? prevPrevPrice = null) => new (id, harvestId, cropName,
|
||||||
=> new (id, harvestId, cropName, price, prevPrice, prevPrevPrice, cropType,
|
price, prevPrice, prevPrevPrice, cropType, isActual, replenishmentDate, isDeleted);
|
||||||
isActual, replenishmentDate, isDeleted);
|
|
||||||
}
|
}
|
||||||
|
@ -14,51 +14,51 @@ internal class SupplierDataModelsTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel(null, "fio", "email", 10);
|
var supplier = CreateDataModel(null, "Барышев Дмитрий Алексеевич", "email", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
supplier = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "number", 10);
|
supplier = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "a@yandex.ru", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuid()
|
public void IdIsNotGuid()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel("Id", "fio", "email", 10);
|
var supplier = CreateDataModel("Id", "Барышев Дмитрий Алексеевич", "a@yandex.ru", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void FIOIsNullOrEmptyTest()
|
public void FIOIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), null, "email", 10);
|
var supplier = CreateDataModel(Guid.NewGuid().ToString(), null, "a@yandex.ru", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email", 10);
|
supplier = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "a@yandex.ru", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void EmailIsNullOrEmptyTest()
|
public void EmailIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
|
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "Барышев Дмитрий Алексеевич", null, 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, 10);
|
supplier = CreateDataModel(Guid.NewGuid().ToString(), "Барышев Дмитрий Алексеевич", string.Empty, 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void EmailIsIncorrectTest()
|
public void EmailIsIncorrectTest()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "i.ru", 10);
|
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "Барышев Дмитрий Алексеевич", "i.ru", 10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void DiscountIsLessZero()
|
public void DiscountIsLessZero()
|
||||||
{
|
{
|
||||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "email", -10);
|
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "Барышев Дмитрий Алексеевич", "a@yandex.ru", -10);
|
||||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +66,7 @@ internal class SupplierDataModelsTests
|
|||||||
public void AllFieldsAreCorrect()
|
public void AllFieldsAreCorrect()
|
||||||
{
|
{
|
||||||
var id = Guid.NewGuid().ToString();
|
var id = Guid.NewGuid().ToString();
|
||||||
var fio = "fio";
|
var fio = "Барышев Дмитрий Алексеевич";
|
||||||
var email = "senior_pomidor@yandex.ru";
|
var email = "senior_pomidor@yandex.ru";
|
||||||
var discountSize = 10;
|
var discountSize = 10;
|
||||||
var supplier = CreateDataModel(id, fio, email, discountSize);
|
var supplier = CreateDataModel(id, fio, email, discountSize);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user