Compare commits

...

1 Commits

Author SHA1 Message Date
Dariaaaa6
3ff087e5d7 1 лаба 2025-03-06 14:23:41 +04:00
37 changed files with 1228 additions and 2 deletions

@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BitterAndExclamationMarkContracts\BitterAndExclamationMarkContracts.csproj" />
<ProjectReference Include="..\BitterAndExclamationMarkTests\BitterAndExclamationMarkTests.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,23 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkApp
{
class Program
{
static void Main(string[] args)
{
try
{
var customer = new CustomerDataModel("123", "John Doe", "1234567890", 100);
customer.Validate();
Console.WriteLine("Customer data is valid!");
}
catch (ValidationException ex)
{
Console.WriteLine($"Validation error: {ex.Message}");
}
}
}
}

@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitterAndExclamationMarkContracts", "BitterAndExclamationMarkContracts\BitterAndExclamationMarkContracts.csproj", "{59367E72-D9F7-4148-99FE-A235A0AB34FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BitterAndExclamationMarkContracts", "BitterAndExclamationMarkContracts\BitterAndExclamationMarkContracts.csproj", "{59367E72-D9F7-4148-99FE-A235A0AB34FB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitterAndExclamationMarkTests", "BitterAndExclamationMarkTests\BitterAndExclamationMarkTests.csproj", "{C0628CA0-472B-4765-BA24-6610464313F3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -15,6 +17,10 @@ Global
{59367E72-D9F7-4148-99FE-A235A0AB34FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{59367E72-D9F7-4148-99FE-A235A0AB34FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{59367E72-D9F7-4148-99FE-A235A0AB34FB}.Release|Any CPU.Build.0 = Release|Any CPU
{C0628CA0-472B-4765-BA24-6610464313F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0628CA0-472B-4765-BA24-6610464313F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0628CA0-472B-4765-BA24-6610464313F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0628CA0-472B-4765-BA24-6610464313F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

@ -0,0 +1,31 @@
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Exceptions;
using System.Text.RegularExpressions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class CustomerDataModel(string id, string fullName, string phoneNumber, string email, List<OrderDataModel> orders) : IValidation
{
public string Id { get; private set; } = id;
public string FullName { get; private set; } = fullName;
public string PhoneNumber { get; private set; } = phoneNumber;
public string Email { get; private set; } = email;
public List<OrderDataModel> Orders { get; private set; } = orders;
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 (FullName.IsEmpty())
throw new ValidationException("Field FullName is empty");
if (PhoneNumber.IsEmpty())
throw new ValidationException("Field PhoneNumber is empty");
if (!Regex.IsMatch(Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$"))
throw new ValidationException("Field Email is not a email");
if ((Orders?.Count ?? 0) == 0)
throw new ValidationException("The customer must include orders");
}
}

@ -0,0 +1,29 @@
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class DishDataModel(string id, string name, DishCategory category, decimal price) : IValidation
{
public string Id { get; private set; } = id;
public string Name { get; private set; } = name;
public DishCategory Category { get; private set; } = category;
public decimal Price { get; private set; } = price;
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 (Name.IsEmpty())
throw new ValidationException("Field Name is empty");
if (Category == DishCategory.None)
throw new ValidationException("Field Category is empty");
if (Price <= 0)
throw new ValidationException("Field Price must be greater than zero");
}
}

@ -0,0 +1,27 @@
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Exceptions;
using BitterAndExclamationMarkContracts.Extensions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class DishHistoryDataModel(string dishId, decimal oldPrice, DateTime changeDate) : IValidation
{
public string DishId { get; private set; } = dishId;
public decimal OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = changeDate;
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 must be greater than 0");
if (ChangeDate > DateTime.UtcNow)
throw new ValidationException("Field ChangeDate cannot be in the future");
}
}

@ -0,0 +1,32 @@
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class EmployeeDataModel(string id, string fullName, DateTime birthDate, DateTime hireDate, List<OrderDataModel> orders) : IValidation
{
public string Id { get; private set; } = id;
public string FullName { get; private set; } = fullName;
public DateTime BirthDate { get; private set; } = birthDate;
public DateTime HireDate { get; private set; } = hireDate;
public List<OrderDataModel> Orders { get; set; } = orders;
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 (FullName.IsEmpty())
throw new ValidationException("Field FullName is empty");
if (BirthDate.Date > DateTime.Now.AddYears(-16).Date)
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
if (HireDate.Date < BirthDate.Date)
throw new ValidationException("The date of employment cannot be less than the date of birth");
if ((HireDate - BirthDate).TotalDays / 365 < 16)
throw new ValidationException($"Minors cannot be hired (HireDate - {HireDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
if ((Orders?.Count ?? 0) == 0)
throw new ValidationException("The employeer must include orders");
}
}

@ -0,0 +1,33 @@
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Infrastructure;
namespace BitterAndExclamationMarkContracts.DataModels;
public class EmployeeRoleDataModel(string id, string employeerId, EmployeeRole role, decimal salary, DateTime changeDate, bool isActual) : IValidation
{
public string Id { get; private set; } = id;
public string EmployeerId { get; private set; } = employeerId;
public EmployeeRole Role { get; private set; } = role;
public decimal Salary { get; private set; } = salary;
public DateTime ChangeDate { get; private set; } = changeDate;
public bool IsActual { get; private set; } = isActual;
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 (EmployeerId.IsEmpty())
throw new ValidationException("Field EmployeerId is empty");
if (!EmployeerId.IsGuid())
throw new ValidationException("The value in the field EmployeerId is not a unique identifier");
if (Role == EmployeeRole.None)
throw new ValidationException("Field Role is empty");
if (Salary < 0)
throw new ValidationException("Field Salary cannot be negative");
if (ChangeDate > DateTime.UtcNow)
throw new ValidationException("Field ChangeDate cannot be in the future");
}
}

@ -0,0 +1,26 @@
using BitterAndExclamationMarkContracts.Exceptions;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Infrastructure;
namespace BitterAndExclamationMarkContracts.DataModels;
public class LoyaltyProgramDataModel(string id, int loyaltyPoints, string customerId) : IValidation
{
public string Id { get; private set; } = id;
public int LoyaltyPoints { get; private set; } = loyaltyPoints;
public string CustomerId { get; private set; } = customerId;
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 (LoyaltyPoints < 0)
throw new ValidationException("Field LoyaltyPoints cannot be negative");
if (CustomerId.IsEmpty())
throw new ValidationException("Field CustomerId is empty");
if (!CustomerId.IsGuid())
throw new ValidationException("The value in the field CustomerId is not a unique identifier");
}
}

@ -0,0 +1,36 @@
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class OrderDataModel(string id, string customerId, string employeeId, OrderStatus status, List<OrderDishDataModel> orderDishes) : IValidation
{
public string Id { get; private set; } = id;
public string CustomerId { get; private set; } = customerId;
public string EmployeeId { get; private set; } = employeeId;
public DateTime OrderDate { get; private set; } = DateTime.UtcNow;
public OrderStatus Status { get; private set; } = status;
public List<OrderDishDataModel> OrderDishes { get; set; } = orderDishes;
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 (CustomerId.IsEmpty())
throw new ValidationException("Field CustomerId is empty");
if (!CustomerId.IsGuid())
throw new ValidationException("The value in the field CustomerId is not a unique identifier");
if (EmployeeId.IsEmpty())
throw new ValidationException("Field EmployeeId is empty");
if (!EmployeeId.IsGuid())
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
if (Status == OrderStatus.Unknown)
throw new ValidationException("Field Status is empty");
if ((OrderDishes?.Count ?? 0) == 0)
throw new ValidationException("The order must include orders");
}
}

@ -0,0 +1,29 @@
using BitterAndExclamationMarkContracts.Infrastructure;
using BitterAndExclamationMarkContracts.Extensions;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.DataModels;
public class OrderDishDataModel(string id, string orderId, string dishId, int quantity) : IValidation
{
public string Id { get; private set; } = id;
public string OrderId { get; private set; } = orderId;
public string DishId { get; private set; } = dishId;
public int Quantity { get; private set; } = quantity;
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 (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?.IsGuid() ?? !DishId?.IsEmpty() ?? false)
throw new ValidationException("The value in the field BuyerId is not a unique identifier");
if (Quantity <= 0)
throw new ValidationException("Field Sum is less than or equal to 0");
}
}

@ -0,0 +1,9 @@
namespace BitterAndExclamationMarkContracts.Enums;
public enum DishCategory
{
None,
HotDishes,
Beverages,
Desserts
}

@ -0,0 +1,9 @@
namespace BitterAndExclamationMarkContracts.Enums;
public enum EmployeeRole
{
None,
Cashier,
Cook,
Janitor
}

@ -0,0 +1,9 @@
namespace BitterAndExclamationMarkContracts.Enums;
public enum OrderStatus
{
Unknown = 0,
Accepted,
InPreparation,
Issued
}

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BitterAndExclamationMarkContracts.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BitterAndExclamationMarkContracts.Extensions;
public static class StringExtensions
{
public static bool IsEmpty(this string value)
{
return string.IsNullOrEmpty(value);
}
public static bool IsGuid(this string value)
{
return Guid.TryParse(value, out _);
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BitterAndExclamationMarkContracts.Infrastructure;
public interface IValidation
{
void Validate();
}

@ -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.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BitterAndExclamationMarkContracts\BitterAndExclamationMarkContracts.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>

@ -0,0 +1 @@
global using NUnit.Framework;

@ -0,0 +1,98 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class CustomerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var customer = CreateDataModel(null, "fullname", "number", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
customer = CreateDataModel(string.Empty, "fullname", "number", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var customer = CreateDataModel("id", "fullname", "number", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void FullNameIsNullOrEmptyTest()
{
var customer = CreateDataModel(Guid.NewGuid().ToString(), null, "number", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
customer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsNullOrEmptyTest()
{
var customer = CreateDataModel(Guid.NewGuid().ToString(), "fullname", null, "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
customer = CreateDataModel(Guid.NewGuid().ToString(), "fullname", string.Empty, "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void EmailIsIncorrectTest()
{
var customer = CreateDataModel(Guid.NewGuid().ToString(), "fullname", "7777777777", "email", CreateSubDataModel());
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductsIsNullOrEmptyTest()
{
var customer = CreateDataModel(Guid.NewGuid().ToString(), "fullname", "7777777777", "email", null);
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
customer = CreateDataModel(Guid.NewGuid().ToString(), "fullname", "7777777777", "email", []);
Assert.That(() => customer.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var customerId = Guid.NewGuid().ToString();
var fullname = "fullname";
var phoneNumber = "77777777777";
var email = "testmail@gmail.com";
var orders = CreateSubDataModel();
var customer = CreateDataModel(customerId, fullname, phoneNumber, email, orders);
Assert.That(() => customer.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(customer.Id, Is.EqualTo(customerId));
Assert.That(customer.FullName, Is.EqualTo(fullname));
Assert.That(customer.PhoneNumber, Is.EqualTo(phoneNumber));
Assert.That(customer.Email, Is.EqualTo(email));
Assert.That(customer.Orders, Is.EquivalentTo(orders));
});
}
private static CustomerDataModel CreateDataModel(string? id, string? fullname, string? phoneNumber, string? email, List<OrderDataModel>? orders) => new(id, fullname, phoneNumber, email, orders);
private static List<OrderDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubSubDataModel())];
private static List<OrderDishDataModel> CreateSubSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

@ -0,0 +1,72 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class DishDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var dish = CreateDataModel(null, "DishName", DishCategory.Desserts, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
dish = CreateDataModel(string.Empty, "DishName", DishCategory.Desserts, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var dish = CreateDataModel("id", "DishName", DishCategory.Desserts, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void NameIsNullOrEmptyTest()
{
var dish = CreateDataModel(Guid.NewGuid().ToString(), null, DishCategory.Desserts, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
dish = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DishCategory.Desserts, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsNegativeOrZeroTest()
{
var dish = CreateDataModel(Guid.NewGuid().ToString(), "DishName", DishCategory.Desserts, -1m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
dish = CreateDataModel(Guid.NewGuid().ToString(), "DishName", DishCategory.Desserts, 0m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CategoryIsNoneTest()
{
var dish = CreateDataModel(Guid.NewGuid().ToString(), "DishName", DishCategory.None, 10m);
Assert.That(() => dish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var dishId = Guid.NewGuid().ToString();
var name = "DishName";
var category = DishCategory.Desserts;
var price = 10m;
var orderDishes = CreateSubDataModel();
var dish = CreateDataModel(dishId, name, category, price);
Assert.That(() => dish.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(dish.Id, Is.EqualTo(dishId));
Assert.That(dish.Name, Is.EqualTo(name));
Assert.That(dish.Category, Is.EqualTo(category));
Assert.That(dish.Price, Is.EqualTo(price));
});
}
private static DishDataModel CreateDataModel(string? id, string? name, DishCategory category, decimal price) => new(id, name, category, price);
private static List<OrderDishDataModel> CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

@ -0,0 +1,61 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class DishHistoryDataModelTests
{
[Test]
public void DishIdIsNullOrEmptyTest()
{
var dishHistory = CreateDataModel(null, 10, DateTime.UtcNow);
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
dishHistory = CreateDataModel(string.Empty, 10, DateTime.UtcNow);
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DishIdIsNotGuidTest()
{
var dishHistory = CreateDataModel("id", 10, DateTime.UtcNow);
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OldPriceIsLessOrZeroTest()
{
var dishHistory = CreateDataModel(Guid.NewGuid().ToString(), 0, DateTime.UtcNow);
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
dishHistory = CreateDataModel(Guid.NewGuid().ToString(), -10, DateTime.UtcNow);
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ChangeDateIsInFutureTest()
{
var dishHistory = CreateDataModel(Guid.NewGuid().ToString(), 10, DateTime.UtcNow.AddMinutes(10));
Assert.That(() => dishHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var dishId = Guid.NewGuid().ToString();
var oldPrice = 10;
var changeDate = DateTime.UtcNow;
var dishHistory = CreateDataModel(dishId, oldPrice, changeDate);
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.LessThanOrEqualTo(DateTime.UtcNow));
});
}
private static DishHistoryDataModel CreateDataModel(string? dishId, decimal oldPrice, DateTime changeDate) =>
new(dishId, oldPrice, changeDate);
}

@ -0,0 +1,87 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class EmployeeDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var employee = CreateDataModel(null, "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(string.Empty, "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var employee = CreateDataModel("id", "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FullNameIsNullOrEmptyTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateIsUnder16Test()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fullname", DateTime.Now.AddYears(-15), DateTime.Now.AddYears(-10), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void HireDateBeforeBirthDateTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-25), CreateSubDataModel());
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OrdersIsNullOrEmptyTest()
{
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), null);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
employee = CreateDataModel(Guid.NewGuid().ToString(), "fullname", DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-10), []);
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var employeeId = Guid.NewGuid().ToString();
var fullname = "fullname";
var birthDate = DateTime.Now.AddYears(-25);
var hireDate = DateTime.Now.AddYears(-5);
var orders = CreateSubDataModel();
var employee = CreateDataModel(employeeId, fullname, birthDate, hireDate, orders);
Assert.That(() => employee.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(employee.Id, Is.EqualTo(employeeId));
Assert.That(employee.FullName, Is.EqualTo(fullname));
Assert.That(employee.BirthDate, Is.EqualTo(birthDate));
Assert.That(employee.HireDate, Is.EqualTo(hireDate));
Assert.That(employee.Orders, Is.EquivalentTo(orders));
});
}
private static EmployeeDataModel CreateDataModel(string? id, string? fullName, DateTime birthDate, DateTime hireDate, List<OrderDataModel>? orders)
=> new(id, fullName, birthDate, hireDate, orders);
private static List<OrderDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubSubDataModel())];
private static List<OrderDishDataModel> CreateSubSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

@ -0,0 +1,88 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class EmployeeRoleDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var employeeRole = CreateDataModel(null, Guid.NewGuid().ToString(), EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
employeeRole = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var employeeRole = CreateDataModel("id", Guid.NewGuid().ToString(), EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeerIdIsNullOrEmptyTest()
{
var employeeRole = CreateDataModel(Guid.NewGuid().ToString(), null, EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
employeeRole = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeerIdIsNotGuidTest()
{
var employeeRole = CreateDataModel(Guid.NewGuid().ToString(), "id", EmployeeRole.Cook, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void RoleIsNoneTest()
{
var employeeRole = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), EmployeeRole.None, 10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SalaryIsNegativeTest()
{
var employeeRole = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), EmployeeRole.None, -10, DateTime.UtcNow, true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ChangeDateIsInFutureTest()
{
var employeeRole = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), EmployeeRole.None, 10, DateTime.UtcNow.AddDays(10), true);
Assert.That(() => employeeRole.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var employeerId = Guid.NewGuid().ToString();
var role = EmployeeRole.Cook;
var salary = 10;
var changeDate = DateTime.UtcNow;
var isActual = true;
var employeeRole = CreateDataModel(id, employeerId, role, salary, changeDate, isActual);
Assert.That(() => employeeRole.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(employeeRole.Id, Is.EqualTo(id));
Assert.That(employeeRole.EmployeerId, Is.EqualTo(employeerId));
Assert.That(employeeRole.Role, Is.EqualTo(role));
Assert.That(employeeRole.Salary, Is.EqualTo(salary));
Assert.That(employeeRole.ChangeDate, Is.LessThanOrEqualTo(changeDate));
Assert.That(employeeRole.IsActual, Is.LessThanOrEqualTo(isActual));
});
}
private static EmployeeRoleDataModel CreateDataModel(string? id, string? employeerId, EmployeeRole role, decimal salary, DateTime changeDate, bool isActual) => new(id, employeerId, role, salary, changeDate, isActual);
}

@ -0,0 +1,68 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class LoyaltyProgramDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var loyalty = CreateDataModel(null, 2, Guid.NewGuid().ToString());
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
loyalty = CreateDataModel(string.Empty, 2, Guid.NewGuid().ToString());
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var loyalty = CreateDataModel("id", 2, Guid.NewGuid().ToString());
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void LoyaltyPointsIsNegativeTest()
{
var loyalty = CreateDataModel(Guid.NewGuid().ToString(), -1, Guid.NewGuid().ToString());
Assert.That(() => loyalty.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void CustomerIdIsNullOrEmptyTest()
{
var loyalty = CreateDataModel(Guid.NewGuid().ToString(), 2, null);
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
loyalty = CreateDataModel(Guid.NewGuid().ToString(), 2, string.Empty);
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CustomerIdIsNotGuidTest()
{
var loyalty = CreateDataModel(Guid.NewGuid().ToString(), 2, "id");
Assert.That(() => loyalty.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var loyaltyPoints = 1;
var customerId = Guid.NewGuid().ToString();
var model = CreateDataModel(id, loyaltyPoints, customerId);
Assert.DoesNotThrow(() => model.Validate());
Assert.Multiple(() =>
{
Assert.That(model.Id, Is.EqualTo(id));
Assert.That(model.LoyaltyPoints, Is.EqualTo(loyaltyPoints));
Assert.That(model.CustomerId, Is.EqualTo(customerId));
});
}
private static LoyaltyProgramDataModel CreateDataModel(string? id, int loyaltyPoints, string? customerId) =>
new(id, loyaltyPoints, customerId);
}

@ -0,0 +1,99 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class OrderDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var order = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var order = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CustomerIdIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CustomerIdIsNotGuidTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), "customer", Guid.NewGuid().ToString(), OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeeIdIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void EmployeeIdIsNotGuidTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "employee", OrderStatus.Accepted, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StatusIsUnknownTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Unknown, CreateSubDataModel());
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OrderDishesIsNullOrEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, null);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), OrderStatus.Accepted, []);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var orderId = Guid.NewGuid().ToString();
var customerId = Guid.NewGuid().ToString();
var employeeId = Guid.NewGuid().ToString();
var status = OrderStatus.Accepted;
var orderDishes = CreateSubDataModel();
var order = CreateDataModel(orderId, customerId, employeeId, status, orderDishes);
Assert.That(() => order.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(order.Id, Is.EqualTo(orderId));
Assert.That(order.CustomerId, Is.EqualTo(customerId));
Assert.That(order.EmployeeId, Is.EqualTo(employeeId));
Assert.That(order.Status, Is.EqualTo(status));
Assert.That(order.OrderDishes, Is.EquivalentTo(orderDishes));
});
}
private static OrderDataModel CreateDataModel(string? id, string? customerId, string? employeeId, OrderStatus status, List<OrderDishDataModel>? orderDishes)
=> new(id, customerId, employeeId, status, orderDishes);
private static List<OrderDishDataModel> CreateSubDataModel()
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
}

@ -0,0 +1,69 @@
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkTests.DataModelsTests;
[TestFixture]
internal class OrderDishDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel(null, "orderId", "dishId", 1).Validate());
Assert.Throws<ValidationException>(() => CreateDataModel(string.Empty, "orderId", "dishId", 1).Validate());
}
[Test]
public void IdIsNotGuidTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel("invalid", "orderId", "dishId", 1).Validate());
}
[Test]
public void OrderIdIsNullOrEmptyTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), null, "dishId", 1).Validate());
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "dishId", 1).Validate());
}
[Test]
public void OrderIdIsNotGuidTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid", "dishId", 1).Validate());
}
[Test]
public void DishIdIsNotGuidTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid", 1).Validate());
}
[Test]
public void QuantityIsZeroOrNegativeTest()
{
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0).Validate());
Assert.Throws<ValidationException>(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1).Validate());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var orderId = Guid.NewGuid().ToString();
var dishId = Guid.NewGuid().ToString();
var quantity = 1;
var model = CreateDataModel(id, orderId, dishId, quantity);
Assert.DoesNotThrow(() => model.Validate());
Assert.Multiple(() =>
{
Assert.That(model.Id, Is.EqualTo(id));
Assert.That(model.OrderId, Is.EqualTo(orderId));
Assert.That(model.DishId, Is.EqualTo(dishId));
Assert.That(model.Quantity, Is.EqualTo(quantity));
});
}
private static OrderDishDataModel CreateDataModel(string? id, string? orderId, string? dishId, int quantity) =>
new(id, orderId, dishId, quantity);
}

@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\BitterAndExclamationMarkContracts\BitterAndExclamationMarkContracts.csproj" />
</ItemGroup>
</Project>

@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Enums;
using BitterAndExclamationMarkContracts.Exceptions;
namespace YourExecutableProject
{
class Program
{
static void Main(string[] args)
{
var productIds = new List<string> { "product1", "product2" };
var order = new OrderDataModel(
id: "order123",
customerId: "customer1",
employeeId: "employee1",
productIds: productIds,
discountType: DiscountType.OnSale, // Используем существующее значение
status: OrderStatus.New,
orderDate: DateTime.Now
);
try
{
order.Validate();
Console.WriteLine("Order is valid.");
}
catch (BitterAndExclamationMarkContracts.Exceptions.ValidationException ex) // Уточняем тип
{
Console.WriteLine($"Validation failed: {ex.Message}");
}
}
}
}

@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.9.34622.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitterAndExclamationMarkTests", "BitterAndExclamationMarkTests\BitterAndExclamationMarkTests.csproj", "{32DAD29B-E0E7-4BAD-BAE8-02D8772CC901}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{32DAD29B-E0E7-4BAD-BAE8-02D8772CC901}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32DAD29B-E0E7-4BAD-BAE8-02D8772CC901}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32DAD29B-E0E7-4BAD-BAE8-02D8772CC901}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32DAD29B-E0E7-4BAD-BAE8-02D8772CC901}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {F4E504DC-A994-4870-8AE9-61106A840E09}
EndGlobalSection
EndGlobal

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -0,0 +1,23 @@
using NUnit.Framework;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.Tests;
[TestFixture]
public class CustomerDataModelTests
{
[Test]
public void Validate_ThrowsException_WhenPhoneNumberIsEmpty()
{
var customer = new CustomerDataModel("123", "John Doe", "", 100);
Assert.Throws<ValidationException>(() => customer.Validate());
}
[Test]
public void Validate_DoesNotThrow_WhenAllFieldsAreValid()
{
var customer = new CustomerDataModel("123", "John Doe", "+123456789", 100);
Assert.DoesNotThrow(() => customer.Validate());
}
}

@ -0,0 +1,23 @@
using NUnit.Framework;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.Tests;
[TestFixture]
public class DishDataModelTests
{
[Test]
public void Validate_ThrowsException_WhenPriceIsZero()
{
var dish = new DishDataModel("123", "Pizza", 0, "Main");
Assert.Throws<ValidationException>(() => dish.Validate());
}
[Test]
public void Validate_DoesNotThrow_WhenAllFieldsAreValid()
{
var dish = new DishDataModel("123", "Pizza", 10.99, "Main");
Assert.DoesNotThrow(() => dish.Validate());
}
}

@ -0,0 +1,23 @@
using NUnit.Framework;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.Tests;
[TestFixture]
public class EmployeeDataModelTests
{
[Test]
public void Validate_ThrowsException_WhenHireDateIsInFuture()
{
var employee = new EmployeeDataModel("123", "Jane Doe", "Waiter", DateTime.Now.AddDays(1));
Assert.Throws<ValidationException>(() => employee.Validate());
}
[Test]
public void Validate_DoesNotThrow_WhenAllFieldsAreValid()
{
var employee = new EmployeeDataModel("123", "Jane Doe", "Waiter", DateTime.Now);
Assert.DoesNotThrow(() => employee.Validate());
}
}

@ -0,0 +1,24 @@
using NUnit.Framework;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
using System.Collections.Generic;
namespace BitterAndExclamationMarkContracts.Tests;
[TestFixture]
public class OrderDataModelTests
{
[Test]
public void Validate_ThrowsException_WhenDishIdsAreEmpty()
{
var order = new OrderDataModel("123", "456", "789", new List<string>(), DateTime.Now);
Assert.Throws<ValidationException>(() => order.Validate());
}
[Test]
public void Validate_DoesNotThrow_WhenAllFieldsAreValid()
{
var order = new OrderDataModel("123", "456", "789", new List<string> { "101" }, DateTime.Now);
Assert.DoesNotThrow(() => order.Validate());
}
}

@ -0,0 +1,23 @@
using NUnit.Framework;
using BitterAndExclamationMarkContracts.DataModels;
using BitterAndExclamationMarkContracts.Exceptions;
namespace BitterAndExclamationMarkContracts.Tests;
[TestFixture]
public class SalaryDataModelTests
{
[Test]
public void Validate_ThrowsException_WhenAmountIsZero()
{
var salary = new SalaryDataModel("123", "456", 0, DateTime.Now);
Assert.Throws<ValidationException>(() => salary.Validate());
}
[Test]
public void Validate_DoesNotThrow_WhenAllFieldsAreValid()
{
var salary = new SalaryDataModel("123", "456", 1000, DateTime.Now);
Assert.DoesNotThrow(() => salary.Validate());
}
}