Compare commits
1 Commits
main
...
Task_1_Mod
| Author | SHA1 | Date | |
|---|---|---|---|
| 32428eeae3 |
@@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.7.34024.191
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndDietCokeProject", "AndDietCokeProject\AndDietCokeProject.csproj", "{624595D1-D7AA-4448-AA30-4D5AA21AE6D6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AndDietCokeContracts", "AndDietCokeProject\AndDietCokeContracts.csproj", "{624595D1-D7AA-4448-AA30-4D5AA21AE6D6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AndDietCokeTests", "AndDietCokeTests\AndDietCokeTests.csproj", "{EABA3AD5-7690-448A-BEE6-010499DD8790}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -15,6 +17,10 @@ Global
|
||||
{624595D1-D7AA-4448-AA30-4D5AA21AE6D6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{624595D1-D7AA-4448-AA30-4D5AA21AE6D6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{624595D1-D7AA-4448-AA30-4D5AA21AE6D6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EABA3AD5-7690-448A-BEE6-010499DD8790}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EABA3AD5-7690-448A-BEE6-010499DD8790}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EABA3AD5-7690-448A-BEE6-010499DD8790}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EABA3AD5-7690-448A-BEE6-010499DD8790}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>preview</LangVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,36 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
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.Infrastrusture;
|
||||
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)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
if (!Regex.IsMatch(FIO, @"^[А-ЯЁA-Z][а-яёa-z]+(?:-[А-ЯЁA-Z][а-яёa-z]+)?\s[А-ЯЁA-Z][а-яёa-z]+(?:\s[А-ЯЁA-Z][а-яёa-z]+)?$"))
|
||||
throw new ValidationException("Incorrect FIO input");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class DishDataModel(string id, string dishName, DishType dishType, double price, 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 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,27 @@
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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,30 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
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,42 @@
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
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,28 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
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,41 @@
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
|
||||
namespace AndDietCokeContracts.DataModels;
|
||||
|
||||
public class SaleDataModel(string id, string workerId, string? buyerId, double sum, bool isConstantClient, 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 IsConstantClient { get; private set; } = isConstantClient;
|
||||
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,42 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Extensions;
|
||||
using AndDietCokeContracts.Infrastrusture;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
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) //EmploymentDate.Year - BirthDate.Year
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
||||
15
AndDietCokeProject/AndDietCokeProject/Enums/DishType.cs
Normal file
15
AndDietCokeProject/AndDietCokeProject/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,
|
||||
Base = 1,
|
||||
Dessert = 2,
|
||||
Drink = 3
|
||||
}
|
||||
16
AndDietCokeProject/AndDietCokeProject/Enums/PostType.cs
Normal file
16
AndDietCokeProject/AndDietCokeProject/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 AndDietCokeContracts.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Waiter = 1,
|
||||
Chef = 2,
|
||||
Packer = 3
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeContracts.Exceptions;
|
||||
|
||||
public class ValidationException : Exception
|
||||
{
|
||||
public ValidationException(string message) : base(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.Infrastrusture;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
24
AndDietCokeProject/AndDietCokeTests/AndDietCokeTests.csproj
Normal file
24
AndDietCokeProject/AndDietCokeTests/AndDietCokeTests.csproj
Normal file
@@ -0,0 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" />
|
||||
<PackageReference Include="NUnit" Version="3.13.3" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.6.1" />
|
||||
<PackageReference Include="coverlet.collector" Version="3.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\AndDietCokeProject\AndDietCokeContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,68 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
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, "Ivanov Ivan", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(string.Empty, "Ivanov Ivan", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var buyer = CreateDataModel("id", "Ivanov Ivan", "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(), "Ivanov Ivan", null);
|
||||
Assert.That(() => buyer.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "Ivanov Ivan", string.Empty);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "Ivanov Ivan", "777");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var fio = "Ivanov Ivan";
|
||||
var phoneNumber = "+7-777-777-77-77";
|
||||
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 AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static NUnit.Framework.Internal.OSPlatform;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class DishDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var dish = CreateDataModel(null, "name", DishType.Drink, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(string.Empty, "name", DishType.Drink, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var dish = CreateDataModel("id", "name", DishType.Drink, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishNameIsEmptyTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), null, DishType.Drink, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DishType.Drink, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DishTypeIsNoneTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), null, DishType.None, 10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var dish = CreateDataModel(Guid.NewGuid().ToString(), "name", DishType.Drink, 0, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
dish = CreateDataModel(Guid.NewGuid().ToString(), "name", DishType.Drink, -10, false);
|
||||
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var dishId = Guid.NewGuid().ToString();
|
||||
var dishName = "name";
|
||||
var dishType = DishType.Drink;
|
||||
var dishPrice = 10;
|
||||
var dishIsDelete = false;
|
||||
var dish = CreateDataModel(dishId, dishName, dishType, dishPrice, 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.IsDeleted, Is.EqualTo(dishIsDelete));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static DishDataModel CreateDataModel(string? id, string? dishName, DishType dishType, double price, bool isDeleted) => new(id, dishName, dishType, price, isDeleted);
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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,74 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OrderDataModelTests
|
||||
{
|
||||
[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("saleId", 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,92 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Enums;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Waiter, 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.Waiter, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Waiter, 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.Waiter, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Waiter, -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.Waiter;
|
||||
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 AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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,99 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AndDietCokeTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SaleDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "workerId", Guid.NewGuid().ToString(), 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuyerIdIsNotGuidTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId", 10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, true, false, CreateSubDataModel());
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, true, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, true, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var saleId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var sum = 10;
|
||||
var isConstantClient = true;
|
||||
var isCancel = true;
|
||||
var dishes = CreateSubDataModel();
|
||||
var sale = CreateDataModel(saleId, workerId, buyerId, sum, isConstantClient, isCancel, dishes);
|
||||
Assert.That(() => sale.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(sale.Id, Is.EqualTo(saleId));
|
||||
Assert.That(sale.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(sale.BuyerId, Is.EqualTo(buyerId));
|
||||
Assert.That(sale.Sum, Is.EqualTo(sum));
|
||||
Assert.That(sale.IsConstantClient, Is.EqualTo(isConstantClient));
|
||||
Assert.That(sale.IsCancel, Is.EqualTo(isCancel));
|
||||
Assert.That(sale.Dishes, Is.EquivalentTo(dishes));
|
||||
});
|
||||
}
|
||||
|
||||
private static SaleDataModel CreateDataModel(string? id, string? workerId, string? buyerId, double sum, bool IsConstantClient, bool isCancel, List<OrderDishDataModel>? dishes) => new(id, workerId, buyerId, sum, IsConstantClient, isCancel, dishes);
|
||||
private static List<OrderDishDataModel> CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
using AndDietCokeContracts.DataModels;
|
||||
using AndDietCokeContracts.Exceptions;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
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(-18).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);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user