done
This commit is contained in:
parent
6c7eeaf5fc
commit
2adcba7625
@ -13,7 +13,8 @@ using System.Xml;
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class CropDataModel(string id, string harvestId, string cropName, double price,
|
||||
CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted) : IValidation
|
||||
double? prevPrice, double? prevPrevPrice, CropType cropType, bool isActual,
|
||||
DateTime replenishmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -23,6 +24,10 @@ public class CropDataModel(string id, string harvestId, string cropName, double
|
||||
|
||||
public double Price { get; private set; } = price;
|
||||
|
||||
public double? PrevPrice { get; private set; } = prevPrice;
|
||||
|
||||
public double? PrevPrevPrice { get; private set; } = prevPrevPrice;
|
||||
|
||||
public CropType CropType { get; private set; } = cropType;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
@ -9,8 +9,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class HarvestDataModel(string id, string cropId, string harvestName
|
||||
/*, string? prevHarvestName, string? prevPrevHarvestName*/, int harvestAmount) : IValidation
|
||||
public class HarvestDataModel(string id, string cropId, string harvestName, int harvestAmount) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -18,10 +17,6 @@ public class HarvestDataModel(string id, string cropId, string harvestName
|
||||
|
||||
public string HarvestName { get; private set; } = harvestName;
|
||||
|
||||
//public string prevHarvestName { get; private set; } = prevHarvestName;
|
||||
|
||||
//public string prevPrevHarvestName { get; private set; }= prevPrevHarvestName;
|
||||
|
||||
public int HarvestAmount { get; private set; } = harvestAmount;
|
||||
|
||||
public void Validate()
|
||||
|
@ -13,13 +13,13 @@ using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplierDataModel(string id, string fio, string phoneNumber, double discountSize) : IValidation
|
||||
public class SupplierDataModel(string id, string fio, string email, double discountSize) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
public string Email { get; private set; } = email;
|
||||
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
@ -34,13 +34,13 @@ public class SupplierDataModel(string id, string fio, string phoneNumber, double
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (PhoneNumber.IsEmpty())
|
||||
throw new ValidationException("Field PhoneNumber is empty");
|
||||
if (Email.IsEmpty())
|
||||
throw new ValidationException("Field Email is empty");
|
||||
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
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");
|
||||
|
||||
if (DiscountSize < 0)
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
throw new ValidationException("Field DiscountSize is less than zero");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplierHistoryDataModel(string supplierId, string oldName) : IValidation
|
||||
{
|
||||
public string SupplierId { get; private set; } = supplierId;
|
||||
|
||||
public string OldName { get; private set; } = oldName;
|
||||
|
||||
public DateTime ChangeTime { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplierId.IsEmpty())
|
||||
throw new ValidationException("Field SupplierId is empty");
|
||||
|
||||
if (!SupplierId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplierId is not a unique identifier");
|
||||
|
||||
if (OldName.IsEmpty())
|
||||
throw new ValidationException("Field OldName is empty");
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using SeniorPomidorContracts.Extensions;
|
||||
using SeniorPomidorContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplyHistoryDataModel(string SupplyId) : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; } = SupplyId;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SupplyId.IsEmpty())
|
||||
throw new ValidationException("Field SupplyId is empty");
|
||||
|
||||
if (!SupplyId.IsGuid())
|
||||
throw new ValidationException("The value in the field SupplyId is not a unique identifier");
|
||||
}
|
||||
}
|
@ -16,11 +16,11 @@ internal class CropDataModelsTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var crop = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
crop = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -28,18 +28,18 @@ internal class CropDataModelsTests
|
||||
public void IdIsNotGuid()
|
||||
{
|
||||
var crop = CreateDataModel("Id", Guid.NewGuid().ToString(), "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
public void HarvestIdIsNullOrEmptyTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
crop = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -47,7 +47,7 @@ internal class CropDataModelsTests
|
||||
public void HarvestIdIsNotGuid()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), "Id", "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ internal class CropDataModelsTests
|
||||
public void CropNameIsEmptyTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -63,11 +63,11 @@ internal class CropDataModelsTests
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||
0, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
0, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||
-10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
-10, 9, 8, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -75,7 +75,7 @@ internal class CropDataModelsTests
|
||||
public void CropTypeIsNoneTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||
10, CropType.None, true, DateTime.UtcNow, false);
|
||||
10, 9, 8, CropType.None, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -86,12 +86,14 @@ internal class CropDataModelsTests
|
||||
var harvestId = Guid.NewGuid().ToString();
|
||||
var cropName = "name";
|
||||
var price = 10;
|
||||
var prevPrice = 9;
|
||||
var prevPrevPrice = 8;
|
||||
var cropType = CropType.Berry;
|
||||
var isActual = true;
|
||||
var replenishmentDate = DateTime.UtcNow.AddDays(-1);
|
||||
var isDeleted = false;
|
||||
var crop = CreateDataModel(cropId, harvestId, cropName, price,
|
||||
cropType, isActual, replenishmentDate, isDeleted);
|
||||
var crop = CreateDataModel(cropId, harvestId, cropName, price, prevPrice,
|
||||
prevPrevPrice, cropType, isActual, replenishmentDate, isDeleted);
|
||||
|
||||
Assert.That(() => crop.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
@ -101,13 +103,17 @@ internal class CropDataModelsTests
|
||||
Assert.That(crop.CropName, Is.EqualTo(cropName));
|
||||
Assert.That(crop.CropType, Is.EqualTo(cropType));
|
||||
Assert.That(crop.Price, Is.EqualTo(price));
|
||||
Assert.That(crop.PrevPrice, Is.EqualTo(prevPrice));
|
||||
Assert.That(crop.PrevPrevPrice, Is.EqualTo(prevPrevPrice));
|
||||
Assert.That(crop.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(crop.ReplenishmentDate, Is.EqualTo(replenishmentDate));
|
||||
Assert.That(crop.IsDeleted, Is.EqualTo(isDeleted));
|
||||
});
|
||||
}
|
||||
|
||||
private static CropDataModel CreateDataModel(string? id, string? harvestId, string? cropName,
|
||||
double price, CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted) => new (id, harvestId,
|
||||
cropName, price, cropType, isActual, replenishmentDate, isDeleted);
|
||||
private static CropDataModel CreateDataModel(string? id, string? harvestId,
|
||||
string? cropName, double price, double? prevPrice, double? prevPrevPrice,
|
||||
CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted)
|
||||
=> new (id, harvestId, cropName, price, prevPrice, prevPrevPrice, cropType,
|
||||
isActual, replenishmentDate, isDeleted);
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ internal class SupplierDataModelsTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(null, "fio", "number", 10);
|
||||
var supplier = CreateDataModel(null, "fio", "email", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplier = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "number", 10);
|
||||
@ -24,22 +24,22 @@ internal class SupplierDataModelsTests
|
||||
[Test]
|
||||
public void IdIsNotGuid()
|
||||
{
|
||||
var supplier = CreateDataModel("Id", "fio", "number", 10);
|
||||
var supplier = CreateDataModel("Id", "fio", "email", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), null, "number", 10);
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), null, "email", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", 10);
|
||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
public void EmailIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
@ -49,16 +49,16 @@ internal class SupplierDataModelsTests
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
public void EmailIsIncorrectTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777", 10);
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "i.ru", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiscountIsLessZero()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "number", -10);
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "email", -10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
@ -67,15 +67,15 @@ internal class SupplierDataModelsTests
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var phoneNum = "+7-777-777-77-77";
|
||||
var email = "senior_pomidor@yandex.ru";
|
||||
var discountSize = 10;
|
||||
var supplier = CreateDataModel(id, fio, phoneNum, discountSize);
|
||||
var supplier = CreateDataModel(id, fio, email, discountSize);
|
||||
Assert.That(() => supplier.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplier.Id, Is.EqualTo(id));
|
||||
Assert.That(supplier.FIO, Is.EqualTo(fio));
|
||||
Assert.That(supplier.PhoneNumber, Is.EqualTo(phoneNum));
|
||||
Assert.That(supplier.Email, Is.EqualTo(email));
|
||||
Assert.That(supplier.DiscountSize, Is.EqualTo(discountSize));
|
||||
});
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplierHistoryDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void SuppplierIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplierHistory = CreateDataModel(null, "name");
|
||||
Assert.That(() => supplierHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplierHistory = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => supplierHistory.Validate(),Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppplierIdIsNotGuid()
|
||||
{
|
||||
var supplierHistory = CreateDataModel("Id", "name");
|
||||
Assert.That(() => supplierHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
public void OldNameNullOrEmptyTest()
|
||||
{
|
||||
var supplierHistory = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => supplierHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplierHistory = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => supplierHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplierId = Guid.NewGuid().ToString();
|
||||
var oldName = "Name";
|
||||
var supplyHistory = CreateDataModel(supplierId, oldName);
|
||||
Assert.That(() => supplyHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyHistory.SupplierId, Is.EqualTo(supplierId));
|
||||
Assert.That(supplyHistory.OldName, Is.EqualTo(oldName));
|
||||
Assert.That(supplyHistory.ChangeTime, Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(supplyHistory.ChangeTime, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplierHistoryDataModel CreateDataModel(string? supplierId,
|
||||
string? oldName) => new(supplierId, oldName);
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplyHistoryDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void SuppplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyHistory = CreateDataModel(null);
|
||||
Assert.That(() => supplyHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyHistory = CreateDataModel(string.Empty);
|
||||
Assert.That(() => supplyHistory.Validate(),Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppplyIdIsNotGuid()
|
||||
{
|
||||
var supplyHistory = CreateDataModel("Id");
|
||||
Assert.That(() => supplyHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var supplyHistory = CreateDataModel(supplyId);
|
||||
Assert.That(() => supplyHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyHistory.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(supplyHistory.SupplyDate, Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(supplyHistory.SupplyDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyHistoryDataModel CreateDataModel(string? supplyId) => new(supplyId);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user