всеобщая гойда
This commit is contained in:
parent
69bc61142f
commit
a516bf3a29
@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using SweetBunsContracts.Extensions;
|
||||
using SweetBunsContracts.Infrastructure;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace SweetBunsContracts.DataModels;
|
||||
|
||||
@ -36,6 +37,9 @@ public class EmployeeDataModel(string id, string fio, string postId, string prev
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (!Regex.IsMatch(FIO, @"^[a-zA-Zа-яА-Я\s'-]+$"))
|
||||
throw new ValidationException("Field FIO is incorrect");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
|
@ -30,7 +30,8 @@ public class ProductIngredientDataModel(string ingredientId,int amountOfIngredie
|
||||
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
if (AmountOfIngredients <= 0)
|
||||
throw new ValidationException("Field AmountOfIngredients is less than or equal to 0");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1 +1,121 @@
|
||||
|
||||
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 employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "123", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PreviousPostIdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), "previousPostId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PreviousPostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var previousPostId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var employee = CreateDataModel(employeeId, fio, postId, previousPostId, birthDate, employmentDate, isDelete);
|
||||
Assert.That(() => employee.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(employee.Id, Is.EqualTo(employeeId));
|
||||
Assert.That(employee.FIO, Is.EqualTo(fio));
|
||||
Assert.That(employee.PostId, Is.EqualTo(postId));
|
||||
Assert.That(employee.PreviousPostId, Is.EqualTo(previousPostId));
|
||||
Assert.That(employee.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate));
|
||||
Assert.That(employee.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId, string? previousPostId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, postId, previousPostId, birthDate, employmentDate, isDeleted);
|
||||
}
|
@ -3,10 +3,51 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.DataModels;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsTests.DataModelsTests
|
||||
namespace SweetBunsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class IngredientDataModelTests
|
||||
{
|
||||
internal class IngredientDataModelTests
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var Ingredient = CreateDataModel(string.Empty, "name");
|
||||
Assert.That(() => Ingredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Ingredient = CreateDataModel(null, "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 NameIsNullOrEmptyTest()
|
||||
{
|
||||
var Ingredient = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => Ingredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
Ingredient = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => Ingredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Name";
|
||||
var Ingredient = CreateDataModel(id, name);
|
||||
Assert.That(() => Ingredient.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(Ingredient.Id, Is.EqualTo(id));
|
||||
Assert.That(Ingredient.Name, Is.EqualTo(name));
|
||||
});
|
||||
}
|
||||
|
||||
private static IngredientDataModel CreateDataModel(string? Id, string? Name) =>
|
||||
new(Id, Name);
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ using SweetBunsContracts.Exceptions;
|
||||
namespace SweetBunsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class EmployeeDataModelTests
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
|
@ -8,13 +8,6 @@ using SweetBunsContracts.Enums;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
namespace SweetBunsTests.DataModelsTests;
|
||||
|
||||
|
||||
|
||||
|
||||
//Тут поменять под мое и проверить связь многие ко многим надо ли чет менять
|
||||
|
||||
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
@ -22,11 +15,11 @@ internal class ProductDataModelTests
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Blanks,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name",
|
||||
ProductType.Blanks, Guid.NewGuid().ToString(), 10, false);
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Blanks,
|
||||
10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
@ -34,63 +27,54 @@ internal class ProductDataModelTests
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Blanks,
|
||||
Guid.NewGuid().ToString(), 10, false);
|
||||
10, false, CreateSubDataModel());
|
||||
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);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Blanks,
|
||||
10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||
ProductType.Blanks, Guid.NewGuid().ToString(), 10, false);
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Blanks,
|
||||
10, false, CreateSubDataModel());
|
||||
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);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.None,
|
||||
10, false, CreateSubDataModel());
|
||||
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);
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Blanks,
|
||||
0, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name",
|
||||
ProductType.Blanks, Guid.NewGuid().ToString(), -10, false);
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Blanks,
|
||||
-10, false, CreateSubDataModel());
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var sale = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Blanks,
|
||||
0, false, null);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
sale = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Blanks,
|
||||
0, false, []);
|
||||
Assert.That(() => sale.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
@ -98,8 +82,9 @@ internal class ProductDataModelTests
|
||||
var productType = ProductType.Blanks;
|
||||
var productPrice = 10;
|
||||
var productIsDelete = false;
|
||||
var ingredients = CreateSubDataModel();
|
||||
var product = CreateDataModel(productId, productName, productType,
|
||||
productPrice, productIsDelete, );
|
||||
productPrice, productIsDelete, ingredients);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
@ -114,5 +99,7 @@ internal class ProductDataModelTests
|
||||
private static ProductDataModel CreateDataModel(string? id, string?
|
||||
productName, ProductType productType, double price, bool
|
||||
isDeleted, List<ProductIngredientDataModel> ingredients) => new(id, productName, productType, price, isDeleted, ingredients);
|
||||
private static List<ProductIngredientDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), 1, Guid.NewGuid().ToString())];
|
||||
}
|
||||
|
||||
|
@ -3,10 +3,71 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.DataModels;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsTests.DataModelsTests
|
||||
namespace SweetBunsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductIngredietsDataModelTests
|
||||
{
|
||||
internal class ProductIngredientDataModelTests
|
||||
[Test]
|
||||
public void IngredientIdIsNullOrEmptyTest()
|
||||
{
|
||||
var ProductIngredient = CreateDataModel(string.Empty, 1, Guid.NewGuid().ToString());
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ProductIngredient = CreateDataModel(null, 1, Guid.NewGuid().ToString());
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IngredientIdIsNotGuidTest()
|
||||
{
|
||||
var ProductIngredient = CreateDataModel("ingredientId", 1, Guid.NewGuid().ToString());
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var ProductIngredient = CreateDataModel(Guid.NewGuid().ToString(), 1, string.Empty);
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ProductIngredient = CreateDataModel(Guid.NewGuid().ToString(), 1, null);
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var ProductIngredient = CreateDataModel(Guid.NewGuid().ToString(), 1, "productId");
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AmountOfIngredientsIsLessOrZeroTest()
|
||||
{
|
||||
var ProductIngredient = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString());
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
ProductIngredient = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString());
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var amountOfIngredients = 10;
|
||||
var ProductIngredient = CreateDataModel(ingredientId, amountOfIngredients, productId);
|
||||
Assert.That(() => ProductIngredient.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(ProductIngredient.IngredientId, Is.EqualTo(ingredientId));
|
||||
Assert.That(ProductIngredient.AmountOfIngredients, Is.EqualTo(amountOfIngredients));
|
||||
Assert.That(ProductIngredient.ProductId, Is.EqualTo(productId));
|
||||
});
|
||||
}
|
||||
|
||||
private static ProductIngredientDataModel CreateDataModel(string? ingredientId, int amountOfIngredients, string? productId) =>
|
||||
new(ingredientId, amountOfIngredients, productId);
|
||||
}
|
||||
|
@ -3,10 +3,55 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using SweetBunsContracts.DataModels;
|
||||
using SweetBunsContracts.Exceptions;
|
||||
|
||||
namespace SweetBunsTests.DataModelsTests
|
||||
namespace SweetBunsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SalaryDataModelTests
|
||||
{
|
||||
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 SalaryIsLessOrZeroTest()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
@ -1,12 +1 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SweetBunsTests.DataModelsTests
|
||||
{
|
||||
internal class SaleDataModelTests
|
||||
{
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user