PIbd-23 Kobin V.O. First labWork #1

Open
vkobi wants to merge 3 commits from Task_1_Models into main
13 changed files with 587 additions and 5 deletions
Showing only changes of commit c433b0954e - Show all commits

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace SweetBunsContracts.DataModels;
public class CookingDataModell(string productId, int count) : IValidation
public class CookingDataModel(string productId, int count) : IValidation
{
public string ProductId { get; private set; } = productId;
public int Count { get; private set; } = count;

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace SweetBunsContracts.DataModels;
public class RecipeDataModel(string ingredientsId, string productId, int count) : IValidation
public class RecipeDataModel(string ingredientsId, int count, string productId) : IValidation
{
public string IngredientsId { get; private set; } = ingredientsId;
public int Count { get; private set; } = count;

View File

@ -9,7 +9,7 @@ using System.Threading.Tasks;
namespace SweetBunsContracts.DataModels;
public class SalaryDataModell(string workerId, DateTime salaryDate, double workerSalary) : IValidation
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
{
public string WorkerId { get; private set; } = workerId;

View File

@ -8,10 +8,12 @@ using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Xml;
using SweetBunsContracts.Exceptions;
using System.Numerics;
using System.Text.RegularExpressions;
namespace SweetBunsContracts.DataModels;
public class WorkerDataModell(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
public class WorkerDataModel(string id, string fio, string postId, string email, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
@ -19,6 +21,8 @@ public class WorkerDataModell(string id, string fio, string postId, DateTime bir
public string PostId { get; private set; } = postId;
public string Email { get; private set; } = email;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime EmploymentDate { get; private set; } = employmentDate;
@ -40,6 +44,12 @@ public class WorkerDataModell(string id, string fio, string postId, DateTime bir
if (!PostId.IsGuid())
throw new ValidationException("The value in the field PostId is not a unique identifier");
if (Email.IsEmpty())
throw new ValidationException("Field Email is empty");
if (!Regex.IsMatch(Email, @"^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$"))
throw new ValidationException("Field Email is not an email");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Exceptions;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class CookingDataModelTests
{
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var cooking = CreateDataModel(string.Empty, 10);
Assert.That(() => cooking.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var cooking = CreateDataModel("id", 10);
Assert.That(() => cooking.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var cooking = CreateDataModel(Guid.NewGuid().ToString(), 0);
Assert.That(() => cooking.Validate(), Throws.TypeOf<ValidationException>());
cooking = CreateDataModel(Guid.NewGuid().ToString(), -10);
Assert.That(() => cooking.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var productId = Guid.NewGuid().ToString();
var count = 10;
var cooking = CreateDataModel(productId, count);
Assert.That(() => cooking.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(cooking.ProductId, Is.EqualTo(productId));
Assert.That(cooking.Count, Is.EqualTo(count));
});
}
private static CookingDataModel CreateDataModel(string ProductId, int Count) => new(ProductId, Count);
}

View File

@ -0,0 +1,58 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class IngredientsDataModelTests
{
[Test]
public void IdIsNullEmptyTest()
{
var ingredient = CreateDataModel(null, "name");
Assert.That(() => ingredient.Validate(), Throws.TypeOf<ValidationException>());
ingredient = CreateDataModel(string.Empty, "name");
Assert.That(() => ingredient.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var ingredient = CreateDataModel("id", "name");
Assert.That(() => ingredient.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IngredientNameIsNullOrEmptyTest()
{
var ingredient = CreateDataModel(Guid.NewGuid().ToString(), null);
Assert.That(() => ingredient.Validate(), Throws.TypeOf<ValidationException>());
ingredient = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
Assert.That(() => ingredient.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var ingredientId = Guid.NewGuid().ToString();
var ingredientName = "name";
var prevIngredientName = "prevIngredientName";
var prevPrevIngredientName = "prevPrevIngredientName";
var ingredient = CreateDataModel(ingredientId, ingredientName, prevIngredientName, prevPrevIngredientName);
Assert.That(() => ingredient.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(ingredient.Id, Is.EqualTo(ingredientId));
Assert.That(ingredient.IngredientName, Is.EqualTo(ingredientName));
Assert.That(ingredient.PrevIngredientName, Is.EqualTo(prevIngredientName));
Assert.That(ingredient.PrevPrevIngredientName, Is.EqualTo(prevPrevIngredientName));
});
}
private static IngredientsDataModel CreateDataModel(string? id, string? ingredientName, string? prevIngredientName = null, string? prevPrevIngredientName = null) => new(id, ingredientName, prevIngredientName, prevPrevIngredientName);
}

View File

@ -0,0 +1,98 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Enums;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class PostDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Production, 10, true, DateTime.UtcNow);
Assert.That(() => post.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.Production, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Production, -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.Production;
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);
}

View File

@ -0,0 +1,95 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Enums;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class ProductDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var product = CreateDataModel(null, "name", ProductType.Cookies, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(string.Empty, "name", ProductType.Cookies, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var product = CreateDataModel("id", "name", ProductType.Cookies, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductNameIsEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Cookies, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Cookies, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductTypeIsNoneTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IngredientsIdIsNullOrEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cookies, null, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cookies, string.Empty, 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IngredientsIdIsNotGuidTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cookies, "ingredientsId", 10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cookies, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cookies, Guid.NewGuid().ToString(), -10, false);
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var productId = Guid.NewGuid().ToString();
var productName = "name";
var productType = ProductType.Cookies;
var productIngredientsId = Guid.NewGuid().ToString();
var productPrice = 10;
var productIsDelete = false;
var product = CreateDataModel(productId, productName, productType, productIngredientsId, productPrice, productIsDelete);
Assert.That(() => product.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(product.Id, Is.EqualTo(productId));
Assert.That(product.ProductName, Is.EqualTo(productName));
Assert.That(product.ProductType, Is.EqualTo(productType));
Assert.That(product.IngredientsId, Is.EqualTo(productIngredientsId));
Assert.That(product.Price, Is.EqualTo(productPrice));
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
});
}
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType, string? ingredientsId, double price, bool isDeleted) => new(id, productName, productType, ingredientsId, price, isDeleted);
}

View File

@ -0,0 +1,72 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class RecipeDataModelTests
{
[Test]
public void IngredientsIdIsNullOrEmptyTest()
{
var recipe = CreateDataModel(null, 10, Guid.NewGuid().ToString());
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
recipe = CreateDataModel(string.Empty, 10, Guid.NewGuid().ToString());
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IngredientsIdIsNotGuidTest()
{
var recipe = CreateDataModel("id", 10, Guid.NewGuid().ToString());
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var recipe = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString());
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
recipe = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString());
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNullOrEmptyTest()
{
var recipe = CreateDataModel(Guid.NewGuid().ToString(), 10, null);
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
recipe = CreateDataModel(Guid.NewGuid().ToString(), 10, string.Empty);
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var recipe = CreateDataModel(Guid.NewGuid().ToString(), 10, "id");
Assert.That(() => recipe.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var ingredientsId = Guid.NewGuid().ToString();
var count = 10;
var productId = Guid.NewGuid().ToString();
var recipe = CreateDataModel(ingredientsId, count, productId);
Assert.That(() => recipe.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(recipe.IngredientsId, Is.EqualTo(ingredientsId));
Assert.That(recipe.Count, Is.EqualTo(count));
Assert.That(recipe.ProductId, Is.EqualTo(productId));
});
}
private static RecipeDataModel CreateDataModel(string? ingredientsId, int count, string? productId) => new(ingredientsId, count, productId);
}

View File

@ -0,0 +1,56 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[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 WorkerSalaryIsLessOrZeroTest()
{
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);
}

View File

@ -0,0 +1,112 @@
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModels_Tests;
[TestFixture]
internal class WorkerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), "email@email.com", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), "email@email.com", 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(), "email@email.com", 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(), "email@email.com", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), "email@email.com", 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, "email@email.com", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, "email@email.com", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var worker = CreateDataModel("id", "fio", "postId", "email@email.com", DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmailIsNullOrEmptyTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), null, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmailIsIncorrectTest()
{
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), "edww@dqd,com", 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(), "email@email.com", 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(), "email@email.com", 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(), "email@email.com", 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 email = "email@email.com";
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
var employmentDate = DateTime.Now;
var isDelete = false;
var worker = CreateDataModel(workerId, fio, postId, email, 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.Email, Is.EqualTo(email));
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, string? email, DateTime birthDate, DateTime employmentDate, bool isDeleted) => new(id, fio, postId, email, birthDate, employmentDate, isDeleted);
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SweetBunsContracts\SweetBunsContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>

View File

@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35707.178 d17.12
VisualStudioVersion = 17.12.35707.178
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SweetBunsContracts", "SweetBunsContracts\SweetBunsContracts.csproj", "{EC2711C2-3C5B-4B61-B205-33C87C822197}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SweetBunsTests", "SweetBunsTests\SweetBunsTests.csproj", "{94AE5144-46DE-4C5A-AE9D-854B84A4ACD2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{EC2711C2-3C5B-4B61-B205-33C87C822197}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC2711C2-3C5B-4B61-B205-33C87C822197}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC2711C2-3C5B-4B61-B205-33C87C822197}.Release|Any CPU.Build.0 = Release|Any CPU
{94AE5144-46DE-4C5A-AE9D-854B84A4ACD2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{94AE5144-46DE-4C5A-AE9D-854B84A4ACD2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{94AE5144-46DE-4C5A-AE9D-854B84A4ACD2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{94AE5144-46DE-4C5A-AE9D-854B84A4ACD2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE