This commit is contained in:
nikskob 2025-02-20 16:20:50 +03:00
parent c3370cd015
commit 69bc61142f
13 changed files with 329 additions and 4 deletions

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 17.10.35004.147
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SweetBunsContracts", "SweetBunsContracts\SweetBunsContracts.csproj", "{9D734A14-E182-4FEC-A0EE-A97BBCBE5D76}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SweetBunsTests", "SweetBunsTests\SweetBunsTests.csproj", "{CF87C268-2E2E-4051-AD88-F83362D8D332}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{9D734A14-E182-4FEC-A0EE-A97BBCBE5D76}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D734A14-E182-4FEC-A0EE-A97BBCBE5D76}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D734A14-E182-4FEC-A0EE-A97BBCBE5D76}.Release|Any CPU.Build.0 = Release|Any CPU
{CF87C268-2E2E-4051-AD88-F83362D8D332}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CF87C268-2E2E-4051-AD88-F83362D8D332}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CF87C268-2E2E-4051-AD88-F83362D8D332}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CF87C268-2E2E-4051-AD88-F83362D8D332}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -16,6 +16,7 @@ public class EmployeeDataModel(string id, string fio, string postId, string prev
public string FIO { get; private set; } = fio;
public string PostId { get; private set; } = postId;
public string PreviousPostId { get; private set; } = previousPostId;
public DateTime BirthDate { get; private set; } = birthDate;
@ -41,6 +42,12 @@ public class EmployeeDataModel(string id, string fio, string postId, string prev
if (!PostId.IsGuid())
throw new ValidationException("The value in the field PostId is not a unique identifier");
if (PreviousPostId.IsEmpty())
throw new ValidationException("Field PreviousPostId is empty");
if (!PreviousPostId.IsGuid())
throw new ValidationException("The value in the field PreviousPostId is not a unique identifier");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");

View File

@ -10,7 +10,7 @@ using SweetBunsContracts.Infrastructure;
namespace SweetBunsContracts.DataModels;
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted, List<ProductIngridientDataModel> ingredients) : IValidation
public class ProductDataModel(string id, string productName, ProductType productType, double price, bool isDeleted, List<ProductIngredientDataModel> ingredients) : IValidation
{
public string Id { get; private set; } = id;
@ -21,7 +21,7 @@ public class ProductDataModel(string id, string productName, ProductType product
public double Price { get; private set; } = price;
public bool IsDeleted { get; private set; } = isDeleted;
public List<ProductIngridientDataModel> Ingredients { get; private set; } = ingredients;
public List<ProductIngredientDataModel> Ingredients { get; private set; } = ingredients;
public void Validate()
{

View File

@ -10,7 +10,7 @@ using SweetBunsContracts.Exceptions;
namespace SweetBunsContracts.DataModels;
public class ProductIngridientDataModel(string ingredientId,int amountOfIngredients, string productId) : IValidation
public class ProductIngredientDataModel(string ingredientId,int amountOfIngredients, string productId) : IValidation
{
public string IngredientId { get; private set; } = ingredientId;
public int AmountOfIngredients { get; private set; } = amountOfIngredients;

View File

@ -7,5 +7,6 @@ using System.Threading.Tasks;
namespace SweetBunsContracts.Infrastructure;
public class IValidation
{
void Validate();
public void Validate() {
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModelsTests
{
internal class IngredientDataModelTests
{
}
}

View File

@ -0,0 +1,116 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Enums;
using SweetBunsContracts.Exceptions;
namespace SweetBunsTests.DataModelsTests;
[TestFixture]
internal class EmployeeDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name",
PostType.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
"name", PostType.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name",
PostType.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name",
PostType.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
"name", PostType.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId",
"name", PostType.Basics, 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.Basics, 10, true, DateTime.UtcNow);
Assert.That(() => manufacturer.Validate(),
Throws.TypeOf<ValidationException>());
manufacturer = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), string.Empty, PostType.Basics, 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.Basics, 0, true, DateTime.UtcNow);
Assert.That(() => post.Validate(),
Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), "name", PostType.Basics, -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.Basics;
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,118 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SweetBunsContracts.DataModels;
using SweetBunsContracts.Enums;
using SweetBunsContracts.Exceptions;
namespace SweetBunsTests.DataModelsTests;
//Тут поменять под мое и проверить связь многие ко многим надо ли чет менять
[TestFixture]
internal class ProductDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var product = CreateDataModel(null, "name", ProductType.Blanks,
Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
product = CreateDataModel(string.Empty, "name",
ProductType.Blanks, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var product = CreateDataModel("id", "name", ProductType.Blanks,
Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductNameIsEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), null,
ProductType.Blanks, Guid.NewGuid().ToString(), 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
ProductType.Blanks, 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 ManufacturerIdIsNullOrEmptyTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
ProductType.Blanks, null, 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
ProductType.Blanks, string.Empty, 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void ManufacturerIdIsNotGuidTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
ProductType.Blanks, 10, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var product = CreateDataModel(Guid.NewGuid().ToString(), "name",
ProductType.Blanks, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => product.Validate(),
Throws.TypeOf<ValidationException>());
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
ProductType.Blanks, 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.Blanks;
var productPrice = 10;
var productIsDelete = false;
var product = CreateDataModel(productId, productName, productType,
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.Price, Is.EqualTo(productPrice));
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
});
}
private static ProductDataModel CreateDataModel(string? id, string?
productName, ProductType productType, double price, bool
isDeleted, List<ProductIngredientDataModel> ingredients) => new(id, productName, productType, price, isDeleted, ingredients);
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModelsTests
{
internal class ProductIngredientDataModelTests
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModelsTests
{
internal class SalaryDataModelTests
{
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SweetBunsTests.DataModelsTests
{
internal class SaleDataModelTests
{
}
}

View 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="..\SweetBunsContracts\SweetBunsContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>