почти все тесты сделаны, осталось чуть чуть
This commit is contained in:
parent
37d7ce8c25
commit
79adbb1632
@ -12,8 +12,8 @@ using System.Xml;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class CropDataModell(string id, string harvestId, string cropName, double price,
|
||||
CropType cropType, bool isActual, DateTime replenishmentDate) : IValidation
|
||||
public class CropDataModel(string id, string harvestId, string cropName, double price,
|
||||
CropType cropType, bool isActual, DateTime replenishmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
@ -29,6 +29,8 @@ public class CropDataModell(string id, string harvestId, string cropName, double
|
||||
|
||||
public DateTime ReplenishmentDate { get; private set; } = replenishmentDate;
|
||||
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
|
@ -9,11 +9,13 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class HarvestDataModel(string id, string harvestName
|
||||
public class HarvestDataModel(string id, string cropId, string harvestName
|
||||
/*, string? prevHarvestName, string? prevPrevHarvestName*/, int harvestAmount) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string CropId { get; private set; } = cropId;
|
||||
|
||||
public string HarvestName { get; private set; } = harvestName;
|
||||
|
||||
//public string prevHarvestName { get; private set; } = prevHarvestName;
|
||||
@ -27,9 +29,15 @@ public class HarvestDataModel(string id, string harvestName
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (Id.IsGuid())
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (CropId.IsEmpty())
|
||||
throw new ValidationException("Field CropId is empty");
|
||||
|
||||
if (!CropId.IsGuid())
|
||||
throw new ValidationException("The value in the field CropId is not a unique identifier");
|
||||
|
||||
if (HarvestName.IsEmpty())
|
||||
throw new ValidationException("Field HarvestName is empty");
|
||||
|
||||
|
@ -38,6 +38,9 @@ public class SupplierDataModel(string id, string fio, string phoneNumber, double
|
||||
throw new ValidationException("Field PhoneNumber is empty");
|
||||
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
|
||||
if (DiscountSize < 0)
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
}
|
||||
}
|
||||
|
113
SeniorPomidorTests/DataModelsTests/CropDataModelsTests.cs
Normal file
113
SeniorPomidorTests/DataModelsTests/CropDataModelsTests.cs
Normal file
@ -0,0 +1,113 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using SeniorPomidorContracts.Enums;
|
||||
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 CropDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var crop = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
||||
10, 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);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuid()
|
||||
{
|
||||
var crop = CreateDataModel("Id", Guid.NewGuid().ToString(), "name",
|
||||
10, 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);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
crop = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarvestIdIsNotGuid()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), "Id", "name",
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropNameIsEmptyTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
||||
10, CropType.Berry, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||
0, 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);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropTypeIsNoneTest()
|
||||
{
|
||||
var crop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name",
|
||||
10, CropType.None, true, DateTime.UtcNow, false);
|
||||
Assert.That(() => crop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var cropId = Guid.NewGuid().ToString();
|
||||
var harvestId = Guid.NewGuid().ToString();
|
||||
var cropName = "name";
|
||||
var price = 10;
|
||||
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);
|
||||
|
||||
Assert.That(() => crop.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(crop.Id, Is.EqualTo(cropId));
|
||||
Assert.That(crop.HarvestId, Is.EqualTo(harvestId));
|
||||
Assert.That(crop.CropName, Is.EqualTo(cropName));
|
||||
Assert.That(crop.CropType, Is.EqualTo(cropType));
|
||||
Assert.That(crop.Price, Is.EqualTo(price));
|
||||
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);
|
||||
}
|
85
SeniorPomidorTests/DataModelsTests/HarvestDataModelsTests.cs
Normal file
85
SeniorPomidorTests/DataModelsTests/HarvestDataModelsTests.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using SeniorPomidorContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class HarvestDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var harvest = CreateDataModel(null, Guid.NewGuid().ToString(), "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
harvest = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuid()
|
||||
{
|
||||
var harvest = CreateDataModel("Id", Guid.NewGuid().ToString(), "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropIdIsNullOrEmptyTest()
|
||||
{
|
||||
var harvest = CreateDataModel(Guid.NewGuid().ToString(), null, "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
harvest = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropIdIsNotGuid()
|
||||
{
|
||||
var harvest = CreateDataModel(Guid.NewGuid().ToString(), "CropId", "name", 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void HarvestNameIsEmptyTest()
|
||||
{
|
||||
var harvest = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AmountIsLessZero()
|
||||
{
|
||||
var harvest = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", -10);
|
||||
Assert.That(() => harvest.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrect()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var cropId = Guid.NewGuid().ToString();
|
||||
var harvestName = "name";
|
||||
var harvestAmount = 10;
|
||||
var harvest = CreateDataModel(id, cropId, harvestName, harvestAmount);
|
||||
|
||||
Assert.That(() => harvest.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(harvest.Id, Is.EqualTo(id));
|
||||
Assert.That(harvest.CropId, Is.EqualTo(cropId));
|
||||
Assert.That(harvest.HarvestName, Is.EqualTo(harvestName));
|
||||
Assert.That(harvest.HarvestAmount, Is.EqualTo(harvestAmount));
|
||||
});
|
||||
}
|
||||
|
||||
private static HarvestDataModel CreateDataModel(string? id, string? cropId,
|
||||
string? harvestName, int harvestAmount) => new(id, cropId, harvestName, harvestAmount);
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SupplierDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(null, Guid.NewGuid().ToString(), "number", 10);
|
||||
|
||||
}
|
||||
|
||||
private static SupplierDataModel CreateDataModel(string? id, string? fio,
|
||||
string? phoneNumber, int discountSize) => new(id, fio, phoneNumber, discountSize);
|
||||
}
|
@ -25,8 +25,4 @@
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DataModelsTests\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
x
Reference in New Issue
Block a user