diff --git a/CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj b/CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj new file mode 100644 index 0000000..1a8ba7a --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/CandyHouseBase.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {5DF70B46-31F7-4D15-8C60-52C0A0A364F0} + Exe + Properties + CandyHouseBase + CandyHouseBase + v4.7.1 + 512 + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/IngredientDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/IngredientDataModel.cs new file mode 100644 index 0000000..60265c3 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/IngredientDataModel.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/OrderDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/OrderDataModel.cs new file mode 100644 index 0000000..cb7b168 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/OrderDataModel.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/PekarDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/PekarDataModel.cs new file mode 100644 index 0000000..84a0747 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/PekarDataModel.cs @@ -0,0 +1,32 @@ +using CandyHouseBase.Exceptions; +using CandyHouseBase.Infrastructure; +using CandyHouseBase.Extensions; + +namespace CandyHouseBase.DataModels +{ + public class PekarDataModel : IValidation + { + public string Id { get; private set; } + public string FIO { get; private set; } + public string Position { get; private set; } + public decimal BonusCoefficient { get; private set; } + + public PekarDataModel(string id, string fio, string position, decimal bonusCoefficient) + { + Id = id; + FIO = fio; + Position = position; + BonusCoefficient = bonusCoefficient; + } + + public void Validate() + { + if (Id.IsEmpty()) throw new ValidationException("Field Id is empty"); + if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID"); + if (FIO.IsEmpty()) throw new ValidationException("Field FIO is empty"); + if (Position.IsEmpty()) throw new ValidationException("Field Position is empty"); + if (!Position.IsGuid()) throw new ValidationException("Field must be a GUID"); + if (BonusCoefficient <= 0) throw new ValidationException("BonusCoefficient must be positive"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/PekarHistoryDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/PekarHistoryDataModel.cs new file mode 100644 index 0000000..d49aa6c --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/PekarHistoryDataModel.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/PositionDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/PositionDataModel.cs new file mode 100644 index 0000000..896f603 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/PositionDataModel.cs @@ -0,0 +1,30 @@ +using System; +using CandyHouseBase.Enums; +using CandyHouseBase.Exceptions; +using CandyHouseBase.Extensions; +using CandyHouseBase.Infrastructure; + +namespace CandyHouseBase.DataModels +{ + public class PositionDataModel : IValidation + { + public string Id { get; set; } + public PositionType Type { get; set; } + public string Title { get; set; } + + public PositionDataModel(string id, PositionType type, string title) + { + Id = id; + Type = type; + Title = title; + } + + public void Validate() + { + if (Id.IsEmpty()) throw new ValidationException("Field Id is empty"); + if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID"); + if (string.IsNullOrEmpty(Title)) throw new ValidationException("Field Title is empty"); + if (!Enum.IsDefined(typeof(PositionType), Type)) throw new ValidationException("Invalid PositionType"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/ProductDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/ProductDataModel.cs new file mode 100644 index 0000000..6fa71ac --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/ProductDataModel.cs @@ -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 IngredientsItems { get; private set; } + + public ProductDataModel(string id, string name, string description, List 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"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/RecipeDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/RecipeDataModel.cs new file mode 100644 index 0000000..fbe97d2 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/RecipeDataModel.cs @@ -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"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/DataModels/SalaryDataModel.cs b/CandyHouseSolution/CandyHouseBase/DataModels/SalaryDataModel.cs new file mode 100644 index 0000000..c15b2b6 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/DataModels/SalaryDataModel.cs @@ -0,0 +1,41 @@ +using System; +using CandyHouseBase.Exceptions; +using CandyHouseBase.Extensions; +using CandyHouseBase.Infrastructure; + +namespace CandyHouseBase.DataModels +{ + public class SalaryDataModel : IValidation + { + public string Id { get; private set; } + public string PekarId { get; private set; } + public DateTime Period { get; private set; } + public decimal BaseRate { get; private set; } + public decimal BonusRate { get; private set; } + public int TotalQuantity { get; private set; } + public decimal TotalSalary { get; private set; } + + public SalaryDataModel(string id, string pekarId, DateTime period, decimal baseRate, decimal bonusRate, int totalQuantity, decimal totalSalary) + { + Id = id; + PekarId = pekarId; + Period = period; + BaseRate = baseRate; + BonusRate = bonusRate; + TotalQuantity = totalQuantity; + TotalSalary = totalSalary; + } + + public void Validate() + { + if (Id.IsEmpty()) throw new ValidationException("Field Id is empty"); + if (!Id.IsGuid()) throw new ValidationException("Id must be a GUID"); + if (PekarId.IsEmpty()) throw new ValidationException("Field PekarId is empty"); + if (!PekarId.IsGuid()) throw new ValidationException("PekarId must be a GUID"); + if (BaseRate < 0) throw new ValidationException("BaseRate cannot be negative"); + if (BonusRate < 0) throw new ValidationException("BonusRate cannot be negative"); + if (TotalQuantity < 0) throw new ValidationException("TotalQuantity cannot be negative"); + if (TotalSalary < 0) throw new ValidationException("TotalSalary cannot be negative"); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Enums/PositionType.cs b/CandyHouseSolution/CandyHouseBase/Enums/PositionType.cs new file mode 100644 index 0000000..8313553 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Enums/PositionType.cs @@ -0,0 +1,10 @@ +namespace CandyHouseBase.Enums +{ + public enum PositionType + { + None = 1, + Small = 2, + Medium = 3, + Cool = 4, + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Enums/StatusType.cs b/CandyHouseSolution/CandyHouseBase/Enums/StatusType.cs new file mode 100644 index 0000000..57a81fa --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Enums/StatusType.cs @@ -0,0 +1,10 @@ +namespace CandyHouseBase.Enums +{ + public enum StatusType + { + Pending, + Completed, + Cancelled, + InProgress + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Exceptions/ValidationException.cs b/CandyHouseSolution/CandyHouseBase/Exceptions/ValidationException.cs new file mode 100644 index 0000000..97af727 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Exceptions/ValidationException.cs @@ -0,0 +1,9 @@ +using System; + +namespace CandyHouseBase.Exceptions +{ + public class ValidationException : Exception + { + public ValidationException(string message) : base(message) { } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Extensions/StringExtensions.cs b/CandyHouseSolution/CandyHouseBase/Extensions/StringExtensions.cs new file mode 100644 index 0000000..17e6077 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Extensions/StringExtensions.cs @@ -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 _); + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Infrastructure/IValidation.cs b/CandyHouseSolution/CandyHouseBase/Infrastructure/IValidation.cs new file mode 100644 index 0000000..07c21c6 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Infrastructure/IValidation.cs @@ -0,0 +1,7 @@ +namespace CandyHouseBase.Infrastructure +{ + public interface IValidation + { + void Validate(); + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseBase/Program.cs b/CandyHouseSolution/CandyHouseBase/Program.cs new file mode 100644 index 0000000..9fda858 --- /dev/null +++ b/CandyHouseSolution/CandyHouseBase/Program.cs @@ -0,0 +1,9 @@ +namespace CandyHouseBase +{ + public class Program + { + public static void Main(string[] args) + { + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseSolution.sln b/CandyHouseSolution/CandyHouseSolution.sln new file mode 100644 index 0000000..1cc98dd --- /dev/null +++ b/CandyHouseSolution/CandyHouseSolution.sln @@ -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 diff --git a/CandyHouseSolution/CandyHouseTests/App.config b/CandyHouseSolution/CandyHouseTests/App.config new file mode 100644 index 0000000..74b8a4e --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/App.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj b/CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj new file mode 100644 index 0000000..760ff16 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/CandyHouseTests.csproj @@ -0,0 +1,145 @@ + + + + + + + + + Debug + AnyCPU + {396EA8C4-6102-479E-83A2-C83E6B74A14E} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Properties + CandyHouseTests + CandyHouseTests + v4.7.1 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.ApplicationInsights.2.22.0\lib\net46\Microsoft.ApplicationInsights.dll + + + + ..\packages\Microsoft.Testing.Platform.MSBuild.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.MSBuild.dll + + + ..\packages\Microsoft.Testing.Extensions.Telemetry.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.Telemetry.dll + + + ..\packages\Microsoft.Testing.Extensions.TrxReport.Abstractions.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.TrxReport.Abstractions.dll + + + ..\packages\Microsoft.Testing.Extensions.VSTestBridge.1.5.3\lib\netstandard2.0\Microsoft.Testing.Extensions.VSTestBridge.dll + + + ..\packages\Microsoft.Testing.Platform.1.5.3\lib\netstandard2.0\Microsoft.Testing.Platform.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.CoreUtilities.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.TestPlatform.PlatformAbstractions.dll + + + ..\packages\Microsoft.TestPlatform.ObjectModel.17.12.0\lib\net462\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll + + + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll + + + + + + ..\packages\System.Diagnostics.DiagnosticSource.5.0.0\lib\net46\System.Diagnostics.DiagnosticSource.dll + + + ..\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll + + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll + + + + ..\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll + + + + + ..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll + + + + + + + + + + + + + + + + + + + {5df70b46-31f7-4d15-8c60-52c0a0a364f0} + CandyHouseBase + + + + + + 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}. + + + + + + + + + + + + + diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/IngredientDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/IngredientDataModelTests.cs new file mode 100644 index 0000000..ad01684 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/IngredientDataModelTests.cs @@ -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(() => ingredient.Validate()); + } + + [Test] + public void Validate_InvalidName_ShouldThrowValidationException() + { + var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "", "kg", 10); + + Assert.Throws(() => ingredient.Validate()); + } + + [Test] + public void Validate_NegativeQuantity_ShouldThrowValidationException() + { + var ingredient = new IngredientDataModel(Guid.NewGuid().ToString(), "Sugar", "kg", -5); + + Assert.Throws(() => ingredient.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/OrderDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/OrderDataModelTests.cs new file mode 100644 index 0000000..2e4a46a --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/OrderDataModelTests.cs @@ -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(() => 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(() => 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(() => order.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarDataModelTests.cs new file mode 100644 index 0000000..d3bd2d3 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarDataModelTests.cs @@ -0,0 +1,57 @@ +using System; +using NUnit.Framework; +using CandyHouseBase.DataModels; +using CandyHouseBase.Exceptions; + +namespace CandyHouseTests.DataModelsTests +{ + [TestFixture] + public class PekarDataModelTests + { + [Test] + public void CreatePekarDataModel_ValidData_ShouldCreateSuccessfully() + { + var id = Guid.NewGuid().ToString(); + var name = "John Doe"; + var experience = Guid.NewGuid().ToString(); + + var pekar = new PekarDataModel(id, name, experience, 0); + + Assert.AreEqual(id, pekar.Id); + Assert.AreEqual(name, pekar.FIO); + Assert.AreEqual(experience, pekar.Position); + } + + [Test] + public void Validate_ValidData_ShouldNotThrowException() + { + var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "John Doe", Guid.NewGuid().ToString(), 6); + + Assert.DoesNotThrow(() => pekar.Validate()); + } + + [Test] + public void Validate_InvalidId_ShouldThrowValidationException() + { + var pekar = new PekarDataModel("", "John Doe", Guid.NewGuid().ToString(), 0); + + Assert.Throws(() => pekar.Validate()); + } + + [Test] + public void Validate_InvalidName_ShouldThrowValidationException() + { + var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "", Guid.NewGuid().ToString(), 0); + + Assert.Throws(() => pekar.Validate()); + } + + [Test] + public void Validate_NegativeExperience_ShouldThrowValidationException() + { + var pekar = new PekarDataModel(Guid.NewGuid().ToString(), "John Doe", "some-invalidate", 0); + + Assert.Throws(() => pekar.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarHistoryModelDataTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarHistoryModelDataTests.cs new file mode 100644 index 0000000..79c6dfb --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PekarHistoryModelDataTests.cs @@ -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); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/PositionDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PositionDataModelTests.cs new file mode 100644 index 0000000..1ecc770 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/PositionDataModelTests.cs @@ -0,0 +1,48 @@ +using System; +using CandyHouseBase.DataModels; +using CandyHouseBase.Enums; +using CandyHouseBase.Exceptions; +using NUnit.Framework; + +namespace CandyHouseTests.DataModelsTests +{ + [TestFixture] + public class PositionDataModelTests + { + [Test] + public void CreatePositionDataModel_ValidData_ShouldCreateSuccessfully() + { + var id = Guid.NewGuid().ToString(); + var type = PositionType.Cool; + var title = "Manager"; + + var position = new PositionDataModel(id, type, title); + + Assert.AreEqual(id, position.Id); + Assert.AreEqual(type, position.Type); + Assert.AreEqual(title, position.Title); + } + + [Test] + public void CreatePositionDataModel_InvalidId_ShouldThrowArgumentException() + { + var invalidId = ""; + var type = PositionType.Cool; + var title = "Manager"; + var item = new PositionDataModel(invalidId, type, title); + + Assert.Throws(() => 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(() => item.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/ProductDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/ProductDataModelTests.cs new file mode 100644 index 0000000..bfabcf1 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/ProductDataModelTests.cs @@ -0,0 +1,79 @@ +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() + { 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() + { new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) }; + var product = new ProductDataModel(invalidId, name, description, ingredients); + + Assert.Throws(() => product.Validate()); + } + + [Test] + public void CreateProductDataModel_InvalidName_ShouldThrowArgumentException() + { + var id = Guid.NewGuid().ToString(); + var invalidName = ""; + var description = "Delicious candy"; + var ingredients = new List() + { new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) }; + var product = new ProductDataModel(id, invalidName, description, ingredients); + + Assert.Throws(() => product.Validate()); + } + + [Test] + public void CreateProductDataModel_InvalidDescription_ShouldThrowArgumentException() + { + var id = Guid.NewGuid().ToString(); + var name = "Candy"; + var invalidDescription = ""; + var ingredients = new List() + { new IngredientDataModel(Guid.NewGuid().ToString(), "sugar", "Sugar", 10) }; + var product = new ProductDataModel(id, name, invalidDescription, ingredients); + + Assert.Throws(() => product.Validate()); + } + + [Test] + public void CreateProductDataModel_InvalidIngredients_ShouldThrowArgumentException() + { + var id = Guid.NewGuid().ToString(); + var name = "Candy"; + var invalidDescription = ""; + var ingredients = new List(); + var product = new ProductDataModel(id, name, invalidDescription, ingredients); + + Assert.Throws(() => product.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/RecipeDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/RecipeDataModelTests.cs new file mode 100644 index 0000000..d9314d7 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/RecipeDataModelTests.cs @@ -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(() => 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(() => 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(() => recipe.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/DataModelsTests/SalaryDataModelTests.cs b/CandyHouseSolution/CandyHouseTests/DataModelsTests/SalaryDataModelTests.cs new file mode 100644 index 0000000..98c37f0 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/DataModelsTests/SalaryDataModelTests.cs @@ -0,0 +1,61 @@ +using System; +using CandyHouseBase.DataModels; +using CandyHouseBase.Exceptions; +using NUnit.Framework; + +namespace CandyHouseTests.DataModelsTests +{ + public class SalaryDataModelTests + { + [Test] + public void CreateSalaryDataModel_ValidData_ShouldCreateSuccessfully() + { + var id = Guid.NewGuid().ToString(); + var pekarId = Guid.NewGuid().ToString(); + var period = new DateTime(2023, 10, 1); + var baseRate = 1000m; + var bonusRate = 200m; + var totalQuantity = 50; + var totalSalary = 1200m; + + var salaryData = new SalaryDataModel(id, pekarId, period, baseRate, bonusRate, totalQuantity, totalSalary); + + Assert.AreEqual(id, salaryData.Id); + Assert.AreEqual(pekarId, salaryData.PekarId); + Assert.AreEqual(period, salaryData.Period); + Assert.AreEqual(baseRate, salaryData.BaseRate); + Assert.AreEqual(bonusRate, salaryData.BonusRate); + Assert.AreEqual(totalQuantity, salaryData.TotalQuantity); + Assert.AreEqual(totalSalary, salaryData.TotalSalary); + } + + [Test] + public void CreateSalaryDataModel_InvalidId_ShouldThrowValidationException() + { + var invalidId = ""; + var pekarId = Guid.NewGuid().ToString(); + var period = new DateTime(2023, 10, 1); + var baseRate = 1000m; + var bonusRate = 200m; + var totalQuantity = 50; + var totalSalary = 1200m; + var salary = new SalaryDataModel(invalidId, pekarId, period, baseRate, bonusRate, totalQuantity, + totalSalary); + Assert.Throws(() => salary.Validate());} + + [Test] + public void CreateSalaryDataModel_InvalidBaseRate_ShouldThrowValidationException() + { + var id = Guid.NewGuid().ToString(); + var pekarId = Guid.NewGuid().ToString(); + var period = new DateTime(2023, 10, 1); + var invalidBaseRate = -1000m; + var bonusRate = 200m; + var totalQuantity = 50; + var totalSalary = 1200m; + var salary = new SalaryDataModel(id, pekarId, period, invalidBaseRate, bonusRate, totalQuantity, + totalSalary); + Assert.Throws(() => salary.Validate()); + } + } +} \ No newline at end of file diff --git a/CandyHouseSolution/CandyHouseTests/packages.config b/CandyHouseSolution/CandyHouseTests/packages.config new file mode 100644 index 0000000..f1136e5 --- /dev/null +++ b/CandyHouseSolution/CandyHouseTests/packages.config @@ -0,0 +1,19 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file