Compare commits
2 Commits
main
...
Task_1_Mod
Author | SHA1 | Date | |
---|---|---|---|
|
41cadf234c | ||
|
b5478a62ef |
@ -1,7 +0,0 @@
|
||||
namespace SquirrelBarContracts
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Numerics;
|
||||
using System.Text.RegularExpressions;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace SquirrelBarContracts.DataModels;
|
||||
|
||||
public class BuyerDataModel(string id, string fio,DateTime birthDate,string phoneNumber, int drinksBought, double discountSize) : IValidation
|
||||
{
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
public int DrinksBought { get; private set; } = drinksBought;
|
||||
public double DiscountSize { get; private set; } = discountSize;
|
||||
|
||||
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 (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
if (!Regex.IsMatch(FIO, @"^([А-ЯЁ][а-яё]*(-[А-ЯЁ][а-яё]*)?)\s([А-ЯЁ]\.?\s?([А-ЯЁ]\.?\s?)?)?$"))
|
||||
throw new ValidationException("Field FIO is not a fio");
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-18).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
if (PhoneNumber.IsEmpty()) 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");
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarContracts.DataModels;
|
||||
|
||||
public class ClientDiscountDataModel(string? buyerId, double totalSum, double personalDiscount) : IValidation
|
||||
{
|
||||
public string? BuyerId { get; private set; } = buyerId;
|
||||
public double TotalSum { get; private set; } = totalSum;
|
||||
public double PersonalDiscount { get; private set; } = personalDiscount;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (BuyerId.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
if (!BuyerId.IsGuid())
|
||||
throw new ValidationException("The value in the field Id 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 (TotalSum < 0)
|
||||
throw new ValidationException("Field Sum is less than 0");
|
||||
if (PersonalDiscount < 0)
|
||||
throw new ValidationException("Field PersonalDiscount is less than 0");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
using SquirrelBarContracts.Enums;
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarContracts.DataModels;
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string PostId { get; private set; } = postId;
|
||||
public string PostName { get; private set; } = postName;
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
public double Salary { get; private set; } = salary;
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
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 (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
using SquirrelBarContracts.Enums;
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Xml;
|
||||
|
||||
namespace SquirrelBarContracts.DataModels;
|
||||
|
||||
public class ProductDataModel(string id, string productName, ProductType productType, string SupplierId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ProductName { get; private set; } = productName;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public string SupplierId { get; private set; } = SupplierId;
|
||||
public double Price { get; private set; } = price;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
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 (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
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 (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarContracts.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
using SquirrelBarContracts.Enums;
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Xml;
|
||||
|
||||
namespace SquirrelBarContracts.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");
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarContracts.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");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,40 @@
|
||||
using SquirrelBarContracts.Extensions;
|
||||
using SquirrelBarContracts.Infrastructure;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Xml;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SquirrelBarContracts.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PostId { get; private set; } = postId;
|
||||
public DateTime BirthDate { get; private set; } = birthDate;
|
||||
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||
public bool IsDeleted { get; private set; } = isDeleted;
|
||||
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 (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
if (!Regex.IsMatch(FIO, @"^([А-ЯЁ][а-яё]*(-[А-ЯЁ][а-яё]*)?)\s([А-ЯЁ]\.?\s?([А-ЯЁ]\.?\s?)?)?$"))
|
||||
throw new ValidationException("Field FIO is not a fio");
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
|
||||
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||
if (EmploymentDate.Date < BirthDate.Date)
|
||||
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16) // EmploymentDate.Year - BirthDate.Year;
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
namespace SquirrelBarContracts.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0,
|
||||
OnSale = 1,
|
||||
RegularCustomer = 2,
|
||||
Certificate = 4
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SquirrelBarContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Barman = 1,
|
||||
Administrator = 2,
|
||||
Waiter = 3
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
namespace SquirrelBarContracts.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Food = 1,
|
||||
AlcoholDrinks = 2,
|
||||
NonAlcoholDrinks = 3,
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
namespace SquirrelBarContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
namespace SquirrelBarContracts.Extensions;
|
||||
|
||||
public static class StringExtensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
namespace SquirrelBarContracts.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
@ -5,6 +5,8 @@ VisualStudioVersion = 17.12.35707.178 d17.12
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SquirrelBarContracts", "SquirrelBarContracts\SquirrelBarContracts.csproj", "{1836A936-AA20-4D13-9855-6E3364AE958E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SquirrelBarTests", "SquirrelBarTests\SquirrelBarTests.csproj", "{DC10787F-93C9-4033-A50A-9113E080CDAA}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{1836A936-AA20-4D13-9855-6E3364AE958E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1836A936-AA20-4D13-9855-6E3364AE958E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1836A936-AA20-4D13-9855-6E3364AE958E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC10787F-93C9-4033-A50A-9113E080CDAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC10787F-93C9-4033-A50A-9113E080CDAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC10787F-93C9-4033-A50A-9113E080CDAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC10787F-93C9-4033-A50A-9113E080CDAA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
@ -0,0 +1,92 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
[TestFixture]
|
||||
internal class BuyerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(null, "Иванов И.И.", DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(string.Empty, "Иванов И.И.", DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var model = CreateDataModel("not a guid", "Иванов И.И.", DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FioIsNullOrEmptyTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FioIsNotCorrectTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов", DateTime.Now.AddYears(-20), "number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", DateTime.Now.AddYears(-20), null, 10, 15);
|
||||
Assert.That(() => buyer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", DateTime.Now.AddYears(-20), string.Empty, 10, 15);
|
||||
Assert.That(() => buyer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", DateTime.Now.AddYears(-20), "7777", 10, 15);
|
||||
Assert.That(() => buyer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsFutureTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "fio", DateTime.Now.AddYears(-14).AddDays(1),"number", 10, 15);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var fio = "Иванов И.И.";
|
||||
var birthDate = DateTime.Now.AddYears(-20);
|
||||
var phoneNumber = "+7-777-777-77-77";
|
||||
var drinksBought = 2;
|
||||
var discountSize = 11;
|
||||
var model = CreateDataModel(id, fio, birthDate, phoneNumber, drinksBought, discountSize);
|
||||
Assert.That(() => model.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(model.Id, Is.EqualTo(id));
|
||||
Assert.That(model.FIO, Is.EqualTo(fio));
|
||||
Assert.That(model.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(model.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||
Assert.That(model.DrinksBought, Is.EqualTo(drinksBought));
|
||||
Assert.That(model.DiscountSize, Is.EqualTo(discountSize));
|
||||
});
|
||||
}
|
||||
|
||||
private static BuyerDataModel CreateDataModel(string? id, string? fio, DateTime birthDate, string? phoneNumber, int drinksBought, double discountSize)
|
||||
=> new(id, fio, birthDate, phoneNumber, drinksBought, discountSize);
|
||||
}
|
@ -0,0 +1,60 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ClientDiscountDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void BuyerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, 100,10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, 100,10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", 100,10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void personalDiscountIsLessThenZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), -100, 10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TotalSumIsLessThenZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), -100, 10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var totalSum = 100;
|
||||
var personalDiscount = 10;
|
||||
var clientDiscount = CreateDataModel(buyerId, totalSum, personalDiscount);
|
||||
Assert.That(() => clientDiscount.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(clientDiscount.BuyerId, Is.EqualTo(buyerId));
|
||||
Assert.That(clientDiscount.TotalSum, Is.EqualTo(totalSum));
|
||||
Assert.That(clientDiscount.PersonalDiscount, Is.EqualTo(personalDiscount));
|
||||
|
||||
});
|
||||
}
|
||||
private static ClientDiscountDataModel CreateDataModel(string? buyerId, double totalSum, double personalDiscount) =>
|
||||
new(buyerId, totalSum, personalDiscount);
|
||||
}
|
@ -0,0 +1,111 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using SquirrelBarContracts.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
||||
PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||
"name", PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name",
|
||||
PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
||||
PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
"name", PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId",
|
||||
"name", PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), null, PostType.Barman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), string.Empty, PostType.Barman, 10, true,
|
||||
DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "name", PostType.Barman, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "name", PostType.Barman, -10, true,
|
||||
DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Barman;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postPostId, postName, postType,
|
||||
salary, isActual, changeDate);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
Assert.That(post.PostId, Is.EqualTo(postPostId));
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
private static PostDataModel CreateDataModel(string? id, string? postId,
|
||||
string? postName, PostType postType, double salary, bool isActual, DateTime
|
||||
changeDate) => new(id, postId, postName, postType, salary, isActual, changeDate);
|
||||
}
|
@ -0,0 +1,104 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using SquirrelBarContracts.Enums;
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
ProductType.None, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ManufacturerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.AlcoholDrinks, null, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.AlcoholDrinks, string.Empty, 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ManufacturerIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.AlcoholDrinks, "supplierId", 10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.AlcoholDrinks, Guid.NewGuid().ToString(), -10, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.AlcoholDrinks;
|
||||
var productSupplierId = Guid.NewGuid().ToString();
|
||||
var productPrice = 10;
|
||||
var productIsDelete = false;
|
||||
var product = CreateDataModel(productId, productName, productType,
|
||||
productSupplierId, productPrice, productIsDelete);
|
||||
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.SupplierId, Is.EqualTo(productSupplierId));
|
||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
|
||||
});
|
||||
}
|
||||
private static ProductDataModel CreateDataModel(string? id, string?
|
||||
productName, ProductType productType, string? supplierId, double price, bool
|
||||
isDeleted) =>
|
||||
new(id, productName, productType, supplierId, price, isDeleted);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, 10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", 10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var productHistory = CreateDataModel(productId, oldPrice);
|
||||
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(productHistory.ChangeDate,
|
||||
Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(productHistory.ChangeDate,
|
||||
Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
private static ProductHistoryDataModel CreateDataModel(string? productId,
|
||||
double oldPrice) =>
|
||||
new(productId, oldPrice);
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using SquirrelBarContracts.Enums;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SaleDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId",
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void BuyerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "buyerId", 10, DiscountType.OnSale, 10, false,
|
||||
CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.OnSale, 10,
|
||||
false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.OnSale,
|
||||
10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale,
|
||||
10, false, null);
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale,
|
||||
10, false, []);
|
||||
Assert.That(() => sale.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var discountType = DiscountType.Certificate;
|
||||
var discount = 1;
|
||||
var isCancel = true;
|
||||
var products = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, workerId, buyerId, sum,
|
||||
discountType, discount, isCancel, products);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(sale.BuyerId, Is.EqualTo(buyerId));
|
||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.DiscountType, Is.EqualTo(discountType));
|
||||
Assert.That(sale.Discount, Is.EqualTo(discount));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
private static SaleDataModel CreateDataModel(string? id, string? workerId,
|
||||
string? buyerId, double sum, DiscountType discountType, double discount, bool
|
||||
isCancel, List<SaleProductDataModel>? products) =>
|
||||
new(id, workerId, buyerId, sum, discountType, discount, isCancel,
|
||||
products);
|
||||
private static List<SaleProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
[TestFixture]
|
||||
internal class SaleProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SaleIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||
10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(string.Empty,
|
||||
Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void SaleIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel("saleId",
|
||||
Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(string.Empty,
|
||||
Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
"productId", 10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => saleProduct.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var saleProduct = CreateDataModel(saleId, productId, count);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleProduct.SaleId, Is.EqualTo(saleId));
|
||||
Assert.That(saleProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
private static SaleProductDataModel CreateDataModel(string? saleId, string?
|
||||
productId, int count) =>
|
||||
new(saleId, productId, count);
|
||||
}
|
||||
|
@ -0,0 +1,117 @@
|
||||
using SquirrelBarContracts.DataModels;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace SquirrelBarTests.DataModelsTests;
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FioIsNotCorrectTest()
|
||||
{
|
||||
var model = CreateDataModel(Guid.NewGuid().ToString(), "Иванов", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now, false);
|
||||
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
"postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now,
|
||||
false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-
|
||||
18).AddDays(-1), false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-
|
||||
16), false);
|
||||
Assert.That(() => worker.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var fio = "Иванов И. И.";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var worker = CreateDataModel(workerId, fio, postId, birthDate,
|
||||
employmentDate, isDelete);
|
||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(worker.Id, Is.EqualTo(workerId));
|
||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||
Assert.That(worker.PostId, Is.EqualTo(postId));
|
||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(worker.EmploymentDate,
|
||||
Is.EqualTo(employmentDate));
|
||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
private static WorkerDataModel CreateDataModel(string? id, string? fio,
|
||||
string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<LangVersion>latest</LangVersion>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SquirrelBarContracts\SquirrelBarContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user