Первая лаба
This commit is contained in:
@@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35527.113 d17.12
|
||||
VisualStudioVersion = 17.12.35527.113
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheBlacksmithVakulaContract", "TheBlacksmithVakulaContract\TheBlacksmithVakulaContract.csproj", "{90D2CF98-6233-4E14-879D-6A618F782FE2}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheBlacksmithVakulaTests", "TheBlacksmithVakulaTests\TheBlacksmithVakulaTests.csproj", "{E713C757-C913-43D7-AC6C-F146E676EECF}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{90D2CF98-6233-4E14-879D-6A618F782FE2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{90D2CF98-6233-4E14-879D-6A618F782FE2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{90D2CF98-6233-4E14-879D-6A618F782FE2}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E713C757-C913-43D7-AC6C-F146E676EECF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E713C757-C913-43D7-AC6C-F146E676EECF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E713C757-C913-43D7-AC6C-F146E676EECF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E713C757-C913-43D7-AC6C-F146E676EECF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class BilletDataModel(string id, string billetName, string prevBilletName, string prevPrevBilletName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string BilletName { get; private set; } = billetName;
|
||||
|
||||
public string PrevBilletName { get; private set; } = prevBilletName;
|
||||
|
||||
public string PrevPrevBilletName { get; private set; } = prevPrevBilletName;
|
||||
|
||||
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 (BilletName.IsEmpty())
|
||||
throw new ValidationException("Field BilletName is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class BlacksmithDataModel(string id, string fio, string rankId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string RankId { get; private set; } = rankId;
|
||||
|
||||
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 (RankId.IsEmpty())
|
||||
throw new ValidationException("Field RankId is empty");
|
||||
if (!RankId.IsGuid())
|
||||
throw new ValidationException("The value in the field RankId 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)
|
||||
throw new ValidationException($"Minors cannot be (EmploymentDate - { EmploymentDate.ToShortDateString() }," +
|
||||
$" BirthDate - { BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class BuyerDataModel(string id, string fio, string phoneNumber, 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 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 (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,48 @@
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class OrderDataModel(string id, string blacksmithId, string? buyerId, double sum, DiscountType discountType,
|
||||
double discount, bool isCancel, List<OrderProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string BlacksmithId { get; private set; } = blacksmithId;
|
||||
|
||||
public string? BuyerId { get; private set; } = buyerId;
|
||||
|
||||
public DateTime OrderDate { 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<OrderProductDataModel> 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 (BlacksmithId.IsEmpty())
|
||||
throw new ValidationException("Field BlacksmithId is empty");
|
||||
if (!BlacksmithId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlacksmithId 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,29 @@
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class OrderProductDataModel(string orderId, string productId, int count) : IValidation
|
||||
{
|
||||
public string OrderId { get; private set; } = orderId;
|
||||
|
||||
public string ProductId { get; private set; } = productId;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (OrderId.IsEmpty())
|
||||
throw new ValidationException("Field OrderId is empty");
|
||||
if (!OrderId.IsGuid())
|
||||
throw new ValidationException("The value in the field OrderId 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,41 @@
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class ProductDataModel(string id, string productName, ProductType productType,
|
||||
string billetId, 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 BilletId { get; private set; } = billetId;
|
||||
|
||||
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 (BilletId.IsEmpty())
|
||||
throw new ValidationException("Field BilletId is empty");
|
||||
if (!BilletId.IsGuid())
|
||||
throw new ValidationException("The value in the field BilletId is not a unique identifier");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.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 Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class RankDataModel(string id, string rankId, string rankName, RankType rankType, bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string RankId { get; private set; } = rankId;
|
||||
|
||||
public string RankName { get; private set; } = rankName;
|
||||
|
||||
public RankType RankType { get; private set; } = rankType;
|
||||
|
||||
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 (RankId.IsEmpty())
|
||||
throw new ValidationException("Field RankId is empty");
|
||||
if (!RankId.IsGuid())
|
||||
throw new ValidationException("The value in the field RankId is not a unique identifier");
|
||||
if (RankName.IsEmpty())
|
||||
throw new ValidationException("Field RankName is empty");
|
||||
if (RankType == RankType.None)
|
||||
throw new ValidationException("Field RankType is empty");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
using TheBlacksmithVakulaContract.Extensions;
|
||||
using TheBlacksmithVakulaContract.Infrastructure;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.DataModels
|
||||
{
|
||||
public class SalaryDataModel(string blacksmithId, DateTime salaryDate, double salary) : IValidation
|
||||
{
|
||||
public string BlacksmithId { get; private set; } = blacksmithId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (BlacksmithId.IsEmpty())
|
||||
throw new ValidationException("Field BlacksmithId is empty");
|
||||
if (!BlacksmithId.IsGuid())
|
||||
throw new ValidationException("The value in the field BlacksmithId is not a unique identifier");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace TheBlacksmithVakulaContract.Enums
|
||||
{
|
||||
[Flags]
|
||||
public enum DiscountType
|
||||
{
|
||||
None = 0,
|
||||
OnSale = 1,
|
||||
RegularCustomer = 2,
|
||||
Certificate = 4
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace TheBlacksmithVakulaContract.Enums
|
||||
{
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Tool = 1,
|
||||
Weapon = 2,
|
||||
Jewel = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace TheBlacksmithVakulaContract.Enums
|
||||
{
|
||||
public enum RankType
|
||||
{
|
||||
None = 0,
|
||||
Student = 1,
|
||||
Expert = 2,
|
||||
Master = 3
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace TheBlacksmithVakulaContract.Exceptions
|
||||
{
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TheBlacksmithVakulaContract.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,7 @@
|
||||
namespace TheBlacksmithVakulaContract.Infrastructure
|
||||
{
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BilletDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var billet = CreateDataModel(null, "name");
|
||||
Assert.That(() => billet.Validate(), Throws.TypeOf<ValidationException>());
|
||||
billet = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => billet.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var billet = CreateDataModel("id", "name");
|
||||
Assert.That(() => billet.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BilletNameIsNullOrEmptyTest()
|
||||
{
|
||||
var billet = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => billet.Validate(), Throws.TypeOf<ValidationException>());
|
||||
billet = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => billet.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var billetId = Guid.NewGuid().ToString();
|
||||
var billetName = "name";
|
||||
var prevBilletName = "prevManufacturerName";
|
||||
var prevPrevBilletName = "prevPrevManufacturerName";
|
||||
var billet = CreateDataModel(billetId, billetName, prevBilletName, prevPrevBilletName);
|
||||
Assert.That(() => billet.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(billet.Id, Is.EqualTo(billetId));
|
||||
Assert.That(billet.BilletName, Is.EqualTo(billetName));
|
||||
Assert.That(billet.PrevBilletName, Is.EqualTo(prevBilletName));
|
||||
Assert.That(billet.PrevPrevBilletName, Is.EqualTo(prevPrevBilletName));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static BilletDataModel CreateDataModel(string? id, string? billetName, string? prevBilletName = null, string? prevPrevBilletName = null) =>
|
||||
new(id, billetName, prevBilletName, prevPrevBilletName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BlacksmithDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(null, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blacksmith = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel("id", "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blacksmith = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankIdIsNullOrEmptyTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankIdIsNotGuidTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
"rankId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-
|
||||
18).AddDays(-1), false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
blacksmith = CreateDataModel(Guid.NewGuid().ToString(), "fio",
|
||||
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-
|
||||
16), false);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var rankId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var blacksmith = CreateDataModel(id, fio, rankId, birthDate, employmentDate, isDelete);
|
||||
Assert.That(() => blacksmith.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(blacksmith.Id, Is.EqualTo(id));
|
||||
Assert.That(blacksmith.FIO, Is.EqualTo(fio));
|
||||
Assert.That(blacksmith.RankId, Is.EqualTo(rankId));
|
||||
Assert.That(blacksmith.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(blacksmith.EmploymentDate, Is.EqualTo(employmentDate));
|
||||
Assert.That(blacksmith.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static BlacksmithDataModel CreateDataModel(string? id, string? fio,
|
||||
string? rankId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, rankId, birthDate, employmentDate, isDeleted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class BuyerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(null, "fio", "number", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(string.Empty, "fio", "number", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var buyer = CreateDataModel("id", "fio", "number", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), null, "number", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777", 10);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var fio = "Fio";
|
||||
var phoneNumber = "+7-777-777-77-77";
|
||||
var discountSize = 11;
|
||||
var buyer = CreateDataModel(buyerId, fio, phoneNumber, discountSize);
|
||||
Assert.That(() => buyer.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(buyer.Id, Is.EqualTo(buyerId));
|
||||
Assert.That(buyer.FIO, Is.EqualTo(fio));
|
||||
Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||
Assert.That(buyer.DiscountSize, Is.EqualTo(discountSize));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber, double discountSize) =>
|
||||
new(id, fio, phoneNumber, discountSize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class OrderDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var order = CreateDataModel("id", Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlacksmithIdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlacksmithIdIsNotGuidTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), "blacksmithId",
|
||||
Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuyerIdIsNotGuidTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "buyerId", 10, DiscountType.OnSale, 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, DiscountType.OnSale, 10,
|
||||
false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, DiscountType.OnSale,
|
||||
10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, null);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, DiscountType.OnSale, 10, false, []);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var blacksmithId = 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(id, blacksmithId, buyerId, sum,
|
||||
discountType, discount, isCancel, products);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(id));
|
||||
Assert.That(sale.BlacksmithId, Is.EqualTo(blacksmithId));
|
||||
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 OrderDataModel CreateDataModel(string? id, string? blacksmithId,
|
||||
string? buyerId, double sum, DiscountType discountType, double discount, bool
|
||||
isCancel, List<OrderProductDataModel>? products) =>
|
||||
new(id, blacksmithId, buyerId, sum, discountType, discount, isCancel, products);
|
||||
|
||||
private static List<OrderProductDataModel> CreateSubDataModel() =>
|
||||
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class OrderProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void OrderIdIsNullOrEmptyTest()
|
||||
{
|
||||
var orderProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OrderIdIsNotGuidTest()
|
||||
{
|
||||
var orederProduct = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orederProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var orderProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var orderProduct = CreateDataModel(Guid.NewGuid().ToString(), "productId", 10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var orderProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var orderProduct = CreateDataModel(orderId, productId, count);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(orderProduct.OrderId, Is.EqualTo(orderId));
|
||||
Assert.That(orderProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(orderProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static OrderProductDataModel CreateDataModel(string? orderId, string?
|
||||
productId, int count) => new(orderId, productId, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProductDataModelsTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Tool,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Tool,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Tool,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||
ProductType.Tool, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
ProductType.Tool, 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 BilletIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Tool, null, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Tool, string.Empty, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BilletIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Tool, "billetId", 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Tool, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Tool, Guid.NewGuid().ToString(), -10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.Tool;
|
||||
var billetId = Guid.NewGuid().ToString();
|
||||
var Price = 10;
|
||||
var isDelete = false;
|
||||
var product = CreateDataModel(id, productName, productType, billetId, Price, isDelete);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(product.Id, Is.EqualTo(id));
|
||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(product.BilletId, Is.EqualTo(billetId));
|
||||
Assert.That(product.Price, Is.EqualTo(Price));
|
||||
Assert.That(product.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductDataModel CreateDataModel(string? id, string?
|
||||
productName, ProductType productType, string? billetId, double price, bool
|
||||
isDeleted) => new(id, productName, productType, billetId, price, isDeleted);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProductHistoryDataMoodelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var productHistory = CreateDataModel(null, 10);
|
||||
Assert.That(() => productHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
productHistory = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => productHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("productId", 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var productHistory = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => productHistory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
productHistory = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => productHistory.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));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductHistoryDataModel CreateDataModel(string? productId, double oldPrice) =>
|
||||
new(productId, oldPrice);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Enums;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RankDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var rank = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
|
||||
RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
rank = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||
"name", RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name",
|
||||
RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankIdIsNullEmptyTest()
|
||||
{
|
||||
var rank = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
|
||||
RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
rank = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
"name", RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankIdIsNotGuidTest()
|
||||
{
|
||||
var rank = CreateDataModel(Guid.NewGuid().ToString(), "rankId",
|
||||
"name", RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankNameIsEmptyTest()
|
||||
{
|
||||
var rank = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), null, RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
rank = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
string.Empty, RankType.Student, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RankTypeIsNoneTest()
|
||||
{
|
||||
var rank = CreateDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), "name", RankType.None, true, DateTime.UtcNow);
|
||||
Assert.That(() => rank.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var rankId = Guid.NewGuid().ToString();
|
||||
var rankName = "name";
|
||||
var rankType = RankType.Student;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var rank = CreateDataModel(id, rankId, rankName, rankType, isActual, changeDate);
|
||||
Assert.That(() => rank.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(rank.Id, Is.EqualTo(id));
|
||||
Assert.That(rank.RankId, Is.EqualTo(rankId));
|
||||
Assert.That(rank.RankName, Is.EqualTo(rankName));
|
||||
Assert.That(rank.RankType, Is.EqualTo(rankType));
|
||||
Assert.That(rank.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(rank.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static RankDataModel CreateDataModel(string? id, string? rankId,
|
||||
string? rankName, RankType rankType, bool isActual, DateTime changeDate) =>
|
||||
new (id, rankId, rankName, rankType, isActual, changeDate);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
using TheBlacksmithVakulaContract.DataModels;
|
||||
using TheBlacksmithVakulaContract.Exceptions;
|
||||
|
||||
namespace TheBlacksmithVakulaTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void BlacksmithIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BlacksmithIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var salarySize = 10;
|
||||
var salary = CreateDataModel(id, salaryDate, salarySize);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.BlacksmithId, Is.EqualTo(id));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(salarySize));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? blacksmithId, DateTime
|
||||
salaryDate, double salary) => new(blacksmithId, salaryDate, salary);
|
||||
}
|
||||
}
|
||||
@@ -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.11.1" />
|
||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TheBlacksmithVakulaContract\TheBlacksmithVakulaContract.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user