done, но скорее всего будут поправки
This commit is contained in:
parent
79adbb1632
commit
6c7eeaf5fc
@ -9,10 +9,8 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace SeniorPomidorContracts.DataModels;
|
||||
|
||||
public class SupplyHistoryDataModell(string id, string SupplyId) : IValidation
|
||||
public class SupplyHistoryDataModel(string SupplyId) : IValidation
|
||||
{
|
||||
public string Id { get; set; } = id;
|
||||
|
||||
public string SupplyId { get; private set; } = SupplyId;
|
||||
|
||||
public DateTime SupplyDate { get; private set; } = DateTime.UtcNow;
|
||||
|
@ -1,6 +1,7 @@
|
||||
using SeniorPomidorContracts.DataModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
@ -13,8 +14,70 @@ internal class SupplierDataModelsTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(null, Guid.NewGuid().ToString(), "number", 10);
|
||||
var supplier = CreateDataModel(null, "fio", "number", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplier = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "number", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuid()
|
||||
{
|
||||
var supplier = CreateDataModel("Id", "fio", "number", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), null, "number", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777", 10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DiscountIsLessZero()
|
||||
{
|
||||
var supplier = CreateDataModel(Guid.NewGuid().ToString(), "fio", "number", -10);
|
||||
Assert.That(() => supplier.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrect()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var phoneNum = "+7-777-777-77-77";
|
||||
var discountSize = 10;
|
||||
var supplier = CreateDataModel(id, fio, phoneNum, 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.DiscountSize, Is.EqualTo(discountSize));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplierDataModel CreateDataModel(string? id, string? fio,
|
||||
|
@ -0,0 +1,75 @@
|
||||
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 SupplyCropDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCrop = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyCrop = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyIdIsNotGuid()
|
||||
{
|
||||
var supplyCrop = CreateDataModel("supplyId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
public void CropIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplyCrop = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyCrop = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropIdIsNotGuid()
|
||||
{
|
||||
var supplyCrop = CreateDataModel(Guid.NewGuid().ToString(), "CropId", 10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AmountIsLessOrZeroTest()
|
||||
{
|
||||
var supplyCrop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplyCrop = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrect()
|
||||
{
|
||||
var supplyId = Guid.NewGuid().ToString();
|
||||
var cropId = Guid.NewGuid().ToString();
|
||||
var amount = 10;
|
||||
var supplyCrop = CreateDataModel(supplyId, cropId, amount);
|
||||
Assert.That(() => supplyCrop.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplyCrop.SupplyId, Is.EqualTo(supplyId));
|
||||
Assert.That(supplyCrop.CropId, Is.EqualTo(cropId));
|
||||
Assert.That(supplyCrop.Amount, Is.EqualTo(amount));
|
||||
});
|
||||
}
|
||||
|
||||
public static SupplyCropDataModel CreateDataModel(string? supplyId, string? cropId, int amount)
|
||||
=> new(supplyId, cropId, amount);
|
||||
}
|
101
SeniorPomidorTests/DataModelsTests/SupplyDataModelsTests.cs
Normal file
101
SeniorPomidorTests/DataModelsTests/SupplyDataModelsTests.cs
Normal file
@ -0,0 +1,101 @@
|
||||
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 SupplyDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), 10, DateTime.UtcNow, false,
|
||||
CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, DateTime.UtcNow, false,
|
||||
CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var supply = CreateDataModel("Id", Guid.NewGuid().ToString(), 10, DateTime.UtcNow, false,
|
||||
CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplierIdIsNotGuidTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(),"SupplierId", 10, DateTime.UtcNow, false,
|
||||
CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0,
|
||||
DateTime.UtcNow, false, CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10,
|
||||
DateTime.UtcNow, false, CreateSubDataModel(), DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CropsIsNullOrEmptyTest()
|
||||
{
|
||||
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,
|
||||
DateTime.UtcNow, false, null, DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,
|
||||
DateTime.UtcNow, false, [], DiscountType.OnSale, 10);
|
||||
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrect()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var supplierId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var supplyDate = DateTime.UtcNow.AddDays(-1);
|
||||
var isCancel = false;
|
||||
var crops = CreateSubDataModel();
|
||||
var discountType = DiscountType.OnSale;
|
||||
var discount = 10;
|
||||
var supply = CreateDataModel(id, supplierId, sum, supplyDate,
|
||||
isCancel, crops, discountType, discount);
|
||||
Assert.That(() => supply.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supply.Id, Is.EqualTo(id));
|
||||
Assert.That(supply.SupplierId, Is.EqualTo(supplierId));
|
||||
Assert.That(supply.Sum, Is.EqualTo(sum));
|
||||
Assert.That(supply.SupplyDate, Is.EqualTo(supplyDate));
|
||||
Assert.That(supply.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(supply.Crops, Is.EquivalentTo(crops));
|
||||
Assert.That(supply.DiscountType, Is.EqualTo(discountType));
|
||||
Assert.That(supply.Discount, Is.EqualTo(discount));
|
||||
});
|
||||
}
|
||||
|
||||
private static SupplyDataModel CreateDataModel(string? id, string? supplierId, int sum,
|
||||
DateTime supplyDate, bool isCancel, List<SupplyCropDataModel>? crops, DiscountType discountType,
|
||||
double discount) => new(id, supplierId, sum, supplyDate, isCancel, crops, discountType, discount);
|
||||
|
||||
private static List<SupplyCropDataModel> CreateSubDataModel() =>
|
||||
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)];
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
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