Compare commits
3 Commits
7dfc2f1ed0
...
ca68301921
Author | SHA1 | Date | |
---|---|---|---|
ca68301921 | |||
341ba875cf | |||
2a7bf25076 |
@ -0,0 +1,34 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Xml;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class BuyerDataModel(string id, string fio, string phoneNumber) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string FIO { get; private set; } = fio;
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
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)[\-\s]?)?(\(?\d{3}\)?[\-\s]?)?[\d\-\s]{7,10}|(\d{2}[\-\s]?\d{2}[\-\s]?\d{2}))$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class DishDataModel(string id, string dishName, DishType dishType, double price, IngredientType ingredientType, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string DishName { get; private set; } = dishName;
|
||||
public DishType DishType { get; private set; } = dishType;
|
||||
public double Price { get; private set; } = price;
|
||||
public IngredientType IngredientType { get; private set; } = ingredientType;
|
||||
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 (DishName.IsEmpty())
|
||||
throw new ValidationException("Field DishName is empty");
|
||||
if (DishType == DishType.None)
|
||||
throw new ValidationException("Field DishType is empty");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class DishHistoryDataModel(string dishId, double oldPrice) : IValidation
|
||||
{
|
||||
public string DishId { get; private set; } = dishId;
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
public void Validate()
|
||||
{
|
||||
if (DishId.IsEmpty())
|
||||
throw new ValidationException("Field DishId is empty");
|
||||
if (!DishId.IsGuid())
|
||||
throw new ValidationException("The value in the field DishId is not a unique identifier");
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class OrderDataModel(string id, string workerId, string? buyerId, double sum, bool isCancel, List<OrderDishDataModel> dishes) : 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 bool IsCancel { get; private set; } = isCancel;
|
||||
public List<OrderDishDataModel> Dishes { get; private set; } = dishes;
|
||||
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 ((Dishes?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include dishes");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class OrderDishDataModel(string orderId, string dishId, int count) :
|
||||
IValidation
|
||||
{
|
||||
public string OrderId { get; private set; } = orderId;
|
||||
public string DishId { get; private set; } = dishId;
|
||||
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 (DishId.IsEmpty())
|
||||
throw new ValidationException("Field DishId is empty");
|
||||
if (!DishId.IsGuid())
|
||||
throw new ValidationException("The value in the field DishId 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 AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeContracts.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,27 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.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,42 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastructure;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
using System.Xml;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeContracts.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)
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - { EmploymentDate.ToShortDateString() }, BirthDate - { BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
15
AndDietCokeProject/AndDietCokeContracts/Enums/DishType.cs
Normal file
15
AndDietCokeProject/AndDietCokeContracts/Enums/DishType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Enums;
|
||||
|
||||
public enum DishType
|
||||
{
|
||||
None = 0,
|
||||
Pizza = 1,
|
||||
Pasta = 2,
|
||||
Beverage = 3
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Enums;
|
||||
|
||||
[Flags]
|
||||
public enum IngredientType
|
||||
{
|
||||
None = 0,
|
||||
Dough = 1,
|
||||
Cheese = 2,
|
||||
Tomato = 4
|
||||
}
|
15
AndDietCokeProject/AndDietCokeContracts/Enums/PostType.cs
Normal file
15
AndDietCokeProject/AndDietCokeContracts/Enums/PostType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Cashier = 1,
|
||||
Cook = 2,
|
||||
Packager = 3
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.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,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Infrastructure;
|
||||
|
||||
internal interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.10.35122.118
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndDietCokeContracts", "AndDietCokeContracts\AndDietCokeContracts.csproj", "{A256099F-4B07-44ED-B748-4369BD259FC6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AndDietCokeContracts", "AndDietCokeContracts\AndDietCokeContracts.csproj", "{A256099F-4B07-44ED-B748-4369BD259FC6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndDietCokeTests", "AndDietCokeTests\AndDietCokeTests.csproj", "{A21ACBA8-D297-49F8-89BF-7FA04B73D23F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{A256099F-4B07-44ED-B748-4369BD259FC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A256099F-4B07-44ED-B748-4369BD259FC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A256099F-4B07-44ED-B748-4369BD259FC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{A21ACBA8-D297-49F8-89BF-7FA04B73D23F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{A21ACBA8-D297-49F8-89BF-7FA04B73D23F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{A21ACBA8-D297-49F8-89BF-7FA04B73D23F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{A21ACBA8-D297-49F8-89BF-7FA04B73D23F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
28
AndDietCokeProject/AndDietCokeTests/AndDietCokeTests.csproj
Normal file
28
AndDietCokeProject/AndDietCokeTests/AndDietCokeTests.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="..\AndDietCokeContracts\AndDietCokeContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,72 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class BuyerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(null, "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(string.Empty, "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var buyer = CreateDataModel("id", "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), null, "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var fio = "Fio";
|
||||
var phoneNumber = "62-10-10";
|
||||
var buyer = CreateDataModel(buyerId, fio, phoneNumber);
|
||||
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));
|
||||
});
|
||||
}
|
||||
private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) =>
|
||||
new(id, fio, phoneNumber);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using static NUnit.Framework.Internal.OSPlatform;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class DishDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var dish = CreateDataModel(null, "name", DishType.Pizza, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(string.Empty, "name", DishType.Pizza, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var dish = CreateDataModel("id", "name", DishType.Pizza, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishNameIsEmptyTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), null, DishType.Pizza, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DishType.Pizza, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishTypeIsNoneTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), null, DishType.None, 10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), "name", DishType.Pizza, 0, IngredientType.Dough , false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(Guid.NewGuid().ToString(), "name", DishType.Pizza, -10, IngredientType.Dough, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var dishId = Guid.NewGuid().ToString();
|
||||
var dishName = "name";
|
||||
var dishType = DishType.Pizza;
|
||||
var dishPrice = 10;
|
||||
var dishIngredientType = IngredientType.Dough;
|
||||
var dishIsDelete = false;
|
||||
var dish = CreateDataModel(dishId, dishName, dishType, dishPrice, dishIngredientType, dishIsDelete);
|
||||
Assert.That(() => dish.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(dish.Id, Is.EqualTo(dishId));
|
||||
Assert.That(dish.DishName, Is.EqualTo(dishName));
|
||||
Assert.That(dish.DishType, Is.EqualTo(dishType));
|
||||
Assert.That(dish.Price, Is.EqualTo(dishPrice));
|
||||
Assert.That(dish.IngredientType, Is.EqualTo(dishIngredientType));
|
||||
Assert.That(dish.IsDeleted, Is.EqualTo(dishIsDelete));
|
||||
});
|
||||
}
|
||||
private static DishDataModel CreateDataModel(string? id, string? dishName, DishType dishType, double price, IngredientType ingredientType, bool isDeleted) =>
|
||||
new(id, dishName, dishType, price, ingredientType, isDeleted);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class DishHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void DishIdIsNullOrEmptyTest()
|
||||
{
|
||||
var dish = CreateDataModel(null, 10);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishIdIsNotGuidTest()
|
||||
{
|
||||
var dish = CreateDataModel("id", 10);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var dishId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var dishHistory = CreateDataModel(dishId, oldPrice);
|
||||
Assert.That(() => dishHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(dishHistory.DishId, Is.EqualTo(dishId));
|
||||
Assert.That(dishHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(dishHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(dishHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
private static DishHistoryDataModel CreateDataModel(string? dishId, double oldPrice) =>
|
||||
new(dishId, oldPrice);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OrderDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 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, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 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, 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, false, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -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, false, null);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, false, []);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var isCancel = true;
|
||||
var dishes = CreateSubDataModel();
|
||||
var sale = CreateDataModel(orderId, workerId, buyerId, sum, isCancel, dishes);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(orderId));
|
||||
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(sale.BuyerId, Is.EqualTo(buyerId));
|
||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Dishes, Is.EquivalentTo(dishes));
|
||||
});
|
||||
}
|
||||
private static OrderDataModel CreateDataModel(string? id, string? workerId, string? buyerId, double sum, bool isCancel, List<OrderDishDataModel>? dishes) =>
|
||||
new(id, workerId, buyerId, sum, isCancel, dishes);
|
||||
private static List<OrderDishDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OrderDishDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void OrderIdIsNullOrEmptyTest()
|
||||
{
|
||||
var orderDish = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderDish = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OrderIdIsNotGuidTest()
|
||||
{
|
||||
var orderDish = CreateDataModel("orderId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishIdIsNullOrEmptyTest()
|
||||
{
|
||||
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderDish = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishIdIsNotGuidTest()
|
||||
{
|
||||
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), "dishId", 10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
orderDish = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
var dishId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var orderDish = CreateDataModel(orderId, dishId, count);
|
||||
Assert.That(() => orderDish.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(orderDish.OrderId, Is.EqualTo(orderId));
|
||||
Assert.That(orderDish.DishId, Is.EqualTo(dishId));
|
||||
Assert.That(orderDish.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
private static OrderDishDataModel CreateDataModel(string? orderId, string? dishId, int count) =>
|
||||
new(orderId, dishId, count);
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Cook, 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.Cook, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Cook, 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.Cook, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Cook, -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.Cook;
|
||||
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,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.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,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
|
||||
namespace AndDietCokeTests.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);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user