init
This commit is contained in:
parent
9ce5690584
commit
7be921eb29
@ -40,19 +40,16 @@
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataModels\CustomerDataModel.cs" />
|
||||
<Compile Include="DataModels\IngredientDataModel.cs" />
|
||||
<Compile Include="DataModels\IngredientStockDataModel.cs" />
|
||||
<Compile Include="DataModels\OrderDataModel.cs" />
|
||||
<Compile Include="DataModels\OrderItemDataModel.cs" />
|
||||
<Compile Include="DataModels\PekarDataModel.cs" />
|
||||
<Compile Include="DataModels\PekarHistoryDataModel.cs" />
|
||||
<Compile Include="DataModels\PositionDataModel.cs" />
|
||||
<Compile Include="DataModels\ProductDataModel.cs" />
|
||||
<Compile Include="DataModels\ProductionDataModel.cs" />
|
||||
<Compile Include="DataModels\ProductStockDataModel.cs" />
|
||||
<Compile Include="DataModels\RecipeDataModel.cs" />
|
||||
<Compile Include="DataModels\SupplyDataModel.cs" />
|
||||
<Compile Include="DataModels\SupplyItemDataModel.cs" />
|
||||
<Compile Include="Enums\ItemType.cs" />
|
||||
<Compile Include="DataModels\SalaryDataModel.cs" />
|
||||
<Compile Include="Enums\PositionType.cs" />
|
||||
<Compile Include="Enums\StatusType.cs" />
|
||||
<Compile Include="Exceptions\ValidationException.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Infrastructure\IValidation.cs" />
|
||||
|
@ -1,36 +0,0 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class CustomerDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string FIO { get; private set; }
|
||||
public string Phone { get; private set; }
|
||||
public string Email { get; private set; }
|
||||
|
||||
public CustomerDataModel(string id, string fio, string phone, string email)
|
||||
{
|
||||
Id = id;
|
||||
FIO = fio;
|
||||
Phone = phone;
|
||||
Email = email;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (Phone.IsEmpty()) throw new ValidationException("Field Phone is empty");
|
||||
|
||||
var phoneRegex = new Regex(@"^\+7\d{10}$");
|
||||
if (!phoneRegex.IsMatch(Phone)) throw new ValidationException("Invalid phone format");
|
||||
|
||||
if (Email.IsEmpty() || !Email.Contains("@")) throw new ValidationException("Invalid email format");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class IngredientStockDataModel : IValidation
|
||||
{
|
||||
public string IngredientId { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
|
||||
public IngredientStockDataModel(string ingredientId, int quantity)
|
||||
{
|
||||
IngredientId = ingredientId;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!IngredientId.IsGuid()) throw new ValidationException("IngredientId must be a GUID");
|
||||
if (Quantity < 0) throw new ValidationException("Quantity cannot be negative");
|
||||
}
|
||||
|
||||
public void AddStock(int amount)
|
||||
{
|
||||
if (amount <= 0) throw new ValidationException("Added quantity must be positive");
|
||||
Quantity += amount;
|
||||
}
|
||||
|
||||
public void RemoveStock(int amount)
|
||||
{
|
||||
if (amount <= 0) throw new ValidationException("Removed quantity must be positive");
|
||||
if (amount > Quantity) throw new ValidationException("Not enough stock available");
|
||||
Quantity -= amount;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
@ -9,40 +10,37 @@ namespace CandyHouseBase.DataModels
|
||||
public class OrderDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string CustomerId { get; private set; } // Может быть null, если клиент разовый
|
||||
public string CustomerName { get; private set; } // Может быть null, если клиент разовый
|
||||
public DateTime OrderDate { get; private set; }
|
||||
public decimal TotalAmount { get; private set; }
|
||||
public decimal DiscountAmount { get; private set; }
|
||||
public List<OrderItemDataModel> OrderItems { get; private set; }
|
||||
public bool IsCompleted { get; private set; }
|
||||
public string OrderId { get; private set; }
|
||||
public string PekarId { get; private set; }
|
||||
public StatusType StatusType { get; private set; }
|
||||
|
||||
public OrderDataModel(string id, string customerId, DateTime orderDate, decimal totalAmount,
|
||||
decimal discountAmount, List<OrderItemDataModel> orderItems, bool isCompleted)
|
||||
public OrderDataModel(string id, string customerName, DateTime orderDate, decimal totalAmount,
|
||||
decimal discountAmount, string orderId, string pekarId, StatusType statusType)
|
||||
{
|
||||
Id = id;
|
||||
CustomerId = customerId;
|
||||
CustomerName = customerName;
|
||||
OrderDate = orderDate;
|
||||
TotalAmount = totalAmount;
|
||||
DiscountAmount = discountAmount;
|
||||
OrderItems = orderItems;
|
||||
IsCompleted = isCompleted;
|
||||
OrderId = orderId;
|
||||
PekarId = pekarId;
|
||||
StatusType = statusType;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (!CustomerId.IsEmpty() && !CustomerId.IsGuid())
|
||||
throw new ValidationException("CustomerId must be a GUID or empty");
|
||||
if (OrderItems == null || OrderItems.Count == 0)
|
||||
throw new ValidationException("Order must contain at least one product");
|
||||
if (CustomerName.IsEmpty())
|
||||
throw new ValidationException("CustomerName is empty");
|
||||
if (TotalAmount < 0) throw new ValidationException("TotalAmount cannot be negative");
|
||||
if (DiscountAmount < 0) throw new ValidationException("DiscountAmount cannot be negative");
|
||||
}
|
||||
|
||||
public void MarkAsCompleted()
|
||||
{
|
||||
IsCompleted = true;
|
||||
if (OrderId.IsEmpty()) throw new ValidationException("Field OrderId is empty");
|
||||
if (!OrderId.IsGuid()) throw new ValidationException("OrderId must be a GUID");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class OrderItemDataModel : IValidation
|
||||
{
|
||||
public string OrderId { get; private set; }
|
||||
public string ProductId { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
public decimal Price { get; private set; } // Цена на момент заказа
|
||||
|
||||
public OrderItemDataModel(string orderId, string productId, int quantity, decimal price)
|
||||
{
|
||||
OrderId = orderId;
|
||||
ProductId = productId;
|
||||
Quantity = quantity;
|
||||
Price = price;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!OrderId.IsGuid()) throw new ValidationException("OrderId must be a GUID");
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("ProductId must be a GUID");
|
||||
if (Quantity <= 0) throw new ValidationException("Quantity must be positive");
|
||||
if (Price < 0) throw new ValidationException("Price cannot be negative");
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,7 @@ namespace CandyHouseBase.DataModels
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (Position.IsEmpty()) throw new ValidationException("Field Position is empty");
|
||||
if (!Position.IsGuid()) throw new ValidationException("Field must be a GUID");
|
||||
if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive");
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
using CandyHouseBase.Extensions;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class PekarHistoryDataModel : IValidation
|
||||
{
|
||||
public string PekarId { get; private set; }
|
||||
public string FIO { get; private set; }
|
||||
public string PositionId { get; private set; }
|
||||
public DateTime Date { get; private set; }
|
||||
public decimal BonusCoefficient { get; private set; }
|
||||
|
||||
public PekarHistoryDataModel(string peKarId, string fio, string positionId, decimal bonusCoefficient, DateTime dateTime)
|
||||
{
|
||||
PekarId = peKarId;
|
||||
FIO = fio;
|
||||
PositionId = positionId;
|
||||
BonusCoefficient = bonusCoefficient;
|
||||
Date = dateTime;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (PekarId.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!PekarId.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty");
|
||||
if (PositionId.IsEmpty()) throw new ValidationException("Field Position is empty");
|
||||
if (!PositionId.IsGuid()) throw new ValidationException("Field must be a GUID");
|
||||
if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class PositionDataModel : IValidation
|
||||
{
|
||||
public string Id { get; set; }
|
||||
public PositionType Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
|
||||
public PositionDataModel(string id, PositionType type, string title)
|
||||
{
|
||||
Id = id;
|
||||
Type = type;
|
||||
Title = title;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (string.IsNullOrEmpty(Title)) throw new ValidationException("Field Title is empty");
|
||||
if (!Enum.IsDefined(typeof(PositionType), Type)) throw new ValidationException("Invalid PositionType");
|
||||
}
|
||||
}
|
||||
}
|
@ -7,8 +7,33 @@ namespace CandyHouseBase.DataModels
|
||||
public class ProductDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string Name { get; private set; }
|
||||
public string Description { get; private set; }
|
||||
|
||||
public string Name
|
||||
{
|
||||
get => name;
|
||||
private set
|
||||
{
|
||||
if (!name.IsEmpty()) OldName = name;
|
||||
name = value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
private set
|
||||
{
|
||||
if (!description.IsEmpty()) OldDescription = description;
|
||||
description = value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public string OldName { get; private set; }
|
||||
|
||||
public string OldDescription { get; private set; }
|
||||
|
||||
private string name;
|
||||
private string description;
|
||||
|
||||
public ProductDataModel(string id, string name, string description)
|
||||
{
|
||||
@ -22,6 +47,7 @@ namespace CandyHouseBase.DataModels
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
|
||||
if (Description.IsEmpty()) throw new ValidationException("Field Description is empty");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class ProductStockDataModel : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
|
||||
public ProductStockDataModel(string productId, int quantity)
|
||||
{
|
||||
ProductId = productId;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("ProductId must be a GUID");
|
||||
if (Quantity < 0) throw new ValidationException("Quantity cannot be negative");
|
||||
}
|
||||
|
||||
public void AddStock(int amount)
|
||||
{
|
||||
if (amount <= 0) throw new ValidationException("Added quantity must be positive");
|
||||
Quantity += amount;
|
||||
}
|
||||
|
||||
public void RemoveStock(int amount)
|
||||
{
|
||||
if (amount <= 0) throw new ValidationException("Removed quantity must be positive");
|
||||
if (amount > Quantity) throw new ValidationException("Not enough stock available");
|
||||
Quantity -= amount;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
using System;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class ProductionDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string PekarId { get; private set; }
|
||||
public string ProductId { get; private set; }
|
||||
public DateTime ProductionDate { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
|
||||
public ProductionDataModel(string id, string pekarId, string productId, DateTime productionDate, int quantity)
|
||||
{
|
||||
Id = id;
|
||||
PekarId = pekarId;
|
||||
ProductId = productId;
|
||||
ProductionDate = productionDate;
|
||||
Quantity = quantity;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (!PekarId.IsGuid()) throw new ValidationException("PekarId must be a GUID");
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("ProductId must be a GUID");
|
||||
if (Quantity <= 0) throw new ValidationException("Quantity must be positive");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class SalaryDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public string PekarId { get; private set; }
|
||||
public DateTime Period { get; private set; }
|
||||
public decimal BaseRate { get; private set; }
|
||||
public decimal BonusRate { get; private set; }
|
||||
public int TotalQuantity { get; private set; }
|
||||
public decimal TotalSalary { get; private set; }
|
||||
|
||||
public SalaryDataModel(string id, string pekarId, DateTime period, decimal baseRate, decimal bonusRate, int totalQuantity, decimal totalSalary)
|
||||
{
|
||||
Id = id;
|
||||
PekarId = pekarId;
|
||||
Period = period;
|
||||
BaseRate = baseRate;
|
||||
BonusRate = bonusRate;
|
||||
TotalQuantity = totalQuantity;
|
||||
TotalSalary = totalSalary;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (PekarId.IsEmpty()) throw new ValidationException("Field PekarId is empty");
|
||||
if (!PekarId.IsGuid()) throw new ValidationException("PekarId must be a GUID");
|
||||
if (BaseRate < 0) throw new ValidationException("BaseRate cannot be negative");
|
||||
if (BonusRate < 0) throw new ValidationException("BonusRate cannot be negative");
|
||||
if (TotalQuantity < 0) throw new ValidationException("TotalQuantity cannot be negative");
|
||||
if (TotalSalary < 0) throw new ValidationException("TotalSalary cannot be negative");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class SupplyDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
public DateTime SupplyDate { get; private set; }
|
||||
public List<SupplyItemDataModel> SupplyItems { get; private set; }
|
||||
|
||||
public SupplyDataModel(string id, DateTime supplyDate, List<SupplyItemDataModel> supplyItems)
|
||||
{
|
||||
Id = id;
|
||||
SupplyDate = supplyDate;
|
||||
SupplyItems = supplyItems;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (SupplyItems == null || SupplyItems.Count == 0) throw new ValidationException("Supply must contain at least one item");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class SupplyItemDataModel : IValidation
|
||||
{
|
||||
public string SupplyId { get; private set; }
|
||||
public string ItemId { get; private set; }
|
||||
public int Quantity { get; private set; }
|
||||
public ItemType ItemType { get; private set; } // 'ingredient' или 'product'
|
||||
|
||||
public SupplyItemDataModel(string supplyId, string itemId, int quantity, ItemType itemType)
|
||||
{
|
||||
SupplyId = supplyId;
|
||||
ItemId = itemId;
|
||||
Quantity = quantity;
|
||||
ItemType = itemType;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (!SupplyId.IsGuid()) throw new ValidationException("SupplyId must be a GUID");
|
||||
if (!ItemId.IsGuid()) throw new ValidationException("ItemId must be a GUID");
|
||||
if (Quantity <= 0) throw new ValidationException("Quantity must be positive");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace CandyHouseBase.Enums
|
||||
{
|
||||
public enum ItemType
|
||||
{
|
||||
Ingredient = 1,
|
||||
Product = 2
|
||||
}
|
||||
}
|
10
CandyHouseSolution/CandyHouseBase/Enums/PositionType.cs
Normal file
10
CandyHouseSolution/CandyHouseBase/Enums/PositionType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace CandyHouseBase.Enums
|
||||
{
|
||||
public enum PositionType
|
||||
{
|
||||
None = 1,
|
||||
Small = 2,
|
||||
Medium = 3,
|
||||
Cool = 4,
|
||||
}
|
||||
}
|
10
CandyHouseSolution/CandyHouseBase/Enums/StatusType.cs
Normal file
10
CandyHouseSolution/CandyHouseBase/Enums/StatusType.cs
Normal file
@ -0,0 +1,10 @@
|
||||
namespace CandyHouseBase.Enums
|
||||
{
|
||||
public enum StatusType
|
||||
{
|
||||
Pending,
|
||||
Completed,
|
||||
Cancelled,
|
||||
InProgress
|
||||
}
|
||||
}
|
@ -101,11 +101,14 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataModelsTests\CustomerDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\IngredientStockDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\IngredientDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\OrderDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\ProductStockDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\SupplyItemDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\PekarDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\PekarHistoryModelDataTests.cs" />
|
||||
<Compile Include="DataModelsTests\PositionDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\ProductDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\RecipeDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\SalaryDataModelTests.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
|
@ -1,55 +0,0 @@
|
||||
using System;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class CustomerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void Customer_ShouldThrowException_WhenIdIsInvalid()
|
||||
{
|
||||
var customerDataModel1 = new CustomerDataModel("", "John Doe", "+79998887766", "john@example.com");
|
||||
var customerDataModel2 =
|
||||
new CustomerDataModel("invalid-guid", "John Doe", "+79998887766", "john@example.com");
|
||||
Assert.Throws<ValidationException>(customerDataModel1.Validate);
|
||||
Assert.Throws<ValidationException>(customerDataModel2.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Customer_ShouldThrowException_WhenFIO_IsEmpty()
|
||||
{
|
||||
var customerDataModel1 =
|
||||
new CustomerDataModel(Guid.NewGuid().ToString(), "", "+79998887766", "john@example.com");
|
||||
Assert.Throws<ValidationException>(customerDataModel1.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Customer_ShouldThrowException_WhenPhone_IsInvalid()
|
||||
{
|
||||
var customerDataModel1 =
|
||||
new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "123456", "john@example.com");
|
||||
Assert.Throws<ValidationException>(customerDataModel1.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Customer_ShouldThrowException_WhenEmail_IsInvalid()
|
||||
{
|
||||
var customerDataModel1 =
|
||||
new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "+79998887766", "invalid-email");
|
||||
Assert.Throws<ValidationException>(customerDataModel1.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Customer_ShouldCreateSuccessfully_WithValidData()
|
||||
{
|
||||
var customer = new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "+79998887766",
|
||||
"john@example.com");
|
||||
Assert.That(customer.FIO, Is.EqualTo("John Doe"));
|
||||
Assert.That(customer.Phone, Is.EqualTo("+79998887766"));
|
||||
Assert.That(customer.Email, Is.EqualTo("john@example.com"));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class IngredientDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateIngredientDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Sugar";
|
||||
var unit = "kg";
|
||||
var cost = 10.5m;
|
||||
|
||||
var ingredient = new IngredientDataModel(id, name, unit, cost);
|
||||
|
||||
Assert.AreEqual(id, ingredient.Id);
|
||||
Assert.AreEqual(name, ingredient.Name);
|
||||
Assert.AreEqual(unit, ingredient.Unit);
|
||||
Assert.AreEqual(cost, ingredient.Cost);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 10);
|
||||
|
||||
Assert.DoesNotThrow(() => ingredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var ingredient = new IngredientDataModel("", "Sugar", "kg", 10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidName_ShouldThrowValidationException()
|
||||
{
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "", "kg", 10);
|
||||
|
||||
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", -5);
|
||||
|
||||
Assert.Throws<ValidationException>(() => ingredient.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class IngredientStockDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IngredientStock_ShouldThrowException_WhenIdIsInvalid()
|
||||
{
|
||||
var stock = new IngredientStockDataModel("", 10);
|
||||
Assert.Throws<ValidationException>(stock.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IngredientStock_ShouldThrowException_WhenQuantityIsNegative()
|
||||
{
|
||||
var stock = new IngredientStockDataModel(Guid.NewGuid().ToString(), -5);
|
||||
Assert.Throws<ValidationException>(stock.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IngredientStock_ShouldAddStockCorrectly()
|
||||
{
|
||||
var stock = new IngredientStockDataModel(Guid.NewGuid().ToString(), 10);
|
||||
stock.AddStock(5);
|
||||
Assert.That(stock.Quantity, Is.EqualTo(15));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IngredientStock_ShouldThrowException_WhenRemovingTooMuchStock()
|
||||
{
|
||||
var stock = new IngredientStockDataModel(Guid.NewGuid().ToString(), 10);
|
||||
Assert.Throws<ValidationException>(() => stock.RemoveStock(15));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
@ -10,32 +10,95 @@ namespace CandyHouseTests.DataModelsTests
|
||||
public class OrderDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void Order_ShouldThrowException_WhenIdIsInvalid()
|
||||
public void CreateOrderDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var orderDataModel = new OrderDataModel("", Guid.NewGuid().ToString(), DateTime.UtcNow,
|
||||
100, 5, new List<OrderItemDataModel>(), false);
|
||||
Assert.Throws<ValidationException>(orderDataModel.Validate);
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var customerName = "Alice";
|
||||
var orderDate = DateTime.Now;
|
||||
var totalAmount = 100.0m;
|
||||
var discountAmount = 10.0m;
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var statusType = StatusType.Pending;
|
||||
|
||||
var order = new OrderDataModel(id, customerName, orderDate, totalAmount, discountAmount, orderId, pekarId, statusType);
|
||||
|
||||
Assert.AreEqual(id, order.Id);
|
||||
Assert.AreEqual(customerName, order.CustomerName);
|
||||
Assert.AreEqual(orderDate, order.OrderDate);
|
||||
Assert.AreEqual(totalAmount, order.TotalAmount);
|
||||
Assert.AreEqual(discountAmount, order.DiscountAmount);
|
||||
Assert.AreEqual(orderId, order.OrderId);
|
||||
Assert.AreEqual(pekarId, order.PekarId);
|
||||
Assert.AreEqual(statusType, order.StatusType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Order_ShouldThrowException_WhenNoItemsInOrder()
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var orderDataModel = new OrderDataModel(Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(), DateTime.UtcNow, 100, 5, new List<OrderItemDataModel>(), false);
|
||||
Assert.Throws<ValidationException>(orderDataModel.Validate);
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Alice",
|
||||
DateTime.Now,
|
||||
100.0m,
|
||||
10.0m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
|
||||
Assert.DoesNotThrow(() => order.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Order_ShouldCreateSuccessfully_WithValidData()
|
||||
public void Validate_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var order = new OrderDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, 200,
|
||||
10, new List<OrderItemDataModel>
|
||||
{
|
||||
new OrderItemDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 2, 50)
|
||||
}, false);
|
||||
var order = new OrderDataModel(
|
||||
"",
|
||||
"Alice",
|
||||
DateTime.Now,
|
||||
100.0m,
|
||||
10.0m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
|
||||
Assert.That(order.TotalAmount, Is.EqualTo(200));
|
||||
Assert.That(order.DiscountAmount, Is.EqualTo(10));
|
||||
Assert.Throws<ValidationException>(() => order.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidCustomerName_ShouldThrowValidationException()
|
||||
{
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"",
|
||||
DateTime.Now,
|
||||
100.0m,
|
||||
10.0m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
|
||||
Assert.Throws<ValidationException>(() => order.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeTotalAmount_ShouldThrowValidationException()
|
||||
{
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Alice",
|
||||
DateTime.Now,
|
||||
-50.0m,
|
||||
10.0m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
|
||||
Assert.Throws<ValidationException>(() => order.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PekarDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreatePekarDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "John Doe";
|
||||
var experience = Guid.NewGuid().ToString();
|
||||
|
||||
var pekar = new PekarDataModel(id, name, experience, 0);
|
||||
|
||||
Assert.AreEqual(id, pekar.Id);
|
||||
Assert.AreEqual(name, pekar.FIO);
|
||||
Assert.AreEqual(experience, pekar.Position);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "John Doe", Guid.NewGuid().ToString(), 6);
|
||||
|
||||
Assert.DoesNotThrow(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel("", "John Doe", Guid.NewGuid().ToString(), 0);
|
||||
|
||||
Assert.Throws<ValidationException>(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidName_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "", Guid.NewGuid().ToString(), 0);
|
||||
|
||||
Assert.Throws<ValidationException>(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeExperience_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "John Doe", "some-invalidate", 0);
|
||||
|
||||
Assert.Throws<ValidationException>(() => pekar.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PekarHistoryModelDataTests
|
||||
{
|
||||
[Test]
|
||||
public void CreatePekarHistoryDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var peKarId = Guid.NewGuid().ToString();
|
||||
var fio = "John Doe";
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var bonusCoefficient = 1.5m;
|
||||
var dateTime = DateTime.Now;
|
||||
|
||||
var peKarHistory = new PekarHistoryDataModel(peKarId, fio, positionId, bonusCoefficient, dateTime);
|
||||
|
||||
Assert.AreEqual(peKarId, peKarHistory.PekarId);
|
||||
Assert.AreEqual(fio, peKarHistory.FIO);
|
||||
Assert.AreEqual(positionId, peKarHistory.PositionId);
|
||||
Assert.AreEqual(bonusCoefficient, peKarHistory.BonusCoefficient);
|
||||
Assert.AreEqual(dateTime, peKarHistory.Date);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class PositionDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreatePositionDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = PositionType.Cool;
|
||||
var title = "Manager";
|
||||
|
||||
var position = new PositionDataModel(id, type, title);
|
||||
|
||||
Assert.AreEqual(id, position.Id);
|
||||
Assert.AreEqual(type, position.Type);
|
||||
Assert.AreEqual(title, position.Title);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatePositionDataModel_InvalidId_ShouldThrowArgumentException()
|
||||
{
|
||||
var invalidId = "";
|
||||
var type = PositionType.Cool;
|
||||
var title = "Manager";
|
||||
var item = new PositionDataModel(invalidId, type, title);
|
||||
|
||||
Assert.Throws<ValidationException>(() => item.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatePositionDataModel_InvalidTitle_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = PositionType.Cool;
|
||||
var invalidTitle = "";
|
||||
var item = new PositionDataModel(id, type, invalidTitle);
|
||||
|
||||
Assert.Throws<ValidationException>(() => item.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateProductDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Candy";
|
||||
var description = "Delicious candy";
|
||||
|
||||
var product = new ProductDataModel(id, name, description);
|
||||
|
||||
Assert.AreEqual(id, product.Id);
|
||||
Assert.AreEqual(name, product.Name);
|
||||
Assert.AreEqual(description, product.Description);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidId_ShouldThrowArgumentException()
|
||||
{
|
||||
var invalidId = "";
|
||||
var name = "Candy";
|
||||
var description = "Delicious candy";
|
||||
var product = new ProductDataModel(invalidId, name, description);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidName_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var invalidName = "";
|
||||
var description = "Delicious candy";
|
||||
var product = new ProductDataModel(id, invalidName, description);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Candy";
|
||||
var invalidDescription = "";
|
||||
var product = new ProductDataModel(id, name, invalidDescription);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ProductStockDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductStock_ShouldThrowException_WhenIdIsInvalid()
|
||||
{
|
||||
var productStockDataModel = new ProductStockDataModel("", 10);
|
||||
Assert.Throws<ValidationException>(productStockDataModel.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductStock_ShouldThrowException_WhenQuantityIsNegative()
|
||||
{
|
||||
var productStockDataModel = new ProductStockDataModel(Guid.NewGuid().ToString(), -5);
|
||||
Assert.Throws<ValidationException>(productStockDataModel.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductStock_ShouldAddStockCorrectly()
|
||||
{
|
||||
var stock = new ProductStockDataModel(Guid.NewGuid().ToString(), 10);
|
||||
stock.AddStock(5);
|
||||
Assert.That(stock.Quantity, Is.EqualTo(15));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductStock_ShouldThrowException_WhenRemovingTooMuchStock()
|
||||
{
|
||||
var stock = new ProductStockDataModel(Guid.NewGuid().ToString(), 10);
|
||||
Assert.Throws<ValidationException>(() => stock.RemoveStock(15));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class RecipeDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateRecipeDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var quantity = 5;
|
||||
|
||||
var recipe = new RecipeDataModel(productId, ingredientId, quantity);
|
||||
|
||||
Assert.AreEqual(productId, recipe.ProductId);
|
||||
Assert.AreEqual(ingredientId, recipe.IngredientId);
|
||||
Assert.AreEqual(quantity, recipe.Quantity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateRecipeDataModel_InvalidProductId_ShouldThrowValidationException()
|
||||
{
|
||||
var invalidProductId = "";
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var quantity = 5;
|
||||
var recipe = new RecipeDataModel(invalidProductId, ingredientId, quantity);
|
||||
|
||||
Assert.Throws<ValidationException>(() => recipe.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateRecipeDataModel_InvalidIngredientId_ShouldThrowValidationException()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var invalidIngredientId = "";
|
||||
var quantity = 5;
|
||||
var recipe = new RecipeDataModel(productId, invalidIngredientId, quantity);
|
||||
|
||||
Assert.Throws<ValidationException>(() => recipe.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateRecipeDataModel_InvalidQuantity_ShouldThrowValidationException()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var invalidQuantity = -1;
|
||||
var recipe = new RecipeDataModel(productId, ingredientId, invalidQuantity);
|
||||
|
||||
Assert.Throws<ValidationException>(() => recipe.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
public class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateSalaryDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var period = new DateTime(2023, 10, 1);
|
||||
var baseRate = 1000m;
|
||||
var bonusRate = 200m;
|
||||
var totalQuantity = 50;
|
||||
var totalSalary = 1200m;
|
||||
|
||||
var salaryData = new SalaryDataModel(id, pekarId, period, baseRate, bonusRate, totalQuantity, totalSalary);
|
||||
|
||||
Assert.AreEqual(id, salaryData.Id);
|
||||
Assert.AreEqual(pekarId, salaryData.PekarId);
|
||||
Assert.AreEqual(period, salaryData.Period);
|
||||
Assert.AreEqual(baseRate, salaryData.BaseRate);
|
||||
Assert.AreEqual(bonusRate, salaryData.BonusRate);
|
||||
Assert.AreEqual(totalQuantity, salaryData.TotalQuantity);
|
||||
Assert.AreEqual(totalSalary, salaryData.TotalSalary);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateSalaryDataModel_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var invalidId = "";
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var period = new DateTime(2023, 10, 1);
|
||||
var baseRate = 1000m;
|
||||
var bonusRate = 200m;
|
||||
var totalQuantity = 50;
|
||||
var totalSalary = 1200m;
|
||||
var salary = new SalaryDataModel(invalidId, pekarId, period, baseRate, bonusRate, totalQuantity,
|
||||
totalSalary);
|
||||
Assert.Throws<ValidationException>(() => salary.Validate());}
|
||||
|
||||
[Test]
|
||||
public void CreateSalaryDataModel_InvalidBaseRate_ShouldThrowValidationException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var period = new DateTime(2023, 10, 1);
|
||||
var invalidBaseRate = -1000m;
|
||||
var bonusRate = 200m;
|
||||
var totalQuantity = 50;
|
||||
var totalSalary = 1200m;
|
||||
var salary = new SalaryDataModel(id, pekarId, period, invalidBaseRate, bonusRate, totalQuantity,
|
||||
totalSalary);
|
||||
Assert.Throws<ValidationException>(() => salary.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,43 +0,0 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class SupplyItemDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void SupplyItem_ShouldThrowException_WhenSupplyIdIsInvalid()
|
||||
{
|
||||
var supplyItem = new SupplyItemDataModel("", Guid.NewGuid().ToString(), 10, ItemType.Ingredient);
|
||||
Assert.Throws<ValidationException>(supplyItem.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyItem_ShouldThrowException_WhenItemIdIsInvalid()
|
||||
{
|
||||
var supplyItem = new SupplyItemDataModel(Guid.NewGuid().ToString(), "", 10, ItemType.Product);
|
||||
Assert.Throws<ValidationException>(supplyItem.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyItem_ShouldThrowException_WhenQuantityIsZeroOrNegative()
|
||||
{
|
||||
var supplyItem = new SupplyItemDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0,
|
||||
ItemType.Product);
|
||||
Assert.Throws<ValidationException>(supplyItem.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplyItem_ShouldCreateSuccessfully_WithValidData()
|
||||
{
|
||||
var supplyItem = new SupplyItemDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10,
|
||||
ItemType.Ingredient);
|
||||
Assert.That(supplyItem.Quantity, Is.EqualTo(10));
|
||||
Assert.That(supplyItem.ItemType, Is.EqualTo(ItemType.Ingredient));
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user