1 лаба
This commit is contained in:
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.11.35312.102
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnowMaidenContracts", "SnowMaidenContracts\SnowMaidenContracts.csproj", "{3DC5F9A5-F527-412A-ABB4-083432D2C54E}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SnowMaidenContracts", "SnowMaidenContracts\SnowMaidenContracts.csproj", "{3DC5F9A5-F527-412A-ABB4-083432D2C54E}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SnowMaidenTests", "SnowMaidenTests\SnowMaidenTests.csproj", "{E9BC9181-A413-46D0-9B6D-C215F995DB45}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{3DC5F9A5-F527-412A-ABB4-083432D2C54E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{3DC5F9A5-F527-412A-ABB4-083432D2C54E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{3DC5F9A5-F527-412A-ABB4-083432D2C54E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E9BC9181-A413-46D0-9B6D-C215F995DB45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{E9BC9181-A413-46D0-9B6D-C215F995DB45}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E9BC9181-A413-46D0-9B6D-C215F995DB45}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E9BC9181-A413-46D0-9B6D-C215F995DB45}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace SnowMaidenContracts
|
||||
{
|
||||
public class Class1
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
|
||||
using SnowMaidenContracts.Enums;
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.DataModels;
|
||||
|
||||
public class IceCreamDataModel(string id, string icecreamName, IceCreamType icecreamType, string manufacturerId, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string IceCreamName { get; private set; } = icecreamName;
|
||||
|
||||
public IceCreamType IceCreamType { get; private set; } = icecreamType;
|
||||
|
||||
public string ManufacturerId { get; private set; } = manufacturerId;
|
||||
|
||||
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 (IceCreamName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
|
||||
if (IceCreamType == IceCreamType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
|
||||
if (ManufacturerId.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerId is empty");
|
||||
|
||||
if (!ManufacturerId.IsGuid())
|
||||
throw new ValidationException("The value in the field ManufacturerId is not a unique identifier");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.DataModels;
|
||||
|
||||
|
||||
public class IceCreamHistoryDataModel(string icecreamId, double oldPrice) : IValidation
|
||||
{
|
||||
public string IceCreamId { get; private set; } = icecreamId;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (IceCreamId.IsEmpty())
|
||||
throw new ValidationException("Field IceCreamId is empty");
|
||||
|
||||
if (!IceCreamId.IsGuid())
|
||||
throw new ValidationException("The value in the field IceCreamId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.DataModels;
|
||||
|
||||
public class ManufacturerDataModel(string id, string manufacturerName, string? prevManufacturerName, string? prevPrevManufacturerName) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string ManufacturerName { get; private set; } = manufacturerName;
|
||||
|
||||
public string? PrevManufacturerName { get; private set; } = prevManufacturerName;
|
||||
|
||||
public string? PrevPrevManufacturerName { get; private set; } = prevPrevManufacturerName;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty())
|
||||
throw new ValidationException("Field Id is empty");
|
||||
|
||||
if (!Id.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
|
||||
if (ManufacturerName.IsEmpty())
|
||||
throw new ValidationException("Field ManufacturerName is empty");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using SnowMaidenContracts.Enums;
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.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,31 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
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 (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, double sum, bool isCancel, List<SaleProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
|
||||
|
||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public double Sum { get; private set; } = sum;
|
||||
|
||||
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 (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,37 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.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,52 @@
|
||||
using SnowMaidenContracts.Extensions;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.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 (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,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.Enums;
|
||||
|
||||
public enum IceCreamType
|
||||
{
|
||||
None = 0,
|
||||
IceCream = 1,
|
||||
Sherbet = 2,
|
||||
FruitIce = 3,
|
||||
Popsicle = 4,
|
||||
CremeBrulee = 5
|
||||
}
|
||||
16
SnowMaidenContracts/SnowMaidenContracts/Enums/PostType.cs
Normal file
16
SnowMaidenContracts/SnowMaidenContracts/Enums/PostType.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Driver = 1,
|
||||
Seller = 2,
|
||||
Assistant = 3
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.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,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SnowMaidenContracts.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
|
||||
using SnowMaidenContracts.Enums;
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class IceCreamDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var icecream = CreateDataModel(null, "name", IceCreamType.Popsicle, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
icecream = CreateDataModel(string.Empty, "name", IceCreamType.Popsicle, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var icecream = CreateDataModel("id", "name", IceCreamType.Popsicle, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IceCreamNameIsEmptyTest()
|
||||
{
|
||||
var icecream = CreateDataModel(Guid.NewGuid().ToString(), null, IceCreamType.Popsicle, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
icecream = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, IceCreamType.Popsicle, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IceCreamTypeIsNoneTest()
|
||||
{
|
||||
var icecream = CreateDataModel(Guid.NewGuid().ToString(), null, IceCreamType.None, Guid.NewGuid().ToString(), 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var icecream = CreateDataModel(Guid.NewGuid().ToString(), "name", IceCreamType.Popsicle, null, 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
icecream = CreateDataModel(Guid.NewGuid().ToString(), "name", IceCreamType.Popsicle, string.Empty, 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerIdIsNotGuidTest()
|
||||
{
|
||||
var icecream = CreateDataModel(Guid.NewGuid().ToString(), "name", IceCreamType.Popsicle, "manufacturerId", 10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var icecream = CreateDataModel(Guid.NewGuid().ToString(), "name", IceCreamType.Popsicle, Guid.NewGuid().ToString(), 0, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
icecream = CreateDataModel(Guid.NewGuid().ToString(), "name", IceCreamType.Popsicle, Guid.NewGuid().ToString(), -10, false);
|
||||
Assert.That(() => icecream.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var icecreamId = Guid.NewGuid().ToString();
|
||||
var icecreamName = "name";
|
||||
var icecreamType = IceCreamType.Popsicle;
|
||||
var icecreamManufacturerId = Guid.NewGuid().ToString();
|
||||
var icecreamPrice = 10;
|
||||
var icecreamIsDelete = false;
|
||||
var icecream = CreateDataModel(icecreamId, icecreamName, icecreamType, icecreamManufacturerId, icecreamPrice, icecreamIsDelete);
|
||||
Assert.That(() => icecream.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(icecream.Id, Is.EqualTo(icecreamId));
|
||||
Assert.That(icecream.IceCreamName, Is.EqualTo(icecreamName));
|
||||
Assert.That(icecream.IceCreamType, Is.EqualTo(icecreamType));
|
||||
Assert.That(icecream.ManufacturerId, Is.EqualTo(icecreamManufacturerId));
|
||||
Assert.That(icecream.Price, Is.EqualTo(icecreamPrice));
|
||||
Assert.That(icecream.IsDeleted, Is.EqualTo(icecreamIsDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static IceCreamDataModel CreateDataModel(string? id, string? icecreamName, IceCreamType icecreamType, string? manufacturerId, double price, bool isDeleted) =>
|
||||
new(id, icecreamName, icecreamType, manufacturerId, price, isDeleted);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class IceCreamHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IceCreamIdIsNullOrEmptyTest()
|
||||
{
|
||||
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 IceCreamIdIsNotGuidTest()
|
||||
{
|
||||
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 icecreamId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var productHistory = CreateDataModel(icecreamId, oldPrice);
|
||||
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productHistory.IceCreamId, Is.EqualTo(icecreamId));
|
||||
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 IceCreamHistoryDataModel CreateDataModel(string? icecreamId, double oldPrice) =>
|
||||
new(icecreamId, oldPrice);
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ManufacturerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(null, "name");
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel("id", "name");
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ManufacturerNameIsNullOrEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var manufacturerId = Guid.NewGuid().ToString();
|
||||
var manufacturerName = "name";
|
||||
var prevManufacturerName = "prevManufacturerName";
|
||||
var prevPrevManufacturerName = "prevPrevManufacturerName";
|
||||
var manufacturer = CreateDataModel(manufacturerId, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(manufacturer.Id, Is.EqualTo(manufacturerId));
|
||||
Assert.That(manufacturer.ManufacturerName, Is.EqualTo(manufacturerName));
|
||||
Assert.That(manufacturer.PrevManufacturerName, Is.EqualTo(prevManufacturerName));
|
||||
Assert.That(manufacturer.PrevPrevManufacturerName, Is.EqualTo(prevPrevManufacturerName));
|
||||
});
|
||||
}
|
||||
|
||||
private static ManufacturerDataModel CreateDataModel(string? id, string? manufacturerName, string? prevManufacturerName = null, string? prevPrevManufacturerName = null) =>
|
||||
new(id, manufacturerName, prevManufacturerName, prevPrevManufacturerName);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
using SnowMaidenContracts.Enums;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistant, 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.Assistant, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistant, 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.Assistant, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistant, -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.Assistant;
|
||||
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,51 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
[TestFixture]
|
||||
internal class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WorkerIdIsEmptyTest()
|
||||
{
|
||||
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 WorkerIdIsNotGuidTest()
|
||||
{
|
||||
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 workerId = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var workerSalary = 10;
|
||||
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
|
||||
new(workerId, salaryDate, workerSalary);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.DataModelsTests;
|
||||
[TestFixture]
|
||||
internal class SaleDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel( string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel( "workerId", Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel( Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel( Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel( Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel( Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var isCancel = true;
|
||||
var products = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, workerId, sum, 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.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Products, Is.EquivalentTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateDataModel(string? id, string? workerId, double sum, bool isCancel, List<SaleProductDataModel>? products) =>
|
||||
new(id, workerId, sum, isCancel, products);
|
||||
|
||||
private static List<SaleProductDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.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,90 @@
|
||||
using SnowMaidenContracts.DataModels;
|
||||
using SnowMaidenContracts.Exceptions;
|
||||
|
||||
namespace SnowMaidenTests.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 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 = "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);
|
||||
}
|
||||
28
SnowMaidenContracts/SnowMaidenTests/SnowMaidenTests.csproj
Normal file
28
SnowMaidenContracts/SnowMaidenTests/SnowMaidenTests.csproj
Normal file
@@ -0,0 +1,28 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="coverlet.collector" Version="6.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="NUnit" Version="3.14.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.9.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SnowMaidenContracts\SnowMaidenContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user