Удалены ненужные классы
This commit is contained in:
parent
b96a5e32ca
commit
46ced049d2
@ -1,28 +0,0 @@
|
||||
using Carpentry.Extensions;
|
||||
using Carpentry.Exceptions;
|
||||
using Carpentry.Infrastructure;
|
||||
|
||||
namespace Carpentry.DataModels;
|
||||
|
||||
public class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ManufacturerName { get; private set; } = manufacturerName;
|
||||
|
||||
public string? PrevManufacturerName { get; private set; } = prevManufacturerName;
|
||||
|
||||
public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (ManufacturerName.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerName is empty");
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
using Carpentry.Extensions;
|
||||
using Carpentry.Exceptions;
|
||||
using Carpentry.Infrastructure;
|
||||
|
||||
namespace Carpentry.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
using Carpentry.Extensions;
|
||||
using Carpentry.Enums;
|
||||
using Carpentry.Exceptions;
|
||||
using Carpentry.Infrastructure;
|
||||
|
||||
namespace Carpentry.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, string? buyerId, double sum, DiscountType discountType, double discount, bool isCancel, List<SaleProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public string? BuyerId { get; private set; } = buyerId;
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
|
||||
public DiscountType DiscountType { get; private set; } = discountType;
|
||||
|
||||
public double Discount { get; private set; } = discount;
|
||||
|
||||
public bool IsCancel { get; private set; } = isCancel;
|
||||
|
||||
public List<SaleProductDataModel> Products { get; private set; } = products;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (!BuyerId?.IsGuid() ?? !BuyerId?.IsEmpty() ?? false)
|
||||
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
|
||||
|
||||
if (Sum <= 0)
|
||||
throw new ValidationException("Field Sum is less than or equal to 0");
|
||||
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
using Carpentry.Extensions;
|
||||
using Carpentry.Exceptions;
|
||||
using Carpentry.Infrastructure;
|
||||
|
||||
namespace Carpentry.DataModels;
|
||||
|
||||
public class SaleProductDataModel(string saleId, string productId, int count) : IValidation
|
||||
{
|
||||
public string SaleId { get; private set; } = saleId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (SaleId.IsEmpty())
|
||||
throw new ValidationException("Field SaleId is empty");
|
||||
|
||||
if (!SaleId.IsGuid())
|
||||
throw new ValidationException("The value in the field SaleId is not a unique identifier");
|
||||
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace Carpentry.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0,
|
||||
OnSale = 1,
|
||||
RegularCustomer = 2,
|
||||
Certificate = 4
|
||||
}
|
@ -0,0 +1,102 @@
|
||||
using Carpentry.DataModels;
|
||||
using Carpentry.Enums;
|
||||
using Carpentry.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace CarpentryWorkshopTest.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "productName", ProductType.Furniture, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
product = CreateDataModel(string.Empty, "productName", ProductType.Furniture, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("invalid-id", "productName", ProductType.Furniture, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Furniture, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Furniture, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.None, Guid.NewGuid().ToString(), 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.Furniture, null, 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.Furniture, string.Empty, 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.Furniture, "invalid-manufacturer-id", 10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.Furniture, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "productName", ProductType.Furniture, Guid.NewGuid().ToString(), -10.0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "productName";
|
||||
var productType = ProductType.Furniture;
|
||||
var manufacturerId = Guid.NewGuid().ToString();
|
||||
var price = 10.0;
|
||||
var isDeleted = false;
|
||||
|
||||
var product = CreateDataModel(productId, productName, productType, manufacturerId, price, isDeleted);
|
||||
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(product.Id, Is.EqualTo(productId));
|
||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(product.ManufacturerId, Is.EqualTo(manufacturerId));
|
||||
Assert.That(product.Price, Is.EqualTo(price));
|
||||
Assert.That(product.IsDeleted, Is.EqualTo(isDeleted));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? manufacturerId, double price, bool isDeleted) =>
|
||||
new(id, productName, productType, manufacturerId, price, isDeleted);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user