Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
0061693eff | |||
825133bed3 | |||
03057e83bd | |||
7be921eb29 | |||
9ce5690584 | |||
48da4621c6 |
67
CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj
Normal file
67
CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj
Normal file
@ -0,0 +1,67 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props"
|
||||
Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')"/>
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{5DF70B46-31F7-4D15-8C60-52C0A0A364F0}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CandyHouseBase</RootNamespace>
|
||||
<AssemblyName>CandyHouseBase</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System"/>
|
||||
<Reference Include="System.Core"/>
|
||||
<Reference Include="System.Data"/>
|
||||
<Reference Include="System.Xml"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataModels\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\ValidationException.cs" />
|
||||
<Compile Include="Extensions\StringExtensions.cs" />
|
||||
<Compile Include="Infrastructure\IValidation.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"/>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
|
||||
</Project>
|
@ -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,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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 OrderId { 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 orderId, string pekarId, StatusType statusType)
|
||||
{
|
||||
Id = id;
|
||||
CustomerName = customerName;
|
||||
OrderDate = orderDate;
|
||||
TotalAmount = totalAmount;
|
||||
DiscountAmount = discountAmount;
|
||||
OrderId = orderId;
|
||||
PekarId = pekarId;
|
||||
StatusType = statusType;
|
||||
}
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (Id.IsEmpty()) throw new ValidationException("Field Id is empty");
|
||||
if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID");
|
||||
if (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 (OrderId.IsEmpty()) throw new ValidationException("Field OrderId is empty");
|
||||
if (!OrderId.IsGuid()) throw new ValidationException("OrderId 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;
|
||||
private set
|
||||
{
|
||||
if (!name.IsEmpty()) OldName = name;
|
||||
name = value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public string Description
|
||||
{
|
||||
get => description;
|
||||
private set
|
||||
{
|
||||
if (!description.IsEmpty()) OldDescription = description;
|
||||
description = value.Trim();
|
||||
}
|
||||
}
|
||||
|
||||
public string OldName { get; private set; }
|
||||
|
||||
public string OldDescription { get; private set; }
|
||||
|
||||
private string name;
|
||||
private string description;
|
||||
|
||||
public 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,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,7 @@
|
||||
namespace CandyHouseBase.Infrastructure
|
||||
{
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
||||
}
|
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
|
10
CandyHouseSolution/CandyHouseTests/App.config
Normal file
10
CandyHouseSolution/CandyHouseTests/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.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
145
CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj
Normal file
145
CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj
Normal file
@ -0,0 +1,145 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props" Condition="Exists('..\packages\NUnit3TestAdapter.5.0.0\build\net462\NUnit3TestAdapter.props')" />
|
||||
<Import Project="..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props" Condition="Exists('..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\build\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.props')" />
|
||||
<Import Project="..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props" Condition="Exists('..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\build\Microsoft.Testing.Platform.MSBuild.props')" />
|
||||
<Import Project="..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props" Condition="Exists('..\packages\Microsoft.Testing.Platform.1.5.3\build\netstandard2.0\Microsoft.Testing.Platform.props')" />
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{396EA8C4-6102-479E-83A2-C83E6B74A14E}</ProjectGuid>
|
||||
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>CandyHouseTests</RootNamespace>
|
||||
<AssemblyName>CandyHouseTests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.ApplicationInsights, Version=2.22.0.997, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="Microsoft.Testing.Extensions.MSBuild, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.MSBuild.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Extensions.Telemetry, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Extensions.TrxReport.Abstractions, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Extensions.VSTestBridge, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Testing.Platform, Version=1.5.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.Testing.Platform.1.5.3\lib\netstandard2.0\Microsoft.Testing.Platform.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.CoreUtilities, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.TestPlatform.PlatformAbstractions, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib" />
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Buffers, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Diagnostics.DiagnosticSource, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Diagnostics.DiagnosticSource.5.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Numerics" />
|
||||
<Reference Include="System.Numerics.Vectors, Version=4.1.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime" />
|
||||
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
|
||||
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DataModelsTests\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>
|
||||
<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,104 @@
|
||||
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 orderId = Guid.NewGuid().ToString();
|
||||
var pekarId = Guid.NewGuid().ToString();
|
||||
var statusType = StatusType.Pending;
|
||||
|
||||
var order = new OrderDataModel(id, customerName, orderDate, totalAmount, discountAmount, orderId, pekarId, statusType);
|
||||
|
||||
Assert.AreEqual(id, order.Id);
|
||||
Assert.AreEqual(customerName, order.CustomerName);
|
||||
Assert.AreEqual(orderDate, order.OrderDate);
|
||||
Assert.AreEqual(totalAmount, order.TotalAmount);
|
||||
Assert.AreEqual(discountAmount, order.DiscountAmount);
|
||||
Assert.AreEqual(orderId, order.OrderId);
|
||||
Assert.AreEqual(pekarId, order.PekarId);
|
||||
Assert.AreEqual(statusType, order.StatusType);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void 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());
|
||||
}
|
||||
}
|
||||
}
|
19
CandyHouseSolution/CandyHouseTests/packages.config
Normal file
19
CandyHouseSolution/CandyHouseTests/packages.config
Normal file
@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.ApplicationInsights" version="2.22.0" targetFramework="net471" />
|
||||
<package id="Microsoft.TestPlatform.ObjectModel" version="17.12.0" targetFramework="net471" />
|
||||
<package id="Microsoft.Testing.Extensions.Telemetry" version="1.5.3" targetFramework="net471" />
|
||||
<package id="Microsoft.Testing.Extensions.TrxReport.Abstractions" version="1.5.3" targetFramework="net471" />
|
||||
<package id="Microsoft.Testing.Extensions.VSTestBridge" version="1.5.3" targetFramework="net471" />
|
||||
<package id="Microsoft.Testing.Platform" version="1.5.3" targetFramework="net471" />
|
||||
<package id="Microsoft.Testing.Platform.MSBuild" version="1.5.3" targetFramework="net471" />
|
||||
<package id="NUnit" version="3.5.0" targetFramework="net45" />
|
||||
<package id="NUnit3TestAdapter" version="5.0.0" targetFramework="net471" />
|
||||
<package id="System.Buffers" version="4.5.1" targetFramework="net471" />
|
||||
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net471" />
|
||||
<package id="System.Diagnostics.DiagnosticSource" version="5.0.0" targetFramework="net471" />
|
||||
<package id="System.Memory" version="4.5.4" targetFramework="net471" />
|
||||
<package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net471" />
|
||||
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net471" />
|
||||
<package id="System.Runtime.CompilerServices.Unsafe" version="5.0.0" targetFramework="net471" />
|
||||
</packages>
|
Loading…
x
Reference in New Issue
Block a user