lab1 + hard

This commit is contained in:
LivelyPuer 2025-02-12 22:16:56 +04:00
parent 2261d1e666
commit 48da4621c6
25 changed files with 835 additions and 0 deletions

View File

@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CandyHouseBase</RootNamespace>
<AssemblyName>CandyHouseBase</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Data"/>
<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\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="Exceptions\ValidationException.cs" />
<Compile Include="Extensions\StringExtensions.cs" />
<Compile Include="Infrastructure\IValidation.cs" />
<Compile Include="Program.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,36 @@
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");
}
}
}

View File

@ -0,0 +1,31 @@
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
namespace CandyHouseBase.DataModels
{
public class IngredientDataModel : IValidation
{
public string Id { get; private set; }
public string Name { get; private set; }
public string Unit { get; private set; }
public decimal Cost { get; private set; }
public IngredientDataModel(string id, string name, string unit, decimal cost)
{
Id = id;
Name = name;
Unit = unit;
Cost = cost;
}
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 (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
if (Unit.IsEmpty()) throw new ValidationException("Field Unit is empty");
if (Cost < 0) throw new ValidationException("Cost must be non-negative");
}
}
}

View File

@ -0,0 +1,37 @@
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;
}
}
}

View File

@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
namespace CandyHouseBase.DataModels
{
public class OrderDataModel : IValidation
{
public string Id { get; private set; }
public string CustomerId { 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 OrderDataModel(string id, string customerId, DateTime orderDate, decimal totalAmount,
decimal discountAmount, List<OrderItemDataModel> orderItems, bool isCompleted)
{
Id = id;
CustomerId = customerId;
OrderDate = orderDate;
TotalAmount = totalAmount;
DiscountAmount = discountAmount;
OrderItems = orderItems;
IsCompleted = isCompleted;
}
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 (TotalAmount < 0) throw new ValidationException("TotalAmount cannot be negative");
if (DiscountAmount < 0) throw new ValidationException("DiscountAmount cannot be negative");
}
public void MarkAsCompleted()
{
IsCompleted = true;
}
}
}

View File

@ -0,0 +1,30 @@
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");
}
}
}

View File

@ -0,0 +1,31 @@
using CandyHouseBase.Exceptions;
using CandyHouseBase.Infrastructure;
using CandyHouseBase.Extensions;
namespace CandyHouseBase.DataModels
{
public class PekarDataModel : IValidation
{
public string Id { get; private set; }
public string FIO { get; private set; }
public string Position { get; private set; }
public decimal BonusCoefficient { get; private set; }
public PekarDataModel(string id, string fio, string position, decimal bonusCoefficient)
{
Id = id;
FIO = fio;
Position = position;
BonusCoefficient = bonusCoefficient;
}
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 (Position.IsEmpty()) throw new ValidationException("Field Position is empty");
if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive");
}
}
}

View File

@ -0,0 +1,27 @@
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
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 ProductDataModel(string id, string name, string description)
{
Id = id;
Name = name;
Description = description;
}
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 (Name.IsEmpty()) throw new ValidationException("Field Name is empty");
}
}
}

View File

@ -0,0 +1,37 @@
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;
}
}
}

View File

@ -0,0 +1,33 @@
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");
}
}
}

View File

@ -0,0 +1,27 @@
using CandyHouseBase.Exceptions;
using CandyHouseBase.Extensions;
using CandyHouseBase.Infrastructure;
namespace CandyHouseBase.DataModels
{
public class RecipeDataModel : IValidation
{
public string ProductId { get; private set; }
public string IngredientId { get; private set; }
public int Quantity { get; private set; }
public RecipeDataModel(string productId, string ingredientId, int quantity)
{
ProductId = productId;
IngredientId = ingredientId;
Quantity = quantity;
}
public void Validate()
{
if (!ProductId.IsGuid()) throw new ValidationException("ProductId must be a GUID");
if (!IngredientId.IsGuid()) throw new ValidationException("IngredientId must be a GUID");
if (Quantity <= 0) throw new ValidationException("Quantity must be positive");
}
}
}

View File

@ -0,0 +1,28 @@
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");
}
}
}

View File

@ -0,0 +1,30 @@
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");
}
}
}

View File

@ -0,0 +1,8 @@
namespace CandyHouseBase.Enums
{
public enum ItemType
{
Ingredient = 1,
Product = 2
}
}

View File

@ -0,0 +1,9 @@
using System;
namespace CandyHouseBase.Exceptions
{
public class ValidationException : Exception
{
public ValidationException(string message) : base(message) { }
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace CandyHouseBase.Extensions
{
public static class StringExtensions
{
public static bool IsEmpty(this string str) => string.IsNullOrWhiteSpace(str);
public static bool IsGuid(this string str) => Guid.TryParse(str, out _);
}
}

View File

@ -0,0 +1,7 @@
namespace CandyHouseBase.Infrastructure
{
public interface IValidation
{
void Validate();
}
}

View File

@ -0,0 +1,9 @@
namespace CandyHouseBase
{
public class Program
{
public static void Main(string[] args)
{
}
}
}

View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CandyHouseBase", "CandyHouseBase\CandyHouseBase.csproj", "{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CandyHouseTests", "CandyHouseTests\CandyHouseTests.csproj", "{396EA8C4-6102-479E-83A2-C83E6B74A14E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}.Release|Any CPU.Build.0 = Release|Any CPU
{396EA8C4-6102-479E-83A2-C83E6B74A14E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{396EA8C4-6102-479E-83A2-C83E6B74A14E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{396EA8C4-6102-479E-83A2-C83E6B74A14E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{396EA8C4-6102-479E-83A2-C83E6B74A14E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?><configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>

View File

@ -0,0 +1,140 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props')" />
<Import Project="..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props" Condition="Exists('..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props')" />
<Import Project="..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props" Condition="Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props')" />
<Import Project="..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props" Condition="Exists('..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{396EA8C4-6102-479E-83A2-C83E6B74A14E}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CandyHouseTests</RootNamespace>
<AssemblyName>CandyHouseTests</AssemblyName>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.ApplicationInsights, Version=2.22.0.997, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="Microsoft.Testing.Extensions.MSBuild, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.MSBuild.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Testing.Extensions.Telemetry, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Testing.Extensions.VSTestBridge, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Testing.Platform, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Testing.Platform.1.5.3\lib\netstandard2.0\Microsoft.Testing.Platform.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
</Reference>
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
</Reference>
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
</Reference>
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.5.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
</Reference>
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
</Reference>
<Reference Include="System.Net.Http" />
<Reference Include="System.Numerics" />
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
</Reference>
<Reference Include="System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
</Reference>
<Reference Include="System.Runtime" />
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.Serialization" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="DataModelsTests\CustomerDataModelTests.cs" />
<Compile Include="DataModelsTests\OrderDataModelTests.cs" />
<Compile Include="DataModelsTests\ProductStockDataModelTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CandyHouseBase\CandyHouseBase.csproj">
<Project>{5df70b46-31f7-4d15-8c60-52c0a0a364f0}</Project>
<Name>CandyHouseBase</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props'))" />
<Error Condition="!Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.targets'))" />
<Error Condition="!Exists('..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.targets" Condition="Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.targets')" />
<Import Project="..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.targets" Condition="Exists('..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@ -0,0 +1,55 @@
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"));
}
}
}

View File

@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using CandyHouseBase.DataModels;
using CandyHouseBase.Exceptions;
namespace CandyHouseTests.DataModelsTests
{
[TestFixture]
public class OrderDataModelTests
{
[Test]
public void Order_ShouldThrowException_WhenIdIsInvalid()
{
var orderDataModel = new OrderDataModel("", Guid.NewGuid().ToString(), DateTime.UtcNow,
100, 5, new List<OrderItemDataModel>(), false);
Assert.Throws<ValidationException>(orderDataModel.Validate);
}
[Test]
public void Order_ShouldThrowException_WhenNoItemsInOrder()
{
var orderDataModel = new OrderDataModel(Guid.NewGuid().ToString(),
Guid.NewGuid().ToString(), DateTime.UtcNow, 100, 5, new List<OrderItemDataModel>(), false);
Assert.Throws<ValidationException>(orderDataModel.Validate);
}
[Test]
public void Order_ShouldCreateSuccessfully_WithValidData()
{
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);
Assert.That(order.TotalAmount, Is.EqualTo(200));
Assert.That(order.DiscountAmount, Is.EqualTo(10));
}
}
}

View File

@ -0,0 +1,40 @@
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));
}
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.ApplicationInsights" version="2.22.0" targetFramework="net471" />
<package id="Microsoft.TestPlatform.ObjectModel" version="17.12.0" targetFramework="net471" />
<package id="Microsoft.Testing.Extensions.Telemetry" version="1.5.3" targetFramework="net471" />
<package id="Microsoft.Testing.Extensions.TrxReport.Abstractions" version="1.5.3" targetFramework="net471" />
<package id="Microsoft.Testing.Extensions.VSTestBridge" version="1.5.3" targetFramework="net471" />
<package id="Microsoft.Testing.Platform" version="1.5.3" targetFramework="net471" />
<package id="Microsoft.Testing.Platform.MSBuild" version="1.5.3" targetFramework="net471" />
<package id="NUnit" version="3.5.0" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="5.0.0" targetFramework="net471" />
<package id="System.Buffers" version="4.5.1" targetFramework="net471" />
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net471" />
<package id="System.Diagnostics.DiagnosticSource" version="5.0.0" targetFramework="net471" />
<package id="System.Memory" version="4.5.4" targetFramework="net471" />
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net471" />
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net471" />
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net471" />
</packages>