Compare commits
8 Commits
main
...
lab-2-no-l
Author | SHA1 | Date | |
---|---|---|---|
805a1d0322 | |||
79cdd4b5d7 | |||
0061693eff | |||
825133bed3 | |||
03057e83bd | |||
7be921eb29 | |||
9ce5690584 | |||
48da4621c6 |
10
CandyHouseSolution/CandyHouseBase/App.config
Normal file
10
CandyHouseSolution/CandyHouseBase/App.config
Normal 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.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
3
CandyHouseSolution/CandyHouseBase/AssemblyInfo.cs
Normal file
3
CandyHouseSolution/CandyHouseBase/AssemblyInfo.cs
Normal file
@ -0,0 +1,3 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly: InternalsVisibleTo("CandyHouseTests")]
|
172
CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj
Normal file
172
CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj
Normal file
@ -0,0 +1,172 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="8.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>
|
||||
<LangVersion>12</LangVersion>
|
||||
</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="Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.5.1.1\lib\net462\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Bcl.AsyncInterfaces, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Options, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Options.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Options.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Primitives, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Primitives.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Moq, Version=4.20.72.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.20.72\lib\net462\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System"/>
|
||||
<Reference Include="System.Buffers, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.6.0\lib\net462\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Data"/>
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.10.0.0-preview.1.25080.5\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.IO.Pipelines.10.0.0-preview.1.25080.5\lib\net462\System.IO.Pipelines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.6.0\lib\net462\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.6.0\lib\net462\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=6.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Encodings.Web, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.10.0.0-preview.1.25080.5\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.10.0.0-preview.1.25080.5\lib\net462\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.6.0\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="DataModels\IngredientDataModel.cs" />
|
||||
<Compile Include="DataModels\OrderDataModel.cs" />
|
||||
<Compile Include="DataModels\PekarDataModel.cs" />
|
||||
<Compile Include="DataModels\PekarHistoryDataModel.cs" />
|
||||
<Compile Include="DataModels\PositionDataModel.cs" />
|
||||
<Compile Include="DataModels\ProductDataModel.cs" />
|
||||
<Compile Include="DataModels\RecipeDataModel.cs" />
|
||||
<Compile Include="DataModels\SalaryDataModel.cs" />
|
||||
<Compile Include="Enums\PositionType.cs" />
|
||||
<Compile Include="Enums\StatusType.cs" />
|
||||
<Compile Include="Exceptions\DateTimeExtensions.cs" />
|
||||
<Compile Include="Exceptions\ElementExistsException.cs" />
|
||||
<Compile Include="Exceptions\ElementNotFoundException.cs" />
|
||||
<Compile Include="Exceptions\IncorrectDatesException.cs" />
|
||||
<Compile Include="Exceptions\NullListException.cs" />
|
||||
<Compile Include="Exceptions\StorageException.cs" />
|
||||
<Compile Include="Exceptions\ValidationException.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Implementations\IngredientBusinessLogicContract.cs" />
|
||||
<Compile Include="Implementations\OrderBusinessLogicContract.cs" />
|
||||
<Compile Include="Implementations\PekarBusinessLogicContract.cs" />
|
||||
<Compile Include="Implementations\PositionBusinessLogicContract.cs" />
|
||||
<Compile Include="Implementations\ProductBusinessLogicContract.cs" />
|
||||
<Compile Include="Implementations\SalaryBusinessLogicContract.cs" />
|
||||
<Compile Include="Infrastructure\IValidation.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\IIngredientBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\IOrderBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\IPekarBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\IPositionBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\IProductBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\BusinessLogicsContracts\ISalaryBusinessLogicContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\IIngredientStorageContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\IOrderStorageContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\IPekarStorageContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\IPositionStorageContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\IProductStorageContact.cs" />
|
||||
<Compile Include="Interfaces\StoragesContracts\ISalaryStorageContact.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<InternalsVisibleTo Include="CatHasPawsTests" />
|
||||
<InternalsVisibleTo Include="DynamicProxyGenAssembly2" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" />
|
||||
</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>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
|
||||
<_Parameter1>$(AssemblyName).Test.dll</_Parameter1>
|
||||
</AssemblyAttribute>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Infrastructure;
|
||||
|
||||
namespace CandyHouseBase.DataModels
|
||||
{
|
||||
public class OrderDataModel : IValidation
|
||||
{
|
||||
public string Id { get; private set; }
|
||||
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 string ProductId { get; private set; }
|
||||
public string PekarId { get; private set; }
|
||||
public StatusType StatusType { get; private set; }
|
||||
|
||||
public OrderDataModel(string id, string customerName, DateTime orderDate, decimal totalAmount,
|
||||
decimal discountAmount, string productId, string pekarId, StatusType statusType)
|
||||
{
|
||||
Id = id;
|
||||
CustomerName = customerName;
|
||||
OrderDate = orderDate;
|
||||
TotalAmount = totalAmount;
|
||||
DiscountAmount = discountAmount;
|
||||
ProductId = productId;
|
||||
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 (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");
|
||||
if (ProductId.IsEmpty()) throw new ValidationException("Field productId is empty");
|
||||
if (!ProductId.IsGuid()) throw new ValidationException("productId must be a GUID");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.RegularExpressions;
|
||||
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 List<ProductDataModel> ProductsItems { get; private set; }
|
||||
|
||||
|
||||
public PekarDataModel(string id, string fio, string position, decimal bonusCoefficient,
|
||||
List<ProductDataModel> productsItems)
|
||||
{
|
||||
Id = id;
|
||||
FIO = fio;
|
||||
Position = position;
|
||||
BonusCoefficient = bonusCoefficient;
|
||||
ProductsItems = productsItems;
|
||||
}
|
||||
|
||||
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");
|
||||
var fioPattern = @"^[A-Za-zА-Яа-яЁё\s\-]+$";
|
||||
if (!Regex.IsMatch(FIO, fioPattern))
|
||||
throw new ValidationException("FIO contains invalid characters");
|
||||
|
||||
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,35 @@
|
||||
using System;
|
||||
using System.Text.RegularExpressions;
|
||||
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");
|
||||
var titlePattern = @"^[A-Za-zА-Яа-яЁё\s\-]+$";
|
||||
if (!Regex.IsMatch(Title, titlePattern))
|
||||
throw new ValidationException("FIO contains invalid characters");
|
||||
|
||||
if (string.IsNullOrEmpty(Title)) throw new ValidationException("Field Title is empty");
|
||||
if (!Enum.IsDefined(typeof(PositionType), Type)) throw new ValidationException("Invalid PositionType");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
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 => name;
|
||||
set
|
||||
{
|
||||
if (!name.IsEmpty()) OldName = name;
|
||||
name = value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
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 List<IngredientDataModel> IngredientsItems { get; private set; }
|
||||
|
||||
public ProductDataModel(string id, string name, string description, List<IngredientDataModel> ingredients)
|
||||
{
|
||||
Id = id;
|
||||
Name = name;
|
||||
Description = description;
|
||||
IngredientsItems = ingredients;
|
||||
}
|
||||
|
||||
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 (Description.IsEmpty()) throw new ValidationException("Field Description is empty");
|
||||
if (IngredientsItems.Count == 0) throw new ValidationException("Field IngredientsItems is empty");
|
||||
}
|
||||
}
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
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 decimal TotalSalary { get; private set; }
|
||||
|
||||
public SalaryDataModel(string id, string pekarId, DateTime period, decimal baseRate, decimal bonusRate, decimal totalSalary)
|
||||
{
|
||||
Id = id;
|
||||
PekarId = pekarId;
|
||||
Period = period;
|
||||
BaseRate = baseRate;
|
||||
BonusRate = bonusRate;
|
||||
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 (TotalSalary < 0) throw new ValidationException("TotalSalary cannot be negative");
|
||||
}
|
||||
}
|
||||
}
|
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
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public static class DateTimeExtensions
|
||||
{
|
||||
public static bool IsDateNotOlder(this DateTime date, DateTime olderDate)
|
||||
{
|
||||
return date >= olderDate;
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public class ElementExistsException : Exception
|
||||
{
|
||||
public string ParamName { get; private set; }
|
||||
public string ParamValue { get; private set; }
|
||||
|
||||
public ElementExistsException(string paramName, string paramValue) :
|
||||
base($"There is already an element with value {paramValue} of parameter {paramName}")
|
||||
{
|
||||
ParamName = paramName;
|
||||
ParamValue = paramValue;
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public class ElementNotFoundException : Exception
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
|
||||
public ElementNotFoundException(string value) : base($"Element not found at value = {value}")
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public class IncorrectDatesException : Exception
|
||||
{
|
||||
public IncorrectDatesException(DateTime start, DateTime end) : base(
|
||||
$"The end date must be later than the start date.. StartDate: {start:dd.MM.YYYY}. EndDate: {end:dd.MM.YYYY}")
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public class NullListException : Exception
|
||||
{
|
||||
public NullListException() : base("The returned list is null")
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions;
|
||||
|
||||
public class StorageException : Exception
|
||||
|
||||
{
|
||||
public StorageException(Exception ex) : base($"Error while working in storage: {ex.Message}", ex)
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
using System;
|
||||
|
||||
namespace CandyHouseBase.Exceptions
|
||||
{
|
||||
public class ValidationException : Exception
|
||||
{
|
||||
public ValidationException(string message) : base(message) { }
|
||||
}
|
||||
}
|
@ -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 _);
|
||||
}
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class IngredientBusinessLogicContract(
|
||||
IIngredientStorageContact ingredientStorageContact,
|
||||
ILogger logger)
|
||||
: IIngredientBusinessLogicContact
|
||||
{
|
||||
private readonly IIngredientStorageContact _ingredientStorageContact = ingredientStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<IngredientDataModel> GetAllIngredients()
|
||||
{
|
||||
return new List<IngredientDataModel>();
|
||||
}
|
||||
|
||||
public IngredientDataModel GetIngredientByData(string data)
|
||||
{
|
||||
return new IngredientDataModel("", "", "", 100);
|
||||
}
|
||||
|
||||
public void InsertIngredient(IngredientDataModel ingredient)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateIngredient(IngredientDataModel ingredient)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteIngredient(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class OrderBusinessLogicContract(
|
||||
IOrderStorageContact orderStorageContact,
|
||||
IPekarStorageContact pekarStorageContact,
|
||||
IProductStorageContact productStorageContact,
|
||||
ILogger logger)
|
||||
: IOrderBusinessLogicContact
|
||||
{
|
||||
private readonly IOrderStorageContact _orderStorageContact = orderStorageContact;
|
||||
private readonly IPekarStorageContact _pekarStorageContact = pekarStorageContact;
|
||||
private readonly IProductStorageContact _productStorageContact = productStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<OrderDataModel> GetAllOrders()
|
||||
{
|
||||
return new List<OrderDataModel>();
|
||||
}
|
||||
|
||||
public OrderDataModel GetOrderByData(string data)
|
||||
{
|
||||
return new OrderDataModel("", "", new DateTime(),
|
||||
100, 100m, "", "", StatusType.Cancelled);
|
||||
}
|
||||
|
||||
public void InsertOrder(OrderDataModel order)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateOrder(OrderDataModel order)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteOrder(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class PekarBusinessLogicContract(
|
||||
IPekarStorageContact pekarStorageContact,
|
||||
IProductStorageContact productStorageContact,
|
||||
IPositionStorageContact positionStorageContact,
|
||||
ILogger logger)
|
||||
: IPekarBusinessLogicContact
|
||||
{
|
||||
private readonly IPekarStorageContact _pekarStorageContact = pekarStorageContact;
|
||||
private readonly IProductStorageContact _productStorageContact = productStorageContact;
|
||||
private readonly IPositionStorageContact _positionStorageContact = positionStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<PekarDataModel> GetAllPekars()
|
||||
{
|
||||
return new List<PekarDataModel>();
|
||||
}
|
||||
|
||||
public List<PekarDataModel> GetAllDataOfPekar(string pekarId)
|
||||
{
|
||||
return new List<PekarDataModel>();
|
||||
}
|
||||
|
||||
public PekarDataModel GetPekarByData(string data)
|
||||
{
|
||||
return new PekarDataModel("", "", "",
|
||||
0, new List<ProductDataModel>());
|
||||
}
|
||||
|
||||
public void InsertPekar(PekarDataModel order)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdatePekar(PekarDataModel order)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeletePekar(string id)
|
||||
{
|
||||
}
|
||||
|
||||
public void RestorePekar(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class PositionBusinessLogicContract(
|
||||
IPositionStorageContact positionStorageContact,
|
||||
ILogger logger)
|
||||
: IPositionBusinessLogicContact
|
||||
{
|
||||
private readonly IPositionStorageContact _positionStorageContact = positionStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<PositionDataModel> GetAllPositions()
|
||||
{
|
||||
return new List<PositionDataModel>();
|
||||
}
|
||||
|
||||
public PositionDataModel GetPositionByData(string data)
|
||||
{
|
||||
return new PositionDataModel("", PositionType.Cool, "");
|
||||
}
|
||||
|
||||
public void InsertPosition(PositionDataModel position)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdatePosition(PositionDataModel position)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeletePosition(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class ProductBusinessLogicContract(
|
||||
IProductStorageContact productStorageContact,
|
||||
IIngredientStorageContact ingredientStorageContact,
|
||||
ILogger logger)
|
||||
: IProductBusinessLogicContact
|
||||
{
|
||||
private readonly IProductStorageContact _productStorageContact = productStorageContact;
|
||||
private readonly IIngredientStorageContact _ingredientStorageContact = ingredientStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<ProductDataModel> GetAllProducts()
|
||||
{
|
||||
return new List<ProductDataModel>();
|
||||
}
|
||||
|
||||
public ProductDataModel GetProductByData(string data)
|
||||
{
|
||||
return new ProductDataModel("", "", "", new List<IngredientDataModel>());
|
||||
}
|
||||
|
||||
public void InsertProduct(ProductDataModel product)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateProduct(ProductDataModel product)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteProduct(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseBase.Implementations
|
||||
{
|
||||
internal class SalaryBusinessLogicContract(
|
||||
ISalaryStorageContact salaryStorageContact,
|
||||
IPekarStorageContact pekarStorageContact,
|
||||
ILogger logger)
|
||||
: ISalaryBusinessLogicContact
|
||||
{
|
||||
private readonly ISalaryStorageContact _salaryStorageContact = salaryStorageContact;
|
||||
private readonly IPekarStorageContact _pekarStorageContact = pekarStorageContact;
|
||||
private readonly ILogger _logger = logger;
|
||||
|
||||
public List<SalaryDataModel> GetAllSalaries()
|
||||
{
|
||||
return new List<SalaryDataModel>();
|
||||
}
|
||||
|
||||
public SalaryDataModel GetSalaryByData(string data)
|
||||
{
|
||||
return new SalaryDataModel("", "", new DateTime(), 0, 0, 0);
|
||||
}
|
||||
|
||||
public void InsertSalary(SalaryDataModel salary)
|
||||
{
|
||||
}
|
||||
|
||||
public void UpdateSalary(SalaryDataModel salary)
|
||||
{
|
||||
}
|
||||
|
||||
public void DeleteSalary(string id)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
namespace CandyHouseBase.Infrastructure
|
||||
{
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface IIngredientBusinessLogicContact
|
||||
{
|
||||
List<IngredientDataModel> GetAllIngredients();
|
||||
IngredientDataModel GetIngredientByData(string data);
|
||||
void InsertIngredient(IngredientDataModel ingredient);
|
||||
void UpdateIngredient(IngredientDataModel ingredient);
|
||||
void DeleteIngredient(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface IOrderBusinessLogicContact
|
||||
{
|
||||
List<OrderDataModel> GetAllOrders();
|
||||
OrderDataModel GetOrderByData(string data);
|
||||
void InsertOrder(OrderDataModel order);
|
||||
void UpdateOrder(OrderDataModel order);
|
||||
void DeleteOrder(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface IPekarBusinessLogicContact
|
||||
{
|
||||
List<PekarDataModel> GetAllPekars();
|
||||
List<PekarDataModel> GetAllDataOfPekar(string pekarId);
|
||||
PekarDataModel GetPekarByData(string data);
|
||||
void InsertPekar(PekarDataModel order);
|
||||
void UpdatePekar(PekarDataModel order);
|
||||
void DeletePekar(string id);
|
||||
void RestorePekar(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface IPositionBusinessLogicContact
|
||||
{
|
||||
List<PositionDataModel> GetAllPositions();
|
||||
PositionDataModel GetPositionByData(string data);
|
||||
void InsertPosition(PositionDataModel position);
|
||||
void UpdatePosition(PositionDataModel position);
|
||||
void DeletePosition(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductBusinessLogicContact
|
||||
{
|
||||
List<ProductDataModel> GetAllProducts();
|
||||
ProductDataModel GetProductByData(string data);
|
||||
void InsertProduct(ProductDataModel product);
|
||||
void UpdateProduct(ProductDataModel product);
|
||||
void DeleteProduct(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.BusinessLogicsContracts
|
||||
{
|
||||
public interface ISalaryBusinessLogicContact
|
||||
{
|
||||
List<SalaryDataModel> GetAllSalaries();
|
||||
SalaryDataModel GetSalaryByData(string data);
|
||||
void InsertSalary(SalaryDataModel salary);
|
||||
void UpdateSalary(SalaryDataModel salary);
|
||||
void DeleteSalary(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface IIngredientStorageContact
|
||||
{
|
||||
List<IngredientDataModel> GetList();
|
||||
IngredientDataModel GetElementById(string id);
|
||||
IngredientDataModel GetElementByName(string name);
|
||||
void AddElement(IngredientDataModel ingredient);
|
||||
void UpdateElement(IngredientDataModel ingredient);
|
||||
void DeleteElement(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface IOrderStorageContact
|
||||
{
|
||||
List<OrderDataModel> GetOrders();
|
||||
void AddElement(OrderDataModel order);
|
||||
void UpdateElement(OrderDataModel order);
|
||||
void DeleteElement(OrderDataModel order);
|
||||
OrderDataModel GetElementById(string orderId);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface IPekarStorageContact
|
||||
{
|
||||
List<PekarDataModel> GetList();
|
||||
List<PekarDataModel> GetPekarWithHistory(string id);
|
||||
PekarDataModel GetElementById(string id);
|
||||
PekarDataModel GetElementByFio(string fio);
|
||||
void AddElement(PekarDataModel item);
|
||||
void UpdateElement(PekarDataModel item);
|
||||
void DeleteElement(string id);
|
||||
void RestoreElement(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface IProductStorageContact
|
||||
{
|
||||
List<ProductDataModel> GetList();
|
||||
ProductDataModel GetElementById(string id);
|
||||
ProductDataModel GetElementByName(string name);
|
||||
ProductDataModel GetElementByOldName(string name);
|
||||
void AddElement(ProductDataModel element);
|
||||
void UpdateElement(ProductDataModel element);
|
||||
void DeleteElement(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface IPositionStorageContact
|
||||
{
|
||||
List<PositionDataModel> GetList();
|
||||
PositionDataModel GetElementById(string id);
|
||||
void AddElement(PositionDataModel element);
|
||||
void UpdateElement(PositionDataModel element);
|
||||
void DeleteElement(string id);
|
||||
}
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
|
||||
namespace CandyHouseBase.Interfaces.StoragesContracts
|
||||
{
|
||||
public interface ISalaryStorageContact
|
||||
{
|
||||
List<SalaryDataModel> GetList();
|
||||
SalaryDataModel GetElementById(string id);
|
||||
void AddElement(SalaryDataModel element);
|
||||
void UpdateElement(SalaryDataModel element);
|
||||
void DeleteElement(string id);
|
||||
}
|
||||
}
|
9
CandyHouseSolution/CandyHouseBase/Program.cs
Normal file
9
CandyHouseSolution/CandyHouseBase/Program.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace CandyHouseBase
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
22
CandyHouseSolution/CandyHouseSolution.sln
Normal file
22
CandyHouseSolution/CandyHouseSolution.sln
Normal 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
|
22
CandyHouseSolution/CandyHouseTests/App.config
Normal file
22
CandyHouseSolution/CandyHouseTests/App.config
Normal file
@ -0,0 +1,22 @@
|
||||
<?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>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Diagnostics.DiagnosticSource" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.0.2.0" newVersion="4.0.2.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.2.1.0" newVersion="4.2.1.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
@ -0,0 +1,362 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class IngredientBusinessLogicContractTests
|
||||
{
|
||||
private IngredientBusinessLogicContract _ingredientBusinessLogicContract;
|
||||
private Mock<IIngredientStorageContact> _ingredientStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_ingredientStorageContact = new Mock<IIngredientStorageContact>();
|
||||
_ingredientBusinessLogicContract = new IngredientBusinessLogicContract(
|
||||
_ingredientStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_ingredientStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllIngredients_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredients = new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100),
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Flour", "kg", 200),
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Cocoa", "kg", 50)
|
||||
};
|
||||
_ingredientStorageContact.Setup(x => x.GetList()).Returns(ingredients);
|
||||
|
||||
// Act
|
||||
var list = _ingredientBusinessLogicContract.GetAllIngredients();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(ingredients));
|
||||
Assert.That(list.All(i => Guid.TryParse(i.Id, out _) && !i.Name.IsEmpty() && !i.Unit.IsEmpty() && i.Cost >= 0), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllIngredients_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_ingredientStorageContact.Setup(x => x.GetList()).Returns(new List<IngredientDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _ingredientBusinessLogicContract.GetAllIngredients();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllIngredients_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_ingredientStorageContact.Setup(x => x.GetList()).Returns((List<IngredientDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetAllIngredients(), Throws.TypeOf<NullListException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllIngredients_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_ingredientStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetAllIngredients(), Throws.TypeOf<StorageException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_ReturnsIngredientById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var ingredient = new IngredientDataModel(id, "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(ingredient);
|
||||
|
||||
// Act
|
||||
var element = _ingredientBusinessLogicContract.GetIngredientByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
||||
Assert.That(!element.Name.IsEmpty());
|
||||
Assert.That(!element.Unit.IsEmpty());
|
||||
Assert.That(element.Cost >= 0);
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_ReturnsIngredientByName_Test()
|
||||
{
|
||||
// Arrange
|
||||
var name = "Sugar";
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), name, "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.GetElementByName(name)).Returns(ingredient);
|
||||
|
||||
// Act
|
||||
var element = _ingredientBusinessLogicContract.GetIngredientByData(name);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Name, Is.EqualTo(name));
|
||||
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
||||
Assert.That(!element.Unit.IsEmpty());
|
||||
Assert.That(element.Cost >= 0);
|
||||
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_NotFoundById_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString(); // Valid Guid
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns((IngredientDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_NotFoundByName_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var name = "Nonexistent";
|
||||
_ingredientStorageContact.Setup(x => x.GetElementByName(name)).Returns((IngredientDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(name), Throws.TypeOf<ElementNotFoundException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementByName(name), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetIngredientByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_ingredientStorageContact.Setup(x => x.GetElementByName(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
Assert.That(() => _ingredientBusinessLogicContract.GetIngredientByData("Sugar"), Throws.TypeOf<StorageException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
_ingredientStorageContact.Verify(x => x.GetElementByName(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertIngredient_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.AddElement(ingredient)).Verifiable();
|
||||
|
||||
// Act
|
||||
_ingredientBusinessLogicContract.InsertIngredient(ingredient);
|
||||
|
||||
// Assert
|
||||
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertIngredient_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.AddElement(ingredient))
|
||||
.Throws(new ElementExistsException("ID", ingredient.Id));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(ingredient), Throws.TypeOf<ElementExistsException>());
|
||||
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertIngredient_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_ingredientStorageContact.Verify(x => x.AddElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertIngredient_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(new IngredientDataModel("", "", "", -1)), Throws.TypeOf<ValidationException>());
|
||||
_ingredientStorageContact.Verify(x => x.AddElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertIngredient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.AddElement(ingredient))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.InsertIngredient(ingredient), Throws.TypeOf<StorageException>());
|
||||
_ingredientStorageContact.Verify(x => x.AddElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateIngredient_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient)).Verifiable();
|
||||
|
||||
// Act
|
||||
_ingredientBusinessLogicContract.UpdateIngredient(ingredient);
|
||||
|
||||
// Assert
|
||||
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateIngredient_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient))
|
||||
.Throws(new ElementNotFoundException(ingredient.Id));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(ingredient), Throws.TypeOf<ElementNotFoundException>());
|
||||
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateIngredient_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_ingredientStorageContact.Verify(x => x.UpdateElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateIngredient_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(new IngredientDataModel("", "", "", -1)), Throws.TypeOf<ValidationException>());
|
||||
_ingredientStorageContact.Verify(x => x.UpdateElement(It.IsAny<IngredientDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateIngredient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100);
|
||||
_ingredientStorageContact.Setup(x => x.UpdateElement(ingredient))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.UpdateIngredient(ingredient), Throws.TypeOf<StorageException>());
|
||||
_ingredientStorageContact.Verify(x => x.UpdateElement(ingredient), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteIngredient_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var ingredient = new IngredientDataModel(id, "Sugar", "kg", 100);
|
||||
var flag = false;
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(ingredient);
|
||||
_ingredientStorageContact.Setup(x => x.DeleteElement(id)).Callback(() => { flag = true; });
|
||||
|
||||
// Act
|
||||
_ingredientBusinessLogicContract.DeleteIngredient(id);
|
||||
|
||||
// Assert
|
||||
_ingredientStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(ingredient.Id, out _), Is.True);
|
||||
Assert.That(!ingredient.Name.IsEmpty());
|
||||
Assert.That(!ingredient.Unit.IsEmpty());
|
||||
Assert.That(ingredient.Cost >= 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteIngredient_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString(); // Use valid Guid
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns((IngredientDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteIngredient_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(id)).Returns(new IngredientDataModel(id, "Sugar", "kg", 100));
|
||||
_ingredientStorageContact.Setup(x => x.DeleteElement(id)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(id), Throws.TypeOf<StorageException>());
|
||||
_ingredientStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_ingredientStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteIngredient_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_ingredientStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteIngredient_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _ingredientBusinessLogicContract.DeleteIngredient("invalid"), Throws.TypeOf<ValidationException>());
|
||||
_ingredientStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,500 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class OrderBusinessLogicContractTests
|
||||
{
|
||||
private OrderBusinessLogicContract _orderBusinessLogicContract;
|
||||
private Mock<IOrderStorageContact> _orderStorageContact;
|
||||
private Mock<IPekarStorageContact> _pekarStorageContact;
|
||||
private Mock<IProductStorageContact> _productStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_orderStorageContact = new Mock<IOrderStorageContact>();
|
||||
_pekarStorageContact = new Mock<IPekarStorageContact>();
|
||||
_productStorageContact = new Mock<IProductStorageContact>();
|
||||
_orderBusinessLogicContract = new OrderBusinessLogicContract(
|
||||
_orderStorageContact.Object,
|
||||
_pekarStorageContact.Object,
|
||||
_productStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_orderStorageContact.Reset();
|
||||
_pekarStorageContact.Reset();
|
||||
_productStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllOrders_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var orders = new List<OrderDataModel>
|
||||
{
|
||||
new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now.AddDays(-1),
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
),
|
||||
new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Jane Smith",
|
||||
DateTime.Now,
|
||||
200.00m,
|
||||
20.00m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Completed
|
||||
)
|
||||
};
|
||||
_orderStorageContact.Setup(x => x.GetOrders()).Returns(orders);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
|
||||
// Act
|
||||
var list = _orderBusinessLogicContract.GetAllOrders();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(orders));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllOrders_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_orderStorageContact.Setup(x => x.GetOrders()).Returns(new List<OrderDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _orderBusinessLogicContract.GetAllOrders();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_orderStorageContact.Verify(x => x.GetOrders(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllOrders_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_orderStorageContact.Setup(x => x.GetOrders()).Returns((List<OrderDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.GetAllOrders(), Throws.TypeOf<NullListException>());
|
||||
_orderStorageContact.Verify(x => x.GetOrders(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllOrders_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_orderStorageContact.Setup(x => x.GetOrders())
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.GetAllOrders(), Throws.TypeOf<StorageException>());
|
||||
_orderStorageContact.Verify(x => x.GetOrders(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOrderByData_ReturnsOrderById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
id,
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
_orderStorageContact.Setup(x => x.GetElementById(id)).Returns(order);
|
||||
|
||||
// Act
|
||||
var element = _orderBusinessLogicContract.GetOrderByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
_orderStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOrderByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.GetOrderByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _orderBusinessLogicContract.GetOrderByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOrderByData_NotFoundRecord_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_orderStorageContact.Setup(x => x.GetElementById(id)).Returns((OrderDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.GetOrderByData(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetOrderByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_orderStorageContact.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.GetOrderByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertOrder_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_orderStorageContact.Setup(x => x.GetElementById(order.Id)).Returns((OrderDataModel)null); // No existing order
|
||||
_orderStorageContact.Setup(x => x.AddElement(It.Is<OrderDataModel>(o => o.Id == order.Id)))
|
||||
.Callback((OrderDataModel x) =>
|
||||
{
|
||||
flag = x.Id == order.Id && x.CustomerName == order.CustomerName && x.OrderDate == order.OrderDate &&
|
||||
x.TotalAmount == order.TotalAmount && x.DiscountAmount == order.DiscountAmount &&
|
||||
x.ProductId == order.ProductId && x.PekarId == order.PekarId &&
|
||||
x.StatusType == order.StatusType;
|
||||
})
|
||||
.Verifiable();
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
|
||||
// Act
|
||||
_orderBusinessLogicContract.InsertOrder(order);
|
||||
|
||||
// Assert
|
||||
_orderStorageContact.Verify(x => x.AddElement(It.Is<OrderDataModel>(o => o.Id == order.Id)), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertOrder_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_orderStorageContact.Setup(x => x.GetElementById(order.Id)).Returns(order); // Existing order
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.InsertOrder(order), Throws.TypeOf<ElementExistsException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(order.Id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertOrder_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.InsertOrder(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_orderStorageContact.Verify(x => x.AddElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertOrder_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.InsertOrder(new OrderDataModel(
|
||||
"",
|
||||
"",
|
||||
DateTime.Now,
|
||||
-100.50m,
|
||||
-10.50m,
|
||||
"",
|
||||
"",
|
||||
StatusType.Pending
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_orderStorageContact.Verify(x => x.AddElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertOrder_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_orderStorageContact.Setup(x => x.GetElementById(order.Id)).Returns((OrderDataModel)null); // No existing order
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
_orderStorageContact.Setup(x => x.AddElement(It.Is<OrderDataModel>(o => o.Id == order.Id)))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.InsertOrder(order), Throws.TypeOf<StorageException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(order.Id), Times.Once);
|
||||
_orderStorageContact.Verify(x => x.AddElement(It.Is<OrderDataModel>(o => o.Id == order.Id)), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateOrder_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_orderStorageContact.Setup(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)))
|
||||
.Callback((OrderDataModel x) =>
|
||||
{
|
||||
flag = x.Id == order.Id && x.CustomerName == order.CustomerName && x.OrderDate == order.OrderDate &&
|
||||
x.TotalAmount == order.TotalAmount && x.DiscountAmount == order.DiscountAmount &&
|
||||
x.ProductId == order.ProductId && x.PekarId == order.PekarId &&
|
||||
x.StatusType == order.StatusType;
|
||||
})
|
||||
.Verifiable();
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
|
||||
// Act
|
||||
_orderBusinessLogicContract.UpdateOrder(order);
|
||||
|
||||
// Assert
|
||||
_orderStorageContact.Verify(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)), Times.Once);
|
||||
Assert.That(flag);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateOrder_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns((PekarDataModel)null); // Trigger not found
|
||||
_orderStorageContact.Setup(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)))
|
||||
.Verifiable();
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.UpdateOrder(order), Throws.TypeOf<ElementNotFoundException>());
|
||||
_orderStorageContact.Verify(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateOrder_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.UpdateOrder(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_orderStorageContact.Verify(x => x.UpdateElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateOrder_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.UpdateOrder(new OrderDataModel(
|
||||
"",
|
||||
"",
|
||||
DateTime.Now,
|
||||
-100.50m,
|
||||
-10.50m,
|
||||
"",
|
||||
"",
|
||||
StatusType.Pending
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_orderStorageContact.Verify(x => x.UpdateElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateOrder_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
productId,
|
||||
pekarId,
|
||||
StatusType.Pending
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId))
|
||||
.Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(new ProductDataModel(productId, "Cake", "Super soft cake", new List<IngredientDataModel>()));
|
||||
_orderStorageContact.Setup(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.UpdateOrder(order), Throws.TypeOf<StorageException>());
|
||||
_orderStorageContact.Verify(x => x.UpdateElement(It.Is<OrderDataModel>(o => o.Id == order.Id)), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOrder_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(
|
||||
id,
|
||||
"John Doe",
|
||||
DateTime.Now,
|
||||
100.50m,
|
||||
10.50m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
var flag = false;
|
||||
_orderStorageContact.Setup(x => x.GetElementById(id)).Returns(order);
|
||||
_orderStorageContact.Setup(x => x.DeleteElement(order)).Callback(() => { flag = true; });
|
||||
|
||||
// Act
|
||||
_orderBusinessLogicContract.DeleteOrder(id);
|
||||
|
||||
// Assert
|
||||
_orderStorageContact.Verify(x => x.DeleteElement(order), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(order.Id, out _), Is.True);
|
||||
Assert.That(!order.CustomerName.IsEmpty());
|
||||
Assert.That(order.TotalAmount >= 0);
|
||||
Assert.That(order.DiscountAmount >= 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOrder_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_orderStorageContact.Setup(x => x.GetElementById(id)).Returns((OrderDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.DeleteOrder(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOrder_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.DeleteOrder(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _orderBusinessLogicContract.DeleteOrder(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_orderStorageContact.Verify(x => x.DeleteElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOrder_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.DeleteOrder("invalid"), Throws.TypeOf<ValidationException>());
|
||||
_orderStorageContact.Verify(x => x.DeleteElement(It.IsAny<OrderDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteOrder_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var order = new OrderDataModel(id, "John Doe", DateTime.Now, 100.50m, 10.50m, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), StatusType.Pending);
|
||||
_orderStorageContact.Setup(x => x.GetElementById(id)).Returns(order);
|
||||
_orderStorageContact.Setup(x => x.DeleteElement(order)).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _orderBusinessLogicContract.DeleteOrder(id), Throws.TypeOf<StorageException>());
|
||||
_orderStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_orderStorageContact.Verify(x => x.DeleteElement(order), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,875 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class PekarBusinessLogicContractTests
|
||||
{
|
||||
private PekarBusinessLogicContract _pekarBusinessLogicContract;
|
||||
private Mock<IPekarStorageContact> _pekarStorageContact;
|
||||
private Mock<IProductStorageContact> _productStorageContact;
|
||||
private Mock<IPositionStorageContact> _positionStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_pekarStorageContact = new Mock<IPekarStorageContact>();
|
||||
_productStorageContact = new Mock<IProductStorageContact>();
|
||||
_positionStorageContact = new Mock<IPositionStorageContact>();
|
||||
_pekarBusinessLogicContract = new PekarBusinessLogicContract(
|
||||
_pekarStorageContact.Object,
|
||||
_productStorageContact.Object,
|
||||
_positionStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_pekarStorageContact.Reset();
|
||||
_productStorageContact.Reset();
|
||||
_positionStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPekars_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var pekars = new List<PekarDataModel>
|
||||
{
|
||||
new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
Guid.NewGuid().ToString(), // Use Guid for Position
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
),
|
||||
new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Maria Petrova",
|
||||
Guid.NewGuid().ToString(), // Use Guid for Position
|
||||
1.8m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Pastry",
|
||||
"Sweet pastry",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Flour", "kg", 200)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
_pekarStorageContact.Setup(x => x.GetList()).Returns(pekars);
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekars[0].ProductsItems[0]);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(pekars[0].Position))
|
||||
.Returns(new PositionDataModel(pekars[0].Position, PositionType.Cool, "Baking position"));
|
||||
_positionStorageContact.Setup(x => x.GetElementById(pekars[1].Position))
|
||||
.Returns(new PositionDataModel(pekars[1].Position, PositionType.Cool, "Pastry Chef position"));
|
||||
|
||||
// Act
|
||||
var list = _pekarBusinessLogicContract.GetAllPekars();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(pekars));
|
||||
Assert.That(
|
||||
list.All(p =>
|
||||
Guid.TryParse(p.Id, out _) && !p.FIO.IsEmpty() && Guid.TryParse(p.Position, out _) &&
|
||||
p.BonusCoefficient > 0), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPekars_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_pekarStorageContact.Setup(x => x.GetList()).Returns(new List<PekarDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _pekarBusinessLogicContract.GetAllPekars();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_pekarStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPekars_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_pekarStorageContact.Setup(x => x.GetList()).Returns((List<PekarDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllPekars(), Throws.TypeOf<NullListException>());
|
||||
_pekarStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPekars_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_pekarStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllPekars(), Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPekar_ReturnsListOfHistoryRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var historyRecords = new List<PekarDataModel>
|
||||
{
|
||||
new PekarDataModel(pekarId, "Ivan Ivanov", positionId, 1.5m, new List<ProductDataModel>()),
|
||||
new PekarDataModel(pekarId, "Ivan Ivanov", positionId, 1.7m, new List<ProductDataModel>())
|
||||
};
|
||||
var pekarsWithHistory = new List<PekarDataModel>
|
||||
{
|
||||
new PekarDataModel(
|
||||
pekarId,
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.8m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
_pekarStorageContact.Setup(x => x.GetPekarWithHistory(pekarId)).Returns(pekarsWithHistory);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act
|
||||
var list = _pekarBusinessLogicContract.GetAllDataOfPekar(pekarId);
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(2, Is.EqualTo(historyRecords.Count));
|
||||
Assert.That(
|
||||
list.All(h =>
|
||||
Guid.TryParse(h.Id, out _) && !h.FIO.IsEmpty() && Guid.TryParse(h.Position, out _) &&
|
||||
h.BonusCoefficient > 0), Is.True);
|
||||
_pekarStorageContact.Verify(x => x.GetPekarWithHistory(pekarId), Times.Once);
|
||||
_positionStorageContact.Verify(x => x.GetElementById(positionId), Times.AtLeastOnce);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPekar_EmptyPekarId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllDataOfPekar(null),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllDataOfPekar(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.GetPekarWithHistory(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPekar_NotFoundPekar_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
_pekarStorageContact.Setup(x => x.GetPekarWithHistory(pekarId)).Returns(new List<PekarDataModel>());
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllDataOfPekar(pekarId),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.GetPekarWithHistory(pekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPekar_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_pekarStorageContact.Setup(x => x.GetPekarWithHistory(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllDataOfPekar(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetPekarWithHistory(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllDataOfPekar_InvalidPosition_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var pekarsWithHistory = new List<PekarDataModel>
|
||||
{
|
||||
new PekarDataModel(
|
||||
pekarId,
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.8m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
)
|
||||
};
|
||||
_pekarStorageContact.Setup(x => x.GetPekarWithHistory(pekarId)).Returns(pekarsWithHistory);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId)).Returns((PositionDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetAllDataOfPekar(pekarId),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.GetPekarWithHistory(pekarId), Times.Once);
|
||||
_positionStorageContact.Verify(x => x.GetElementById(positionId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPekarByData_ReturnsPekarById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
id,
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns(pekar);
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekar.ProductsItems[0]);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act
|
||||
var element = _pekarBusinessLogicContract.GetPekarByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
||||
Assert.That(!element.FIO.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(element.FIO, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Guid.TryParse(element.Position, out _), Is.True);
|
||||
Assert.That(element.BonusCoefficient > 0);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPekarByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetPekarByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetPekarByData(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPekarByData_NotFoundPekar_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetPekarByData(id),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPekarByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.GetPekarByData(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPekar_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekar.Id))
|
||||
.Returns((PekarDataModel)null);
|
||||
_pekarStorageContact.Setup(x => x.AddElement(It.Is<PekarDataModel>(p => p.Id == pekar.Id)))
|
||||
.Callback((PekarDataModel x) =>
|
||||
{
|
||||
flag = x.Id == pekar.Id && x.FIO == pekar.FIO && x.Position == pekar.Position &&
|
||||
x.BonusCoefficient == pekar.BonusCoefficient &&
|
||||
x.ProductsItems.SequenceEqual(pekar.ProductsItems);
|
||||
});
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekar.ProductsItems[0]);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act
|
||||
_pekarBusinessLogicContract.InsertPekar(pekar);
|
||||
|
||||
// Assert
|
||||
_pekarStorageContact.Verify(x => x.AddElement(It.Is<PekarDataModel>(p => p.Id == pekar.Id)), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(pekar.Id, out _), Is.True);
|
||||
Assert.That(!pekar.FIO.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(pekar.FIO, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Guid.TryParse(pekar.Position, out _), Is.True);
|
||||
Assert.That(pekar.BonusCoefficient > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPekar_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
var existingPekar = new PekarDataModel(pekar.Id, "Old Name", positionId, 1.0m, new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(productId, "Old Cake", "Old cake", new List<IngredientDataModel>())
|
||||
});
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekar.Id)).Returns(existingPekar);
|
||||
_pekarStorageContact.Setup(x => x.AddElement(It.IsAny<PekarDataModel>()))
|
||||
.Throws(new ElementExistsException("ID", pekar.Id));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(existingPekar.ProductsItems[0]); // Mock product existence
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.InsertPekar(pekar), Throws.TypeOf<ElementExistsException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekar.Id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPekar_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.InsertPekar(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.AddElement(It.IsAny<PekarDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPekar_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.InsertPekar(new PekarDataModel(
|
||||
"",
|
||||
"123",
|
||||
Guid.NewGuid().ToString(),
|
||||
-1.0m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel("", "Sugar", "kg", -100)
|
||||
}
|
||||
)
|
||||
}
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_pekarStorageContact.Verify(x => x.AddElement(It.IsAny<PekarDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPekar_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekar.Id)).Returns((PekarDataModel)null);
|
||||
_pekarStorageContact.Setup(x => x.AddElement(It.IsAny<PekarDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId))
|
||||
.Returns(pekar.ProductsItems[0]); // Mock product existence
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.InsertPekar(pekar), Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekar.Id), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.AddElement(It.IsAny<PekarDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePekar_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.UpdateElement(It.Is<PekarDataModel>(p => p.Id == pekar.Id)))
|
||||
.Callback((PekarDataModel x) =>
|
||||
{
|
||||
flag = x.Id == pekar.Id && x.FIO == pekar.FIO && x.Position == pekar.Position &&
|
||||
x.BonusCoefficient == pekar.BonusCoefficient &&
|
||||
x.ProductsItems.SequenceEqual(pekar.ProductsItems);
|
||||
});
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekar.ProductsItems[0]);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
|
||||
// Act
|
||||
_pekarBusinessLogicContract.UpdatePekar(pekar);
|
||||
|
||||
// Assert
|
||||
_pekarStorageContact.Verify(x => x.UpdateElement(It.Is<PekarDataModel>(p => p.Id == pekar.Id)), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(pekar.Id, out _), Is.True);
|
||||
Assert.That(!pekar.FIO.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(pekar.FIO, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Guid.TryParse(pekar.Position, out _), Is.True);
|
||||
Assert.That(pekar.BonusCoefficient > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePekar_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_productStorageContact.Setup(x => x.GetElementById(pekar.ProductsItems[0].Id))
|
||||
.Returns(pekar.ProductsItems[0]);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
_pekarStorageContact.Setup(x => x.UpdateElement(It.IsAny<PekarDataModel>()))
|
||||
.Throws(new ElementNotFoundException("Pekar not found"));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.UpdatePekar(pekar),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.UpdateElement(It.IsAny<PekarDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePekar_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.UpdatePekar(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.UpdateElement(It.IsAny<PekarDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePekar_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.UpdatePekar(new PekarDataModel(
|
||||
"",
|
||||
"123",
|
||||
Guid.NewGuid().ToString(),
|
||||
-1.0m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel("", "Sugar", "kg", -100)
|
||||
}
|
||||
)
|
||||
}
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_pekarStorageContact.Verify(x => x.UpdateElement(It.IsAny<PekarDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePekar_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var positionId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Ivan Ivanov",
|
||||
positionId,
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekar.Id)).Returns(pekar); // Ensure Pekar exists
|
||||
_pekarStorageContact.Setup(x => x.UpdateElement(It.IsAny<PekarDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_positionStorageContact.Setup(x => x.GetElementById(positionId))
|
||||
.Returns(new PositionDataModel(positionId, PositionType.Cool, "Baking position"));
|
||||
_productStorageContact.Setup(x => x.GetElementById(pekar.ProductsItems[0].Id))
|
||||
.Returns(pekar.ProductsItems[0]);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.UpdatePekar(pekar), Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.UpdateElement(It.IsAny<PekarDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePekar_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
id,
|
||||
"Ivan Ivanov",
|
||||
Guid.NewGuid().ToString(),
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
var flag = false;
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns(pekar);
|
||||
_pekarStorageContact.Setup(x => x.DeleteElement(id))
|
||||
.Callback(() => { flag = true; });
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekar.ProductsItems[0]);
|
||||
|
||||
// Act
|
||||
_pekarBusinessLogicContract.DeletePekar(id);
|
||||
|
||||
// Assert
|
||||
_pekarStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(pekar.Id, out _), Is.True);
|
||||
Assert.That(!pekar.FIO.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(pekar.FIO, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(!pekar.Position.IsEmpty());
|
||||
Assert.That(pekar.BonusCoefficient > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePekar_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.DeletePekar(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePekar_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.DeletePekar(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _pekarBusinessLogicContract.DeletePekar(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePekar_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
// No need to setup GetElementById for invalid ID since validation should prevent it
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.DeletePekar(id), Throws.TypeOf<ValidationException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePekar_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
id,
|
||||
"Ivan Ivanov",
|
||||
Guid.NewGuid().ToString(),
|
||||
1.5m,
|
||||
new List<ProductDataModel>()
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns(pekar);
|
||||
_pekarStorageContact.Setup(x => x.DeleteElement(id))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.DeletePekar(id), Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePekar_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
id,
|
||||
"Ivan Ivanov",
|
||||
Guid.NewGuid().ToString(),
|
||||
1.5m,
|
||||
new List<ProductDataModel>
|
||||
{
|
||||
new ProductDataModel(
|
||||
productId,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
)
|
||||
}
|
||||
);
|
||||
var flag = false;
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns(pekar);
|
||||
_pekarStorageContact.Setup(x => x.RestoreElement(id))
|
||||
.Callback(() => { flag = true; });
|
||||
_productStorageContact.Setup(x => x.GetElementById(productId)).Returns(pekar.ProductsItems[0]);
|
||||
|
||||
// Act
|
||||
_pekarBusinessLogicContract.RestorePekar(id);
|
||||
|
||||
// Assert
|
||||
_pekarStorageContact.Verify(x => x.RestoreElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(pekar.Id, out _), Is.True);
|
||||
Assert.That(!pekar.FIO.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(pekar.FIO, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(!pekar.Position.IsEmpty());
|
||||
Assert.That(pekar.BonusCoefficient > 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePekar_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.RestorePekar(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePekar_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.RestorePekar(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _pekarBusinessLogicContract.RestorePekar(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_pekarStorageContact.Verify(x => x.RestoreElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePekar_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
// No need to setup GetElementById for invalid ID since validation should prevent it
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.RestorePekar(id), Throws.TypeOf<ValidationException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void RestorePekar_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekar = new PekarDataModel(
|
||||
id,
|
||||
"Ivan Ivanov",
|
||||
Guid.NewGuid().ToString(),
|
||||
1.5m,
|
||||
new List<ProductDataModel>()
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(id)).Returns(pekar);
|
||||
_pekarStorageContact.Setup(x => x.RestoreElement(id))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _pekarBusinessLogicContract.RestorePekar(id), Throws.TypeOf<StorageException>());
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.RestoreElement(id), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,421 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class PositionBusinessLogicContractTests
|
||||
{
|
||||
private PositionBusinessLogicContract _positionBusinessLogicContract;
|
||||
private Mock<IPositionStorageContact> _positionStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_positionStorageContact = new Mock<IPositionStorageContact>();
|
||||
_positionBusinessLogicContract = new PositionBusinessLogicContract(
|
||||
_positionStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_positionStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPositions_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var positions = new List<PositionDataModel>
|
||||
{
|
||||
new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
),
|
||||
new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Medium,
|
||||
"Pastry Chef"
|
||||
)
|
||||
};
|
||||
_positionStorageContact.Setup(x => x.GetList()).Returns(positions);
|
||||
|
||||
// Act
|
||||
var list = _positionBusinessLogicContract.GetAllPositions();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(positions));
|
||||
Assert.That(
|
||||
list.All(p =>
|
||||
Guid.TryParse(p.Id, out _) && !p.Title.IsEmpty() && Enum.IsDefined(typeof(PositionType), p.Type)),
|
||||
Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPositions_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_positionStorageContact.Setup(x => x.GetList()).Returns(new List<PositionDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _positionBusinessLogicContract.GetAllPositions();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_positionStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPositions_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_positionStorageContact.Setup(x => x.GetList()).Returns((List<PositionDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.GetAllPositions(), Throws.TypeOf<NullListException>());
|
||||
_positionStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllPositions_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_positionStorageContact.Setup(x => x.GetList())
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.GetAllPositions(), Throws.TypeOf<StorageException>());
|
||||
_positionStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPositionByData_ReturnsPositionById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var position = new PositionDataModel(
|
||||
id,
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.GetElementById(id)).Returns(position);
|
||||
|
||||
// Act
|
||||
var element = _positionBusinessLogicContract.GetPositionByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
||||
Assert.That(!element.Title.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(element.Title, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Enum.IsDefined(typeof(PositionType), element.Type), Is.True);
|
||||
_positionStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPositionByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.GetPositionByData(null),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _positionBusinessLogicContract.GetPositionByData(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPositionByData_NotFoundPosition_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString(); // Use a valid Guid to test not found scenario
|
||||
_positionStorageContact.Setup(x => x.GetElementById(id)).Returns((PositionDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.GetPositionByData(id),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetPositionByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_positionStorageContact.Setup(x => x.GetElementById(It.IsAny<string>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.GetPositionByData(Guid.NewGuid().ToString()),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPosition_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var flag = false;
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.AddElement(It.IsAny<PositionDataModel>()))
|
||||
.Callback((PositionDataModel x) =>
|
||||
{
|
||||
flag = x.Id == position.Id && x.Type == position.Type && x.Title == position.Title;
|
||||
});
|
||||
|
||||
// Act
|
||||
_positionBusinessLogicContract.InsertPosition(position);
|
||||
|
||||
// Assert
|
||||
_positionStorageContact.Verify(x => x.AddElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(position.Id, out _), Is.True);
|
||||
Assert.That(!position.Title.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(position.Title, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Enum.IsDefined(typeof(PositionType), position.Type), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPosition_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.AddElement(It.IsAny<PositionDataModel>()))
|
||||
.Throws(new ElementExistsException("ID", position.Id));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.InsertPosition(position),
|
||||
Throws.TypeOf<ElementExistsException>());
|
||||
_positionStorageContact.Verify(x => x.AddElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPosition_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.InsertPosition(null),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_positionStorageContact.Verify(x => x.AddElement(It.IsAny<PositionDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPosition_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.InsertPosition(new PositionDataModel(
|
||||
"",
|
||||
(PositionType)999,
|
||||
"123"
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_positionStorageContact.Verify(x => x.AddElement(It.IsAny<PositionDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertPosition_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.AddElement(It.IsAny<PositionDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.InsertPosition(position),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_positionStorageContact.Verify(x => x.AddElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePosition_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var flag = false;
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.UpdateElement(It.IsAny<PositionDataModel>()))
|
||||
.Callback((PositionDataModel x) =>
|
||||
{
|
||||
flag = x.Id == position.Id && x.Type == position.Type && x.Title == position.Title;
|
||||
});
|
||||
|
||||
// Act
|
||||
_positionBusinessLogicContract.UpdatePosition(position);
|
||||
|
||||
// Assert
|
||||
_positionStorageContact.Verify(x => x.UpdateElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(position.Id, out _), Is.True);
|
||||
Assert.That(!position.Title.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(position.Title, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Enum.IsDefined(typeof(PositionType), position.Type), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePosition_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.UpdateElement(It.IsAny<PositionDataModel>()))
|
||||
.Throws(new ElementNotFoundException("Position not found"));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.UpdatePosition(position),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_positionStorageContact.Verify(x => x.UpdateElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePosition_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.UpdatePosition(null),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_positionStorageContact.Verify(x => x.UpdateElement(It.IsAny<PositionDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePosition_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.UpdatePosition(new PositionDataModel(
|
||||
"", // Invalid ID
|
||||
(PositionType)999,
|
||||
"123"
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_positionStorageContact.Verify(x => x.UpdateElement(It.IsAny<PositionDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdatePosition_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var position = new PositionDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
_positionStorageContact.Setup(x => x.UpdateElement(It.IsAny<PositionDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.UpdatePosition(position),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_positionStorageContact.Verify(x => x.UpdateElement(It.IsAny<PositionDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePosition_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var position = new PositionDataModel(
|
||||
id,
|
||||
PositionType.Cool,
|
||||
"Baker"
|
||||
);
|
||||
var flag = false;
|
||||
_positionStorageContact.Setup(x => x.GetElementById(id)).Returns(position);
|
||||
_positionStorageContact.Setup(x => x.DeleteElement(id)).Callback(() => { flag = true; });
|
||||
|
||||
// Act
|
||||
_positionBusinessLogicContract.DeletePosition(id);
|
||||
|
||||
// Assert
|
||||
_positionStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(position.Id, out _), Is.True);
|
||||
Assert.That(!position.Title.IsEmpty());
|
||||
Assert.That(Regex.IsMatch(position.Title, @"^[A-Za-zА-Яа-яЁё\s\-]+$"), Is.True);
|
||||
Assert.That(Enum.IsDefined(typeof(PositionType), position.Type), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePosition_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString(); // Use a valid Guid to test not found scenario
|
||||
_positionStorageContact.Setup(x => x.GetElementById(id)).Returns((PositionDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.DeletePosition(id),
|
||||
Throws.TypeOf<ElementNotFoundException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePosition_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.DeletePosition(null),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _positionBusinessLogicContract.DeletePosition(string.Empty),
|
||||
Throws.TypeOf<ArgumentNullException>());
|
||||
_positionStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePosition_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
// No need to setup GetElementById for invalid ID since validation should be after existence check
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.DeletePosition(id),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(id), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletePosition_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var position = new PositionDataModel(id, PositionType.Cool, "Baker");
|
||||
_positionStorageContact.Setup(x => x.GetElementById(id)).Returns(position);
|
||||
_positionStorageContact.Setup(x => x.DeleteElement(id))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _positionBusinessLogicContract.DeletePosition(id),
|
||||
Throws.TypeOf<StorageException>());
|
||||
_positionStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_positionStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,586 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class ProductBusinessLogicContractTests
|
||||
{
|
||||
private ProductBusinessLogicContract _productBusinessLogicContract;
|
||||
private Mock<IProductStorageContact> _productStorageContact;
|
||||
private Mock<IIngredientStorageContact> _ingredientStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_productStorageContact = new Mock<IProductStorageContact>();
|
||||
_ingredientStorageContact = new Mock<IIngredientStorageContact>();
|
||||
_productBusinessLogicContract = new ProductBusinessLogicContract(
|
||||
_productStorageContact.Object,
|
||||
_ingredientStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_productStorageContact.Reset();
|
||||
_ingredientStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product1 = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product1.Name = "Updated Cake";
|
||||
product1.Description = "Updated delicious cake";
|
||||
var product2 = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Pastry",
|
||||
"Sweet pastry",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Flour", "kg", 200)
|
||||
}
|
||||
);
|
||||
product2.Name = "Updated Pastry";
|
||||
product2.Description = "Updated sweet pastry";
|
||||
var products = new List<ProductDataModel> { product1, product2 };
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(products);
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product1.IngredientsItems[0]);
|
||||
|
||||
// Act
|
||||
var list = _productBusinessLogicContract.GetAllProducts();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(products));
|
||||
Assert.That(
|
||||
list.All(p =>
|
||||
Guid.TryParse(p.Id, out _) && !p.Name.IsEmpty() && !p.Description.IsEmpty() &&
|
||||
p.IngredientsItems.Count > 0 && !p.OldName.IsEmpty() && !p.OldDescription.IsEmpty()), Is.True);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(new List<ProductDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _productBusinessLogicContract.GetAllProducts();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns((List<ProductDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProducts(), Throws.TypeOf<NullListException>());
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllProducts_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_productStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetAllProducts(), Throws.TypeOf<StorageException>());
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_ReturnsProductById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
id,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Returns(product);
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(new List<ProductDataModel> { product });
|
||||
|
||||
// Act
|
||||
var elementById = _productBusinessLogicContract.GetProductByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(elementById, Is.Not.Null);
|
||||
Assert.That(elementById.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(elementById.Id, out _), Is.True);
|
||||
Assert.That(elementById.Name, Is.EqualTo("Updated Cake"));
|
||||
Assert.That(elementById.Description, Is.EqualTo("Updated delicious cake"));
|
||||
Assert.That(elementById.IngredientsItems.Count > 0);
|
||||
Assert.That(elementById.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(elementById.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_ReturnsProductByName_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
id,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(new List<ProductDataModel> { product });
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act
|
||||
var elementByName = _productBusinessLogicContract.GetProductByData("Updated Cake");
|
||||
|
||||
// Assert
|
||||
Assert.That(elementByName, Is.Not.Null);
|
||||
Assert.That(elementByName.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(elementByName.Id, out _), Is.True);
|
||||
Assert.That(elementByName.Name, Is.EqualTo("Updated Cake"));
|
||||
Assert.That(elementByName.Description, Is.EqualTo("Updated delicious cake"));
|
||||
Assert.That(elementByName.IngredientsItems.Count > 0);
|
||||
Assert.That(elementByName.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(elementByName.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_ReturnsProductByOldName_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
id,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(new List<ProductDataModel> { product });
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act
|
||||
var elementByOldName = _productBusinessLogicContract.GetProductByData("Cake");
|
||||
|
||||
// Assert
|
||||
Assert.That(elementByOldName, Is.Not.Null);
|
||||
Assert.That(elementByOldName.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(elementByOldName.Id, out _), Is.True);
|
||||
Assert.That(elementByOldName.Name, Is.EqualTo("Updated Cake"));
|
||||
Assert.That(elementByOldName.Description, Is.EqualTo("Updated delicious cake"));
|
||||
Assert.That(elementByOldName.IngredientsItems.Count > 0);
|
||||
Assert.That(elementByOldName.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(elementByOldName.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_EmptyData_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_NotFoundProduct_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Returns((ProductDataModel)null);
|
||||
_productStorageContact.Setup(x => x.GetList()).Returns(new List<ProductDataModel>());
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData("NonExistentProduct"), Throws.TypeOf<ElementNotFoundException>());
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData("OldNonExistent"), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.AtLeast(2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetProductByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Throws(new StorageException(new InvalidOperationException()));
|
||||
_productStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.GetProductByData(id), Throws.TypeOf<StorageException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_productStorageContact.Verify(x => x.GetList(), Times.Never);
|
||||
}
|
||||
[Test]
|
||||
public void InsertProduct_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
var flag = false;
|
||||
_productStorageContact.Setup(x => x.AddElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
flag = x.Id == product.Id && x.Name == product.Name && x.Description == product.Description &&
|
||||
x.IngredientsItems.SequenceEqual(product.IngredientsItems) &&
|
||||
x.OldName == product.OldName && x.OldDescription == product.OldDescription;
|
||||
});
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act
|
||||
_productBusinessLogicContract.InsertProduct(product);
|
||||
|
||||
// Assert
|
||||
_productStorageContact.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(product.Id, out _), Is.True);
|
||||
Assert.That(!product.Name.IsEmpty());
|
||||
Assert.That(!product.Description.IsEmpty());
|
||||
Assert.That(product.IngredientsItems.Count > 0);
|
||||
Assert.That(
|
||||
product.IngredientsItems.All(i =>
|
||||
Guid.TryParse(i.Id, out _) && !i.Name.IsEmpty() && !i.Unit.IsEmpty() && i.Cost >= 0), Is.True);
|
||||
Assert.That(product.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(product.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.AddElement(It.IsAny<ProductDataModel>()))
|
||||
.Throws(new ElementExistsException("ID", product.Id));
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(product), Throws.TypeOf<ElementExistsException>());
|
||||
_productStorageContact.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContact.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(new ProductDataModel(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel("", "", "", -100)
|
||||
}
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContact.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.AddElement(It.IsAny<ProductDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.InsertProduct(product), Throws.TypeOf<StorageException>());
|
||||
_productStorageContact.Verify(x => x.AddElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var ingredientId = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(ingredientId, "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
var flag = false;
|
||||
_productStorageContact.Setup(x => x.UpdateElement(It.IsAny<ProductDataModel>()))
|
||||
.Callback((ProductDataModel x) =>
|
||||
{
|
||||
flag = x.Id == product.Id && x.Name == product.Name && x.Description == product.Description &&
|
||||
x.IngredientsItems.SequenceEqual(product.IngredientsItems) &&
|
||||
x.OldName == product.OldName && x.OldDescription == product.OldDescription;
|
||||
});
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(ingredientId)).Returns(product.IngredientsItems[0]);
|
||||
|
||||
// Act
|
||||
_productBusinessLogicContract.UpdateProduct(product);
|
||||
|
||||
// Assert
|
||||
_productStorageContact.Verify(x => x.UpdateElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(product.Id, out _), Is.True);
|
||||
Assert.That(!product.Name.IsEmpty());
|
||||
Assert.That(!product.Description.IsEmpty());
|
||||
Assert.That(product.IngredientsItems.Count > 0);
|
||||
Assert.That(
|
||||
product.IngredientsItems.All(i =>
|
||||
Guid.TryParse(i.Id, out _) && !i.Name.IsEmpty() && !i.Unit.IsEmpty() && i.Cost >= 0), Is.True);
|
||||
Assert.That(product.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(product.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.UpdateElement(It.IsAny<ProductDataModel>()))
|
||||
.Throws(new ElementNotFoundException("Product not found"));
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(product.IngredientsItems[0].Id)).Returns(product.IngredientsItems[0]); // Mock ingredient existence
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(product), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContact.Verify(x => x.UpdateElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_productStorageContact.Verify(x => x.UpdateElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(new ProductDataModel(
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel("", "", "", -100)
|
||||
}
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContact.Verify(x => x.UpdateElement(It.IsAny<ProductDataModel>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var product = new ProductDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.UpdateElement(It.IsAny<ProductDataModel>()))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
_ingredientStorageContact.Setup(x => x.GetElementById(product.IngredientsItems[0].Id)).Returns(product.IngredientsItems[0]); // Mock ingredient existence
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.UpdateProduct(product), Throws.TypeOf<StorageException>());
|
||||
_productStorageContact.Verify(x => x.UpdateElement(It.IsAny<ProductDataModel>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
id,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
var flag = false;
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Returns(product);
|
||||
_productStorageContact.Setup(x => x.DeleteElement(id)).Callback(() => { flag = true; });
|
||||
|
||||
// Act
|
||||
_productBusinessLogicContract.DeleteProduct(id);
|
||||
|
||||
// Assert
|
||||
_productStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(product.Id, out _), Is.True);
|
||||
Assert.That(!product.Name.IsEmpty());
|
||||
Assert.That(!product.Description.IsEmpty());
|
||||
Assert.That(product.IngredientsItems.Count > 0);
|
||||
Assert.That(
|
||||
product.IngredientsItems.All(i =>
|
||||
Guid.TryParse(i.Id, out _) && !i.Name.IsEmpty() && !i.Unit.IsEmpty() && i.Cost >= 0), Is.True);
|
||||
Assert.That(product.OldName, Is.EqualTo("Cake"));
|
||||
Assert.That(product.OldDescription, Is.EqualTo("Delicious cake"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString(); // Use a valid Guid
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Returns((ProductDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
// No need to setup GetElementById for invalid ID since validation should occur first
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf<ValidationException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Never); // Should not call GetElementById for invalid GUID
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteProduct_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var product = new ProductDataModel(
|
||||
id,
|
||||
"Cake",
|
||||
"Delicious cake",
|
||||
new List<IngredientDataModel>
|
||||
{
|
||||
new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", 100)
|
||||
}
|
||||
);
|
||||
product.Name = "Updated Cake";
|
||||
product.Description = "Updated delicious cake";
|
||||
_productStorageContact.Setup(x => x.GetElementById(id)).Returns(product);
|
||||
_productStorageContact.Setup(x => x.DeleteElement(id))
|
||||
.Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _productBusinessLogicContract.DeleteProduct(id), Throws.TypeOf<StorageException>());
|
||||
_productStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_productStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,535 @@
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Exceptions;
|
||||
using CandyHouseBase.Extensions;
|
||||
using CandyHouseBase.Implementations;
|
||||
using CandyHouseBase.Interfaces.BusinessLogicsContracts;
|
||||
using CandyHouseBase.Interfaces.StoragesContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace CandyHouseTests.BusinessLogicsContractsTests
|
||||
{
|
||||
[TestFixture]
|
||||
internal class SalaryBusinessLogicContractTests
|
||||
{
|
||||
private SalaryBusinessLogicContract _salaryBusinessLogicContract;
|
||||
private Mock<ISalaryStorageContact> _salaryStorageContact;
|
||||
private Mock<IPekarStorageContact> _pekarStorageContact;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public void OneTimeSetUp()
|
||||
{
|
||||
_salaryStorageContact = new Mock<ISalaryStorageContact>();
|
||||
_pekarStorageContact = new Mock<IPekarStorageContact>();
|
||||
_salaryBusinessLogicContract = new SalaryBusinessLogicContract(
|
||||
_salaryStorageContact.Object,
|
||||
_pekarStorageContact.Object,
|
||||
new Mock<ILogger>().Object
|
||||
);
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public void SetUp()
|
||||
{
|
||||
_salaryStorageContact.Reset();
|
||||
_pekarStorageContact.Reset();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnsListOfRecords_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var salaries = new List<SalaryDataModel>
|
||||
{
|
||||
new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
pekarId,
|
||||
DateTime.Now.AddMonths(-1),
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
),
|
||||
new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
pekarId,
|
||||
DateTime.Now,
|
||||
1500.00m,
|
||||
300.00m,
|
||||
1800.00m
|
||||
)
|
||||
};
|
||||
_salaryStorageContact.Setup(x => x.GetList()).Returns(salaries);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalaries();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Is.EquivalentTo(salaries));
|
||||
Assert.That(list.All(s => Guid.TryParse(s.Id, out _) && Guid.TryParse(s.PekarId, out _) && s.BaseRate >= 0 && s.BonusRate >= 0 && s.TotalSalary >= 0), Is.True);
|
||||
_salaryStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnsEmptyList_Test()
|
||||
{
|
||||
// Arrange
|
||||
_salaryStorageContact.Setup(x => x.GetList()).Returns(new List<SalaryDataModel>());
|
||||
|
||||
// Act
|
||||
var list = _salaryBusinessLogicContract.GetAllSalaries();
|
||||
|
||||
// Assert
|
||||
Assert.That(list, Is.Not.Null);
|
||||
Assert.That(list, Has.Count.EqualTo(0));
|
||||
_salaryStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_ReturnsNull_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_salaryStorageContact.Setup(x => x.GetList()).Returns((List<SalaryDataModel>)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalaries(), Throws.TypeOf<NullListException>());
|
||||
_salaryStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetAllSalaries_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_salaryStorageContact.Setup(x => x.GetList()).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetAllSalaries(), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContact.Verify(x => x.GetList(), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_ReturnsSalaryById_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var salary = new SalaryDataModel(
|
||||
id,
|
||||
pekarId,
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns(salary);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act
|
||||
var element = _salaryBusinessLogicContract.GetSalaryByData(id);
|
||||
|
||||
// Assert
|
||||
Assert.That(element, Is.Not.Null);
|
||||
Assert.That(element.Id, Is.EqualTo(id));
|
||||
Assert.That(Guid.TryParse(element.Id, out _), Is.True);
|
||||
Assert.That(Guid.TryParse(element.PekarId, out _), Is.True);
|
||||
Assert.That(element.BaseRate >= 0);
|
||||
Assert.That(element.BonusRate >= 0);
|
||||
Assert.That(element.TotalSalary >= 0);
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_EmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(id), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_NotFoundSalary_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns((SalaryDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_PekarNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var salary = new SalaryDataModel(id, pekarId, DateTime.Now, 1000.00m, 200.00m, 1200.00m);
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns(salary);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void GetSalaryByData_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(It.IsAny<string>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.GetSalaryByData(Guid.NewGuid().ToString()), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
pekarId,
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
flag = x.Id == salary.Id && x.PekarId == salary.PekarId && x.Period == salary.Period &&
|
||||
x.BaseRate == salary.BaseRate && x.BonusRate == salary.BonusRate && x.TotalSalary == salary.TotalSalary;
|
||||
});
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act
|
||||
_salaryBusinessLogicContract.InsertSalary(salary);
|
||||
|
||||
// Assert
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(salary.Id, out _), Is.True);
|
||||
Assert.That(Guid.TryParse(salary.PekarId, out _), Is.True);
|
||||
Assert.That(salary.BaseRate >= 0);
|
||||
Assert.That(salary.BonusRate >= 0);
|
||||
Assert.That(salary.TotalSalary >= 0);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_PekarNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.InsertSalary(salary), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_RecordWithExistsData_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>())).Throws(new ElementExistsException("ID", salary.Id));
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns(new PekarDataModel(salary.PekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.InsertSalary(salary), Throws.TypeOf<ElementExistsException>());
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.InsertSalary(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.InsertSalary(new SalaryDataModel(
|
||||
"",
|
||||
"",
|
||||
DateTime.Now,
|
||||
-1000.00m,
|
||||
-200.00m,
|
||||
-1200.00m
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InsertSalary_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.AddElement(It.IsAny<SalaryDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns(new PekarDataModel(salary.PekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.InsertSalary(salary), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContact.Verify(x => x.AddElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_CorrectRecord_Test()
|
||||
{
|
||||
// Arrange
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var flag = false;
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
pekarId,
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.UpdateElement(It.IsAny<SalaryDataModel>()))
|
||||
.Callback((SalaryDataModel x) =>
|
||||
{
|
||||
flag = x.Id == salary.Id && x.PekarId == salary.PekarId && x.Period == salary.Period &&
|
||||
x.BaseRate == salary.BaseRate && x.BonusRate == salary.BonusRate && x.TotalSalary == salary.TotalSalary;
|
||||
});
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act
|
||||
_salaryBusinessLogicContract.UpdateSalary(salary);
|
||||
|
||||
// Assert
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(salary.Id, out _), Is.True);
|
||||
Assert.That(Guid.TryParse(salary.PekarId, out _), Is.True);
|
||||
Assert.That(salary.BaseRate >= 0);
|
||||
Assert.That(salary.BonusRate >= 0);
|
||||
Assert.That(salary.TotalSalary >= 0);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(pekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_PekarNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns((PekarDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.UpdateSalary(salary), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.UpdateElement(It.IsAny<SalaryDataModel>())).Throws(new ElementNotFoundException("Salary not found"));
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns(new PekarDataModel(salary.PekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.UpdateSalary(salary), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_NullRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.UpdateSalary(null), Throws.TypeOf<ArgumentNullException>());
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_InvalidRecord_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.UpdateSalary(new SalaryDataModel(
|
||||
"",
|
||||
"",
|
||||
DateTime.Now,
|
||||
-1000.00m,
|
||||
-200.00m,
|
||||
-1200.00m
|
||||
)), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Never);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateSalary_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var salary = new SalaryDataModel(
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
_salaryStorageContact.Setup(x => x.UpdateElement(It.IsAny<SalaryDataModel>())).Throws(new StorageException(new InvalidOperationException()));
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(salary.PekarId)).Returns(new PekarDataModel(salary.PekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.UpdateSalary(salary), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContact.Verify(x => x.UpdateElement(It.IsAny<SalaryDataModel>()), Times.Once);
|
||||
_pekarStorageContact.Verify(x => x.GetElementById(salary.PekarId), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteSalary_CorrectId_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var salary = new SalaryDataModel(
|
||||
id,
|
||||
pekarId,
|
||||
DateTime.Now,
|
||||
1000.00m,
|
||||
200.00m,
|
||||
1200.00m
|
||||
);
|
||||
var flag = false;
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns(salary);
|
||||
_salaryStorageContact.Setup(x => x.DeleteElement(id)).Callback(() => { flag = true; });
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act
|
||||
_salaryBusinessLogicContract.DeleteSalary(id);
|
||||
|
||||
// Assert
|
||||
_salaryStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
Assert.That(flag);
|
||||
Assert.That(Guid.TryParse(salary.Id, out _), Is.True);
|
||||
Assert.That(Guid.TryParse(salary.PekarId, out _), Is.True);
|
||||
Assert.That(salary.BaseRate >= 0);
|
||||
Assert.That(salary.BonusRate >= 0);
|
||||
Assert.That(salary.TotalSalary >= 0);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteSalary_RecordNotFound_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns((SalaryDataModel)null);
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.DeleteSalary(id), Throws.TypeOf<ElementNotFoundException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteSalary_NullOrEmptyId_ThrowException_Test()
|
||||
{
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.DeleteSalary(null), Throws.TypeOf<ArgumentNullException>());
|
||||
Assert.That(() => _salaryBusinessLogicContract.DeleteSalary(string.Empty), Throws.TypeOf<ArgumentNullException>());
|
||||
_salaryStorageContact.Verify(x => x.DeleteElement(It.IsAny<string>()), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteSalary_InvalidId_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = "invalid";
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.DeleteSalary(id), Throws.TypeOf<ValidationException>());
|
||||
_salaryStorageContact.Verify(x => x.DeleteElement(id), Times.Never);
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Never);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeleteSalary_StorageThrowError_ThrowException_Test()
|
||||
{
|
||||
// Arrange
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var salary = new SalaryDataModel(id, pekarId, DateTime.Now, 1000.00m, 200.00m, 1200.00m);
|
||||
_salaryStorageContact.Setup(x => x.GetElementById(id)).Returns(salary);
|
||||
_salaryStorageContact.Setup(x => x.DeleteElement(id)).Throws(new StorageException(new InvalidOperationException()));
|
||||
_pekarStorageContact.Setup(x => x.GetElementById(pekarId)).Returns(new PekarDataModel(pekarId, "Ivan Ivanov", "Baker", 1.5m, new List<ProductDataModel>()));
|
||||
|
||||
// Act & Assert
|
||||
Assert.That(() => _salaryBusinessLogicContract.DeleteSalary(id), Throws.TypeOf<StorageException>());
|
||||
_salaryStorageContact.Verify(x => x.GetElementById(id), Times.Once);
|
||||
_salaryStorageContact.Verify(x => x.DeleteElement(id), Times.Once);
|
||||
}
|
||||
}
|
||||
}
|
201
CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj
Normal file
201
CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj
Normal file
@ -0,0 +1,201 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="8.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>
|
||||
<LangVersion>latest</LangVersion>
|
||||
</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="Castle.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Castle.Core.5.1.1\lib\net462\Castle.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<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.Bcl.AsyncInterfaces, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Bcl.AsyncInterfaces.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.DependencyInjection.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Logging.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Logging.Abstractions, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Logging.Abstractions.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Logging.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Options, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Options.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Options.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Extensions.Primitives, Version=10.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Extensions.Primitives.10.0.0-preview.1.25080.5\lib\net462\Microsoft.Extensions.Primitives.dll</HintPath>
|
||||
</Reference>
|
||||
<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="Moq, Version=4.20.72.0, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Moq.4.20.72\lib\net462\Moq.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.4.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.6.0\lib\net462\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.ComponentModel.DataAnnotations" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.10.0.0-preview.1.25080.5\lib\net462\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.IO.Pipelines, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.IO.Pipelines.10.0.0-preview.1.25080.5\lib\net462\System.IO.Pipelines.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.6.0\lib\net462\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.6.0\lib\net462\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=6.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.6.1.0\lib\net462\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Text.Encodings.Web, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Encodings.Web.10.0.0-preview.1.25080.5\lib\net462\System.Text.Encodings.Web.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Text.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Text.Json.10.0.0-preview.1.25080.5\lib\net462\System.Text.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.6.0\lib\net462\System.Threading.Tasks.Extensions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll</HintPath>
|
||||
</Reference>
|
||||
<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="BusinessLogicsContractsTests\IngredientBusinessLogicContractTests.cs" />
|
||||
<Compile Include="BusinessLogicsContractsTests\OrderBusinessLogicContractTests.cs" />
|
||||
<Compile Include="BusinessLogicsContractsTests\PekarBusinessLogicContractTests.cs" />
|
||||
<Compile Include="BusinessLogicsContractsTests\PositionBusinessLogicContractTests.cs" />
|
||||
<Compile Include="BusinessLogicsContractsTests\ProductBusinessLogicContractTests.cs" />
|
||||
<Compile Include="BusinessLogicsContractsTests\SalaryBusinessLogicContractTests.cs" />
|
||||
<Compile Include="DataModelsTests\IngredientDataModelTests.cs" />
|
||||
<Compile Include="DataModelsTests\OrderDataModelTests.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" />
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\CandyHouseBase\CandyHouseBase.csproj">
|
||||
<Project>{5df70b46-31f7-4d15-8c60-52c0a0a364f0}</Project>
|
||||
<Name>CandyHouseBase</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="ILLink\ILLink.Descriptors.LibraryBuild.xml" />
|
||||
</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>
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using NUnit.Framework;
|
||||
using CandyHouseBase.DataModels;
|
||||
using CandyHouseBase.Enums;
|
||||
using CandyHouseBase.Exceptions;
|
||||
|
||||
namespace CandyHouseTests.DataModelsTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class OrderDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void CreateOrderDataModel_ValidData_ShouldCreateSuccessfully()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var customerName = "Alice";
|
||||
var orderDate = DateTime.Now;
|
||||
var totalAmount = 100.0m;
|
||||
var discountAmount = 10.0m;
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var statusType = StatusType.Pending;
|
||||
|
||||
var order = new OrderDataModel(id, customerName, orderDate, totalAmount, discountAmount, productId, 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(productId, order.ProductId);
|
||||
Assert.AreEqual(pekarId, order.PekarId);
|
||||
Assert.AreEqual(statusType, order.StatusType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_ValidData_ShouldNotThrowException()
|
||||
{
|
||||
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 Validate_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var order = new OrderDataModel(
|
||||
"",
|
||||
"Alice",
|
||||
DateTime.Now,
|
||||
100.0m,
|
||||
10.0m,
|
||||
Guid.NewGuid().ToString(),
|
||||
Guid.NewGuid().ToString(),
|
||||
StatusType.Pending
|
||||
);
|
||||
|
||||
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,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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, new List<ProductDataModel>());
|
||||
|
||||
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,
|
||||
new List<ProductDataModel>());
|
||||
|
||||
Assert.DoesNotThrow(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidId_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel("", "John Doe", Guid.NewGuid().ToString(), 0, new List<ProductDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_InvalidName_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "", Guid.NewGuid().ToString(), 0,
|
||||
new List<ProductDataModel>());
|
||||
|
||||
Assert.Throws<ValidationException>(() => pekar.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Validate_NegativeExperience_ShouldThrowValidationException()
|
||||
{
|
||||
var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "John Doe", "some-invalidate", 0,
|
||||
new List<ProductDataModel>());
|
||||
|
||||
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,59 @@
|
||||
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());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreatePositionDataModel_TitleWithInvalidCharacters_ShouldThrowValidationException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var type = PositionType.Cool;
|
||||
var invalidTitle = "Manager123";
|
||||
var item = new PositionDataModel(id, type, invalidTitle);
|
||||
|
||||
Assert.Throws<ValidationException>(() => item.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 ingredients = new List<IngredientDataModel>()
|
||||
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||
var product = new ProductDataModel(id, name, description, ingredients);
|
||||
|
||||
Assert.AreEqual(id, product.Id);
|
||||
Assert.AreEqual(name, product.Name);
|
||||
Assert.AreEqual(description, product.Description);
|
||||
Assert.AreEqual(ingredients, product.IngredientsItems);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidId_ShouldThrowArgumentException()
|
||||
{
|
||||
var invalidId = "";
|
||||
var name = "Candy";
|
||||
var description = "Delicious candy";
|
||||
var ingredients = new List<IngredientDataModel>()
|
||||
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||
var product = new ProductDataModel(invalidId, name, description, ingredients);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidName_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var invalidName = "";
|
||||
var description = "Delicious candy";
|
||||
var ingredients = new List<IngredientDataModel>()
|
||||
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||
var product = new ProductDataModel(id, invalidName, description, ingredients);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Candy";
|
||||
var invalidDescription = "";
|
||||
var ingredients = new List<IngredientDataModel>()
|
||||
{ new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) };
|
||||
var product = new ProductDataModel(id, name, invalidDescription, ingredients);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidIngredients_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Candy";
|
||||
var invalidDescription = "";
|
||||
var ingredients = new List<IngredientDataModel>();
|
||||
var product = new ProductDataModel(id, name, invalidDescription, ingredients);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CreateProductDataModel_InvalidIngredientsNull_ShouldThrowArgumentException()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "Candy";
|
||||
var invalidDescription = "";
|
||||
var product = new ProductDataModel(id, name, invalidDescription, null);
|
||||
|
||||
Assert.Throws<ValidationException>(() => product.Validate());
|
||||
}
|
||||
}
|
||||
}
|
@ -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,57 @@
|
||||
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 totalSalary = 1200m;
|
||||
|
||||
var salaryData = new SalaryDataModel(id, pekarId, period, baseRate, bonusRate, 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(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 totalSalary = 1200m;
|
||||
var salary = new SalaryDataModel(invalidId, pekarId, period, baseRate, bonusRate,
|
||||
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 totalSalary = 1200m;
|
||||
var salary = new SalaryDataModel(id, pekarId, period, invalidBaseRate, bonusRate,
|
||||
totalSalary);
|
||||
Assert.Throws<ValidationException>(() => salary.Validate());
|
||||
}
|
||||
}
|
||||
}
|
33
CandyHouseSolution/CandyHouseTests/packages.config
Normal file
33
CandyHouseSolution/CandyHouseTests/packages.config
Normal file
@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Castle.Core" version="5.1.1" targetFramework="net471" />
|
||||
<package id="Microsoft.ApplicationInsights" version="2.22.0" targetFramework="net471" />
|
||||
<package id="Microsoft.Bcl.AsyncInterfaces" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.Logging" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.Logging.Abstractions" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.Options" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Moq" version="4.20.72" targetFramework="net471" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="Microsoft.Extensions.Primitives" version="10.0.0-preview.1.25080.5" 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.6.0" targetFramework="net471" />
|
||||
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net471" />
|
||||
<package id="System.IO.Pipelines" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="System.Memory" version="4.6.0" targetFramework="net471" />
|
||||
<package id="System.Numerics.Vectors" version="4.6.0" targetFramework="net471" />
|
||||
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net471" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="6.1.0" targetFramework="net471" />
|
||||
<package id="System.Text.Encodings.Web" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="System.Text.Json" version="10.0.0-preview.1.25080.5" targetFramework="net471" />
|
||||
<package id="System.Threading.Tasks.Extensions" version="4.6.0" targetFramework="net471" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net471" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user