ISEbd-21_Savelyev.P.Y._PimpMyRide_Task1 #1
@@ -1,10 +1,12 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.12.35527.113 d17.12
|
VisualStudioVersion = 17.12.35527.113
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PimpMyRide", "PimpMyRide\PimpMyRide.csproj", "{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PimpMyRide", "PimpMyRide\PimpMyRide.csproj", "{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PimpMyRideTest", "PimpMyRideTest\PimpMyRideTest.csproj", "{B9E83569-89AA-4293-BC57-84FD67CE584E}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@@ -15,6 +17,10 @@ Global
|
|||||||
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Release|Any CPU.Build.0 = Release|Any CPU
|
{0DF3EFC4-9A6D-4325-9C25-16F971E4BC53}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B9E83569-89AA-4293-BC57-84FD67CE584E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B9E83569-89AA-4293-BC57-84FD67CE584E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B9E83569-89AA-4293-BC57-84FD67CE584E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B9E83569-89AA-4293-BC57-84FD67CE584E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
42
PimpMyRide/PimpMyRide/DataModels/CarDataModel.cs
Normal file
42
PimpMyRide/PimpMyRide/DataModels/CarDataModel.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class CarDataModel(string id, string clientId, string make, string model, string stateNumber) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public string ClientId { get; private set; } = clientId;
|
||||||
|
|
||||||
|
public string Make { get; private set; } = make;
|
||||||
|
|
||||||
|
public string Model { get; private set; } = model;
|
||||||
|
|
||||||
|
public string StateNumber { get; private set; } = stateNumber;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||||
|
|
||||||
|
if (ClientId.IsEmpty())
|
||||||
|
throw new ValidationException("Field CustomerId is empty");
|
||||||
|
|
||||||
|
if (!ClientId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field CustomerId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Make.IsEmpty())
|
||||||
|
throw new ValidationException("Field Make is empty");
|
||||||
|
|
||||||
|
if (Model.IsEmpty())
|
||||||
|
throw new ValidationException("Field Model is empty");
|
||||||
|
|
||||||
|
if (StateNumber.IsEmpty())
|
||||||
|
throw new ValidationException("Field StateNumber is empty");
|
||||||
|
}
|
||||||
|
}
|
||||||
33
PimpMyRide/PimpMyRide/DataModels/ClientDataModel.cs
Normal file
33
PimpMyRide/PimpMyRide/DataModels/ClientDataModel.cs
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class ClientDataModel(string id, string fio, string phoneNumber) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public string FIO { get; private set; } = fio;
|
||||||
|
|
||||||
|
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not an unique identifier");
|
||||||
|
|
||||||
|
if (FIO.IsEmpty())
|
||||||
|
throw new ValidationException("Field FIO is empty");
|
||||||
|
|
||||||
|
if (PhoneNumber.IsEmpty())
|
||||||
|
throw new ValidationException("Field PhoneNumber is empty");
|
||||||
|
|
||||||
|
if (!Regex.IsMatch(PhoneNumber, @"^((\+7|7|8)+([0-9]){10})$"))
|
||||||
|
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||||
|
}
|
||||||
|
}
|
||||||
35
PimpMyRide/PimpMyRide/DataModels/MaterialDataModel.cs
Normal file
35
PimpMyRide/PimpMyRide/DataModels/MaterialDataModel.cs
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class MaterialDataModel(string id, MaterialType materialType, string description, double unitCost) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public MaterialType MaterialType { get; private set; } = materialType;
|
||||||
|
|
||||||
|
public string Description { get; private set; } = description;
|
||||||
|
|
||||||
|
public double UnitCost { get; private set; } = unitCost;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not an unique identifier");
|
||||||
|
|
||||||
|
if (MaterialType == MaterialType.None)
|
||||||
|
throw new ValidationException("Field MaterialType is empty");
|
||||||
|
|
||||||
|
if (Description.IsEmpty())
|
||||||
|
throw new ValidationException("Field Description is empty");
|
||||||
|
|
||||||
|
if (UnitCost < 0)
|
||||||
|
throw new ValidationException("Cost cannot be zero or less");
|
||||||
|
}
|
||||||
|
}
|
||||||
26
PimpMyRide/PimpMyRide/DataModels/MaterialHistoryDataModel.cs
Normal file
26
PimpMyRide/PimpMyRide/DataModels/MaterialHistoryDataModel.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class MaterialHistoryDataModel(string materialId, double oldPrice) : IValidation
|
||||||
|
{
|
||||||
|
public string MaterialId { get; private set; } = materialId;
|
||||||
|
|
||||||
|
public double OldPrice { get; private set; } = oldPrice;
|
||||||
|
|
||||||
|
public DateTime ChangeDate { get; private set;} = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (MaterialId.IsEmpty())
|
||||||
|
throw new ValidationException("Field MaterialId is empty");
|
||||||
|
|
||||||
|
if (!MaterialId.IsGuid())
|
||||||
|
throw new ValidationException("The value in field MaterialId is not an unique identifier");
|
||||||
|
|
||||||
|
if (OldPrice <= 0)
|
||||||
|
throw new ValidationException("OldPrice value cannnot be less or equal to '0'");
|
||||||
|
}
|
||||||
|
}
|
||||||
41
PimpMyRide/PimpMyRide/DataModels/OrderDataModel.cs
Normal file
41
PimpMyRide/PimpMyRide/DataModels/OrderDataModel.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class OrderDataModel(string id, string carId, double totalCost, bool isCancel, List<OrderServiceDataModel> services) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public string CarId { get; private set; } = carId;
|
||||||
|
|
||||||
|
public DateTime OrderDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
|
public double TotalCost { get; private set; } = totalCost;
|
||||||
|
|
||||||
|
public bool IsCancel { get; private set; } = isCancel;
|
||||||
|
|
||||||
|
public List<OrderServiceDataModel> Services { get; private set; } = services;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not an unique identifier");
|
||||||
|
|
||||||
|
if (CarId.IsEmpty())
|
||||||
|
throw new ValidationException("Field CarId is empty");
|
||||||
|
|
||||||
|
if (!CarId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field CarId is not an unique identifier");
|
||||||
|
|
||||||
|
if (TotalCost <= 0)
|
||||||
|
throw new ValidationException("TotalCost cannot be 0 or less");
|
||||||
|
|
||||||
|
if ((Services?.Count ?? 0) == 0)
|
||||||
|
throw new ValidationException("The order must include Services");
|
||||||
|
}
|
||||||
|
}
|
||||||
32
PimpMyRide/PimpMyRide/DataModels/OrderServiceDataModel.cs
Normal file
32
PimpMyRide/PimpMyRide/DataModels/OrderServiceDataModel.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class OrderServiceDataModel(string orderId, string serviceId, int count) : IValidation
|
||||||
|
{
|
||||||
|
public string OrderId { get; private set; } = orderId;
|
||||||
|
|
||||||
|
public string ServiceId { get; private set; } = serviceId;
|
||||||
|
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (OrderId.IsEmpty())
|
||||||
|
throw new ValidationException("Field OrderId is empty");
|
||||||
|
|
||||||
|
if (!OrderId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field OrderId is not a unique identifier");
|
||||||
|
|
||||||
|
if (ServiceId.IsEmpty())
|
||||||
|
throw new ValidationException("Field ServiceId is empty");
|
||||||
|
|
||||||
|
if (!ServiceId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
43
PimpMyRide/PimpMyRide/DataModels/ServiceDataModel.cs
Normal file
43
PimpMyRide/PimpMyRide/DataModels/ServiceDataModel.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class ServiceDataModel(string id, string workerId, WorkType workType, double cost, List<ServiceMaterialDataModel> materials) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public string WorkerId { get; private set; } = workerId;
|
||||||
|
|
||||||
|
public WorkType WorkType { get; private set; } = workType;
|
||||||
|
|
||||||
|
public double CostWithMaterials { get; private set; } = cost;
|
||||||
|
|
||||||
|
public List<ServiceMaterialDataModel> Materials { get; private set; } = materials;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not an unique identifier");
|
||||||
|
|
||||||
|
if (WorkerId.IsEmpty())
|
||||||
|
throw new ValidationException("Field WorkerId is empty");
|
||||||
|
|
||||||
|
if (!WorkerId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field WorkerId is not an unique identifier");
|
||||||
|
|
||||||
|
if (WorkType == WorkType.None)
|
||||||
|
throw new ValidationException("Field WorkType is empty");
|
||||||
|
|
||||||
|
if (CostWithMaterials <= 0)
|
||||||
|
throw new ValidationException("CostWithMaterials cannot be 0 or less");
|
||||||
|
|
||||||
|
if ((Materials?.Count ?? 0) == 0)
|
||||||
|
throw new ValidationException("The service must include Materials");
|
||||||
|
}
|
||||||
|
}
|
||||||
32
PimpMyRide/PimpMyRide/DataModels/ServiceMaterialDataModel.cs
Normal file
32
PimpMyRide/PimpMyRide/DataModels/ServiceMaterialDataModel.cs
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class ServiceMaterialDataModel(string serviceId, string materialId, int count) : IValidation
|
||||||
|
{
|
||||||
|
public string ServiceId { get; private set; } = serviceId;
|
||||||
|
|
||||||
|
public string MaterialId { get; private set; } = materialId;
|
||||||
|
|
||||||
|
public int Count { get; private set; } = count;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (ServiceId.IsEmpty())
|
||||||
|
throw new ValidationException("Field ServiceId is empty");
|
||||||
|
|
||||||
|
if (!ServiceId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
|
||||||
|
|
||||||
|
if (MaterialId.IsEmpty())
|
||||||
|
throw new ValidationException("Field MaterialId is empty");
|
||||||
|
|
||||||
|
if (!MaterialId.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field MaterialId is not a unique identifier");
|
||||||
|
|
||||||
|
if (Count <= 0)
|
||||||
|
throw new ValidationException("Field Count is less than or equal to 0");
|
||||||
|
}
|
||||||
|
}
|
||||||
45
PimpMyRide/PimpMyRide/DataModels/WorkerDataModel.cs
Normal file
45
PimpMyRide/PimpMyRide/DataModels/WorkerDataModel.cs
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
using PimpMyRide.Extensions;
|
||||||
|
using PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
namespace PimpMyRide.DataModels;
|
||||||
|
|
||||||
|
public class WorkerDataModel(string id, string fio, SpecialityType specialityType, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||||
|
{
|
||||||
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
|
public string FIO { get; private set; } = fio;
|
||||||
|
|
||||||
|
public SpecialityType SpecialityType { get; private set; } = specialityType;
|
||||||
|
|
||||||
|
public DateTime BirthDate { get; private set; } = birthDate;
|
||||||
|
|
||||||
|
public DateTime EmploymentDate { get; private set; } = employmentDate;
|
||||||
|
|
||||||
|
public bool IsDeleted { get; private set; } = isDeleted;
|
||||||
|
|
||||||
|
public void Validate()
|
||||||
|
{
|
||||||
|
if (Id.IsEmpty())
|
||||||
|
throw new ValidationException("Field Id is empty");
|
||||||
|
|
||||||
|
if (!Id.IsGuid())
|
||||||
|
throw new ValidationException("The value in the field Id is not an unique identifier");
|
||||||
|
|
||||||
|
if (FIO.IsEmpty())
|
||||||
|
throw new ValidationException("Field FIO is empty");
|
||||||
|
|
||||||
|
if (SpecialityType == SpecialityType.None)
|
||||||
|
throw new ValidationException("Field SpecialityType is empty");
|
||||||
|
|
||||||
|
if (BirthDate.Date > DateTime.Now.AddYears(-18).Date)
|
||||||
|
throw new ValidationException($"Minors cannot be hired (BirthDate = {BirthDate.ToShortDateString()})");
|
||||||
|
|
||||||
|
if (EmploymentDate.Date < BirthDate.Date)
|
||||||
|
throw new ValidationException("The date of employment cannot be less than the date of birth");
|
||||||
|
|
||||||
|
if ((EmploymentDate - BirthDate).TotalDays / 365 < 16)
|
||||||
|
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||||
|
}
|
||||||
|
}
|
||||||
10
PimpMyRide/PimpMyRide/Enums/MaterialType.cs
Normal file
10
PimpMyRide/PimpMyRide/Enums/MaterialType.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PimpMyRide.Enums;
|
||||||
|
|
||||||
|
public enum MaterialType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
SmallConsumables = 1,
|
||||||
|
BodyParts = 2,
|
||||||
|
EngineParts = 3,
|
||||||
|
Wheels = 4
|
||||||
|
}
|
||||||
10
PimpMyRide/PimpMyRide/Enums/SpecialityType.cs
Normal file
10
PimpMyRide/PimpMyRide/Enums/SpecialityType.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PimpMyRide.Enums;
|
||||||
|
|
||||||
|
public enum SpecialityType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
TireFitter = 1,
|
||||||
|
BodyWorker = 2,
|
||||||
|
MaintenanceWorker = 3,
|
||||||
|
Mechanic = 4
|
||||||
|
}
|
||||||
10
PimpMyRide/PimpMyRide/Enums/WorkType.cs
Normal file
10
PimpMyRide/PimpMyRide/Enums/WorkType.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace PimpMyRide.Enums;
|
||||||
|
|
||||||
|
public enum WorkType
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Wheels = 1,
|
||||||
|
Body = 2,
|
||||||
|
Maintenance = 3,
|
||||||
|
Engine = 4
|
||||||
|
}
|
||||||
5
PimpMyRide/PimpMyRide/Exceptions/ValidationException.cs
Normal file
5
PimpMyRide/PimpMyRide/Exceptions/ValidationException.cs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
namespace PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
public class ValidationException(string message) : Exception(message)
|
||||||
|
{
|
||||||
|
}
|
||||||
14
PimpMyRide/PimpMyRide/Extensions/StringExtensions.cs
Normal file
14
PimpMyRide/PimpMyRide/Extensions/StringExtensions.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
namespace PimpMyRide.Extensions;
|
||||||
|
|
||||||
|
public static class StringExtensions
|
||||||
|
{
|
||||||
|
public static bool IsEmpty(this string str)
|
||||||
|
{
|
||||||
|
return string.IsNullOrWhiteSpace(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsGuid(this string str)
|
||||||
|
{
|
||||||
|
return Guid.TryParse(str, out _);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
PimpMyRide/PimpMyRide/Infrastructure/IValidation.cs
Normal file
6
PimpMyRide/PimpMyRide/Infrastructure/IValidation.cs
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
namespace PimpMyRide.Infrastructure;
|
||||||
|
|
||||||
|
public interface IValidation
|
||||||
|
{
|
||||||
|
void Validate();
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]//Указывает, что класс является контейнером для тестовых методов.
|
||||||
|
internal class CarDataModelTests
|
||||||
|
{
|
||||||
|
[Test]//Указывает, что метод — это метода теста.
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(null, Guid.NewGuid().ToString(), "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
car = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel("id", Guid.NewGuid().ToString(), "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ClientIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(Guid.NewGuid().ToString(), null, "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
car = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ClientIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(Guid.NewGuid().ToString(), "id", "Porsche", "911", "A991MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MakeIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, "911", "A911MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, "911", "A911MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ModelIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Porsche", null, "A911MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Porsche", string.Empty, "A911MP");
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void StateNumberIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Porsche", "911", null);
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
car = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Porsche", "911", string.Empty);
|
||||||
|
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var clientId = Guid.NewGuid().ToString();
|
||||||
|
var make = "Porsche";
|
||||||
|
var model = "911";
|
||||||
|
var stateNumber = "A911MP";
|
||||||
|
var car = CreateDataModel(id, clientId, make, model, stateNumber);
|
||||||
|
Assert.That(() => car.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(car.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(car.ClientId, Is.EqualTo(clientId));
|
||||||
|
Assert.That(car.Make, Is.EqualTo(make));
|
||||||
|
Assert.That(car.Model, Is.EqualTo(model));
|
||||||
|
Assert.That(car.StateNumber, Is.EqualTo(stateNumber));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CarDataModel CreateDataModel(string? id, string? clientId, string? make, string? model, string? stateNumber) =>
|
||||||
|
new(id, clientId, make, model, stateNumber);
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ClientDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(null, "fio", "88005553535");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(string.Empty, "fio", "88005553535");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel("id", "fio", "88005553535");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void FIOIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), null, "88005553535");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "88005553535");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void PhoneNumberIsIncorrectTest()
|
||||||
|
{
|
||||||
|
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
|
||||||
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var clientId = Guid.NewGuid().ToString();
|
||||||
|
var fio = "Fio";
|
||||||
|
var phoneNumber = "88005553535";
|
||||||
|
var client = CreateDataModel(clientId, fio, phoneNumber);
|
||||||
|
Assert.That(() => client.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(client.Id, Is.EqualTo(clientId));
|
||||||
|
Assert.That(client.FIO, Is.EqualTo(fio));
|
||||||
|
Assert.That(client.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ClientDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) =>
|
||||||
|
new(id, fio, phoneNumber);
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class MaterialDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(null, MaterialType.Wheels, "Bridgestone tires", 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
material = CreateDataModel(string.Empty, MaterialType.Wheels, "Bridgestone tires", 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel("id", MaterialType.Wheels, "Bridgestone tires", 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MaterialTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(Guid.NewGuid().ToString(), MaterialType.None, "Bridgestone tires", 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void DescriptionIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(Guid.NewGuid().ToString(), MaterialType.Wheels, null, 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
material = CreateDataModel(Guid.NewGuid().ToString(), MaterialType.Wheels, string.Empty, 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void UnitCostIsNegativeTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(Guid.NewGuid().ToString(), MaterialType.Wheels, "Bridgestone tires", -1.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var materialType = MaterialType.Wheels;
|
||||||
|
var description = "Bridgestone tires";
|
||||||
|
var unitCost = 100.0;
|
||||||
|
var material = CreateDataModel(id, materialType, description, unitCost);
|
||||||
|
Assert.That(() => material.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(material.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(material.MaterialType, Is.EqualTo(materialType));
|
||||||
|
Assert.That(material.Description, Is.EqualTo(description));
|
||||||
|
Assert.That(material.UnitCost, Is.EqualTo(unitCost));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MaterialDataModel CreateDataModel(string? id, MaterialType materialType, string? description, double unitCost) =>
|
||||||
|
new(id, materialType, description, unitCost);
|
||||||
|
}
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class MaterialHistoryDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void MaterialIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(null, 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
material = CreateDataModel(string.Empty, 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MaterialIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel("id", 100.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OldPriceIsZeroOrNegative()
|
||||||
|
{
|
||||||
|
var material = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
material = CreateDataModel(Guid.NewGuid().ToString(), -1.0);
|
||||||
|
Assert.That(() => material.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var materialId = Guid.NewGuid().ToString();
|
||||||
|
var oldPrice = 100.0;
|
||||||
|
var material = CreateDataModel(materialId, oldPrice);
|
||||||
|
Assert.That(() => material.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(material.MaterialId, Is.EqualTo(materialId));
|
||||||
|
Assert.That(material.OldPrice, Is.EqualTo(oldPrice));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static MaterialHistoryDataModel CreateDataModel(string? materialId, double oldPrice) =>
|
||||||
|
new(materialId, oldPrice);
|
||||||
|
}
|
||||||
101
PimpMyRide/PimpMyRideTest/DataModelTests/OrderDataModelTests.cs
Normal file
101
PimpMyRide/PimpMyRideTest/DataModelTests/OrderDataModelTests.cs
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class OrderDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(null, Guid.NewGuid().ToString(), 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel("id", Guid.NewGuid().ToString(), 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CarIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), null, 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CarIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), "id", 500.0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TotalCostIsZeroOrNegativeTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
|
||||||
|
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1, false,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ServicesAreEmptyTest()
|
||||||
|
{
|
||||||
|
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 500.0, false, []);
|
||||||
|
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var carId = Guid.NewGuid().ToString();
|
||||||
|
var totalCost = 5000.0;
|
||||||
|
var isCancel = false;
|
||||||
|
var services = new List<OrderServiceDataModel> { new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1) };
|
||||||
|
|
||||||
|
var order = CreateDataModel(id, carId, totalCost, isCancel, services);
|
||||||
|
|
||||||
|
|
||||||
|
Assert.That(() => order.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(order.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(order.CarId, Is.EqualTo(carId));
|
||||||
|
Assert.That(order.TotalCost, Is.EqualTo(totalCost));
|
||||||
|
Assert.That(order.IsCancel, Is.EqualTo(isCancel));
|
||||||
|
Assert.That(order.Services, Is.EquivalentTo(services));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderDataModel CreateDataModel(string? id, string? carId, double totalCost, bool isCancel,
|
||||||
|
List<OrderServiceDataModel> services) => new(id, carId, totalCost, isCancel, services);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class OrderServiceDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void OrderIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var orderService = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
orderService = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void OrderIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var orderService = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ServiceIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var orderService = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
orderService = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ServiceIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var orderService = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsZeroOrNegativeTest()
|
||||||
|
{
|
||||||
|
var orderService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
orderService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var orderId = Guid.NewGuid().ToString();
|
||||||
|
var serviceId = Guid.NewGuid().ToString();
|
||||||
|
var count = 2;
|
||||||
|
var orderService = CreateDataModel(orderId, serviceId, count);
|
||||||
|
Assert.That(() => orderService.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(orderService.OrderId, Is.EqualTo(orderId));
|
||||||
|
Assert.That(orderService.ServiceId, Is.EqualTo(serviceId));
|
||||||
|
Assert.That(orderService.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static OrderServiceDataModel CreateDataModel(string? orderId, string? serviceId, int count) =>
|
||||||
|
new(orderId, serviceId, count);
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ServiceDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel(null, Guid.NewGuid().ToString(), WorkType.Engine, 200.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
service = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), WorkType.Engine, 200.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel("id", Guid.NewGuid().ToString(), WorkType.Engine, 200.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkerIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel(Guid.NewGuid().ToString(), "worker", WorkType.Engine, 200.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void WorkTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), WorkType.None, 200.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CostIsZeroOrNegativeTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), WorkType.Engine, 0.0,
|
||||||
|
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MaterialsAreEmptyTest()
|
||||||
|
{
|
||||||
|
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), WorkType.Engine, 200.0, []);
|
||||||
|
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var workerId = Guid.NewGuid().ToString();
|
||||||
|
var workType = WorkType.Engine;
|
||||||
|
var cost = 200.0;
|
||||||
|
var materials = new List<ServiceMaterialDataModel> {new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)};
|
||||||
|
|
||||||
|
var service = CreateDataModel(id, workerId, workType, cost, materials);
|
||||||
|
|
||||||
|
Assert.That(() => service.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(service.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(service.WorkerId, Is.EqualTo(workerId));
|
||||||
|
Assert.That(service.WorkType, Is.EqualTo(workType));
|
||||||
|
Assert.That(service.CostWithMaterials, Is.EqualTo(cost));
|
||||||
|
Assert.That(service.Materials, Is.EquivalentTo(materials));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ServiceDataModel CreateDataModel(string? id, string? workerId, WorkType workType, double cost,
|
||||||
|
List<ServiceMaterialDataModel> materials) => new(id, workerId, workType, cost, materials);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class ServiceMaterialDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void ServiceIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var serviceMaterial = new ServiceMaterialDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
serviceMaterial = new ServiceMaterialDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ServiceIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var serviceMaterial = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MaterialIdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var serviceMaterial = new ServiceMaterialDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
serviceMaterial = new ServiceMaterialDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void MaterialIdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var serviceMaterial = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CountIsZeroOrNegativeTest()
|
||||||
|
{
|
||||||
|
var serviceMaterial = new ServiceMaterialDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
serviceMaterial = new ServiceMaterialDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var serviceId = Guid.NewGuid().ToString();
|
||||||
|
var materialId = Guid.NewGuid().ToString();
|
||||||
|
var count = 2;
|
||||||
|
|
||||||
|
var serviceMaterial = CreateDataModel(serviceId, materialId, count);
|
||||||
|
|
||||||
|
Assert.That(() => serviceMaterial.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(serviceMaterial.ServiceId, Is.EqualTo(serviceId));
|
||||||
|
Assert.That(serviceMaterial.MaterialId, Is.EqualTo(materialId));
|
||||||
|
Assert.That(serviceMaterial.Count, Is.EqualTo(count));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ServiceMaterialDataModel CreateDataModel(string? serviceId, string? materialId, int count) =>
|
||||||
|
new(serviceId, materialId, count);
|
||||||
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
using PimpMyRide.DataModels;
|
||||||
|
using PimpMyRide.Enums;
|
||||||
|
using PimpMyRide.Exceptions;
|
||||||
|
|
||||||
|
namespace PimpMyRideTest.DataModelTests;
|
||||||
|
|
||||||
|
[TestFixture]
|
||||||
|
internal class WorkerDataModelTests
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void IdIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(null, "John Doe", SpecialityType.Mechanic, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(string.Empty, "John Doe", SpecialityType.Mechanic, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void IdIsNotGuidTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel("id", "John Doe", SpecialityType.Mechanic, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void FioIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, SpecialityType.Mechanic, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, SpecialityType.Mechanic, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void SpecialityTypeIsNoneTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "John Doe", SpecialityType.None, DateTime.Now.AddYears(-20),
|
||||||
|
DateTime.Now.AddYears(-2), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void BirthDateIsUnderageTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "John Doe", SpecialityType.Mechanic, DateTime.Now.AddYears(-17),
|
||||||
|
DateTime.Now.AddYears(-1), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmploymentDateBeforeBirthDateTest()
|
||||||
|
{
|
||||||
|
var worker = CreateDataModel(Guid.NewGuid().ToString(), "John Doe", SpecialityType.Mechanic, DateTime.Now.AddYears(-30),
|
||||||
|
DateTime.Now.AddYears(-31), false);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void AllFieldsAreCorrectTest()
|
||||||
|
{
|
||||||
|
var id = Guid.NewGuid().ToString();
|
||||||
|
var fio = "John Doe";
|
||||||
|
var specialityType = SpecialityType.Mechanic;
|
||||||
|
var birthDate = DateTime.Now.AddYears(-25);
|
||||||
|
var employmentDate = DateTime.Now.AddYears(-5);
|
||||||
|
var isDeleted = false;
|
||||||
|
|
||||||
|
var worker = CreateDataModel(id, fio, specialityType, birthDate, employmentDate, isDeleted);
|
||||||
|
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||||
|
Assert.Multiple(() =>
|
||||||
|
{
|
||||||
|
Assert.That(worker.Id, Is.EqualTo(id));
|
||||||
|
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||||
|
Assert.That(worker.SpecialityType, Is.EqualTo(specialityType));
|
||||||
|
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||||
|
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
|
||||||
|
Assert.That(worker.IsDeleted, Is.EqualTo(isDeleted));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static WorkerDataModel CreateDataModel(string? id, string? fio, SpecialityType specialityType, DateTime birthDate,
|
||||||
|
DateTime employmentDate, bool isDeleted) => new(id, fio, specialityType, birthDate, employmentDate, isDeleted);
|
||||||
|
}
|
||||||
27
PimpMyRide/PimpMyRideTest/PimpMyRideTest.csproj
Normal file
27
PimpMyRide/PimpMyRideTest/PimpMyRideTest.csproj
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
|
<LangVersion>latest</LangVersion>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="coverlet.collector" Version="6.0.2" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
|
||||||
|
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||||
|
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
|
||||||
|
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PimpMyRide\PimpMyRide.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="NUnit.Framework" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user