Pibd-21 Nekrasov A.A. Первая лабораторная работа #1
31
TheWingsOfTheWorldProject.sln
Normal file
31
TheWingsOfTheWorldProject.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.13.35806.99
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldContratcs", "WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj", "{BEAC542F-7E06-4942-A37D-583E87FAE7FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WingsOfTheWorldTests", "WingsOfTheWorldTests\WingsOfTheWorldTests.csproj", "{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BEAC542F-7E06-4942-A37D-583E87FAE7FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{B6D3F94F-D240-494C-AC11-D9B8ADAD4914}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {FDD9A46D-B6D6-40D9-AE18-3DF8480C20EB}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
36
WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs
Normal file
36
WingsOfTheWorldContratcs/DataModels/AccessoriesDataModel.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Enums;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class AccessoriesDataModel(string id, string name, AccessoriesType accessoriesType) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
public AccessoriesType AccessoriesType { get; private set; } = accessoriesType;
|
||||
|
||||
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 (Name.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
||||
if (AccessoriesType == AccessoriesType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
}
|
||||
}
|
35
WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs
Normal file
35
WingsOfTheWorldContratcs/DataModels/AirplaneDataModel.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class AirplaneDataModel(string id, string model) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string Model { get; private set; } = model;
|
||||
|
||||
|
||||
|
||||
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 (Model.IsEmpty())
|
||||
throw new ValidationException("Field Model is empty");
|
||||
|
||||
if (!Model.IsGuid())
|
||||
throw new ValidationException("The value in the field Model is not a unique identifier");
|
||||
|
||||
}
|
||||
}
|
53
WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs
Normal file
53
WingsOfTheWorldContratcs/DataModels/DeliveryDataModel.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class DeliveryDataModel(string id, string airPlaneId, string place, int count, int price) : IValidation
|
||||
{
|
||||
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string AirPlaneId { get; private set; } = airPlaneId;
|
||||
|
||||
public string Place { get; private set; } = place;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public int Price { get; private set; } = price;
|
||||
|
||||
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 (AirPlaneId.IsEmpty())
|
||||
throw new ValidationException("Field AirPlaneId is empty");
|
||||
|
||||
if (!AirPlaneId.IsGuid())
|
||||
throw new ValidationException("The value in the field AirPlaneId is not a unique identifier");
|
||||
|
||||
if (Place.IsEmpty())
|
||||
throw new ValidationException("Field Place is empty");
|
||||
|
||||
if (!Place.IsGuid())
|
||||
throw new ValidationException("The value in the field Place is not a unique identifier");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is empty");
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class DeliveryHistoryDataModel(string airplaneid, double oldPrice) : IValidation
|
||||
{
|
||||
public string AirplaneId { get; private set; } = airplaneid;
|
||||
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (AirplaneId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
|
||||
if (!AirplaneId.IsGuid())
|
||||
throw new ValidationException("The value in the field ProductId is not a unique identifier");
|
||||
|
||||
if (OldPrice <= 0)
|
||||
throw new ValidationException("Field OldPrice is less than or equal to 0");
|
||||
}
|
||||
}
|
53
WingsOfTheWorldContratcs/DataModels/PostDataModel.cs
Normal file
53
WingsOfTheWorldContratcs/DataModels/PostDataModel.cs
Normal file
@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Enums;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class PostDataModel(string id, string postId, string postName, PostType postType, double salary, bool isActual, DateTime changeDate) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
public string PostName { get; private set; } = postName;
|
||||
|
||||
public PostType PostType { get; private set; } = postType;
|
||||
|
||||
public double Salary { get; private set; } = salary;
|
||||
|
||||
public bool IsActual { get; private set; } = isActual;
|
||||
|
||||
public DateTime ChangeDate { get; private set; } = changeDate;
|
||||
|
||||
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 (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (PostName.IsEmpty())
|
||||
throw new ValidationException("Field PostName is empty");
|
||||
|
||||
if (PostType == PostType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
||||
|
31
WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs
Normal file
31
WingsOfTheWorldContratcs/DataModels/SalaryDataModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class SalaryDataModel(string workerId, DateTime salaryDate, double workerSalary) : IValidation
|
||||
{
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
|
||||
public DateTime SalaryDate { get; private set; } = salaryDate;
|
||||
|
||||
public double Salary { get; private set; } = workerSalary;
|
||||
|
||||
public void Validate()
|
||||
{
|
||||
if (WorkerId.IsEmpty())
|
||||
throw new ValidationException("Field WorkerId is empty");
|
||||
|
||||
if (!WorkerId.IsGuid())
|
||||
throw new ValidationException("The value in the field WorkerId is not a unique identifier");
|
||||
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is less than or equal to 0");
|
||||
}
|
||||
}
|
52
WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs
Normal file
52
WingsOfTheWorldContratcs/DataModels/WorkerDataModel.cs
Normal file
@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class WorkerDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string FIO { get; private set; } = fio;
|
||||
|
||||
public string PostId { get; private set; } = postId;
|
||||
|
||||
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 a unique identifier");
|
||||
|
||||
if (FIO.IsEmpty())
|
||||
throw new ValidationException("Field FIO is empty");
|
||||
|
||||
if (PostId.IsEmpty())
|
||||
throw new ValidationException("Field PostId is empty");
|
||||
|
||||
if (!PostId.IsGuid())
|
||||
throw new ValidationException("The value in the field PostId is not a unique identifier");
|
||||
|
||||
if (BirthDate.Date > DateTime.Now.AddYears(-16).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) // EmploymentDate.Year - BirthDate.Year
|
||||
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using WingsOfTheWorldContratcs.Exstensions;
|
||||
using WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.DataModels;
|
||||
|
||||
public class СarrierСompanyDataModel(string id, string name, string phoneNumber, int count, int price) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
|
||||
public string Name { get; private set; } = name;
|
||||
|
||||
public string PhoneNumber { get; private set; } = phoneNumber;
|
||||
|
||||
public int Count { get; private set; } = count;
|
||||
|
||||
public int Price { get; private set; } = price;
|
||||
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 (Name.IsEmpty())
|
||||
throw new ValidationException("Field Name is empty");
|
||||
|
||||
if (PhoneNumber.IsEmpty())
|
||||
throw new ValidationException("Field PhoneNumber is empty");
|
||||
|
||||
if (!Regex.IsMatch(PhoneNumber, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\- ]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is empty");
|
||||
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is empty");
|
||||
}
|
||||
}
|
15
WingsOfTheWorldContratcs/Enums/AccessoriesType.cs
Normal file
15
WingsOfTheWorldContratcs/Enums/AccessoriesType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.Enums;
|
||||
|
||||
public enum AccessoriesType
|
||||
{
|
||||
None = 0,
|
||||
Accessories = 1,
|
||||
Salon = 2,
|
||||
BodyWork = 3
|
||||
}
|
15
WingsOfTheWorldContratcs/Enums/PostType.cs
Normal file
15
WingsOfTheWorldContratcs/Enums/PostType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.Enums;
|
||||
|
||||
public enum PostType
|
||||
{
|
||||
None = 0,
|
||||
Supervisor = 1,
|
||||
Master = 2,
|
||||
Assistent = 3
|
||||
}
|
11
WingsOfTheWorldContratcs/Exceptions/ValidationException.cs
Normal file
11
WingsOfTheWorldContratcs/Exceptions/ValidationException.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
20
WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs
Normal file
20
WingsOfTheWorldContratcs/Exstensions/StringExstensions.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.Exstensions;
|
||||
|
||||
public static class StringExstensions
|
||||
{
|
||||
public static bool IsEmpty(this string str)
|
||||
{
|
||||
return string.IsNullOrWhiteSpace(str);
|
||||
}
|
||||
|
||||
public static bool IsGuid(this string str)
|
||||
{
|
||||
return Guid.TryParse(str, out _);
|
||||
}
|
||||
}
|
12
WingsOfTheWorldContratcs/Infrastructure/IValidation.cs
Normal file
12
WingsOfTheWorldContratcs/Infrastructure/IValidation.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WingsOfTheWorldContratcs.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
9
WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj
Normal file
9
WingsOfTheWorldContratcs/WingsOfTheWorldContratcs.csproj
Normal file
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Enums;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class AccessoriesDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var accessory = CreateDataModel(null, "AccessoryName", AccessoriesType.Salon);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
accessory = CreateDataModel(string.Empty, "AccessoryName", AccessoriesType.Salon);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var accessory = CreateDataModel("invalid_id", "AccessoryName", AccessoriesType.Salon);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrEmptyTest()
|
||||
{
|
||||
var accessory = CreateDataModel(Guid.NewGuid().ToString(), null, AccessoriesType.Salon);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
accessory = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, AccessoriesType.Salon);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AccessoriesTypeIsNoneTest()
|
||||
{
|
||||
var accessory = CreateDataModel(Guid.NewGuid().ToString(), "AccessoryName", AccessoriesType.None);
|
||||
Assert.That(() => accessory.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "AccessoryName";
|
||||
var type = AccessoriesType.Salon;
|
||||
var accessory = CreateDataModel(id, name, type);
|
||||
|
||||
Assert.That(() => accessory.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(accessory.Id, Is.EqualTo(id));
|
||||
Assert.That(accessory.Name, Is.EqualTo(name));
|
||||
Assert.That(accessory.AccessoriesType, Is.EqualTo(type));
|
||||
});
|
||||
}
|
||||
|
||||
private static AccessoriesDataModel CreateDataModel(string? id, string? name, AccessoriesType type) =>
|
||||
new(id, name, type);
|
||||
}
|
65
WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs
Normal file
65
WingsOfTheWorldTests/DataModelTests/AirplaneDataModelTest.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class AirplaneDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var airplane = CreateDataModel(null, "model");
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
airplane = CreateDataModel(string.Empty, "model");
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var airplane = CreateDataModel("invalid_id", "model");
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModelIsNullOrEmptyTest()
|
||||
{
|
||||
var airplane = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
airplane = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ModelIsNotGuidTest()
|
||||
{
|
||||
var airplane = CreateDataModel(Guid.NewGuid().ToString(), "invalid_model");
|
||||
Assert.That(() => airplane.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var model = Guid.NewGuid().ToString();
|
||||
var airplane = CreateDataModel(id, model);
|
||||
|
||||
Assert.That(() => airplane.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(airplane.Id, Is.EqualTo(id));
|
||||
Assert.That(airplane.Model, Is.EqualTo(model));
|
||||
});
|
||||
}
|
||||
|
||||
private static AirplaneDataModel CreateDataModel(string? id, string? model) =>
|
||||
new(id, model);
|
||||
}
|
109
WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs
Normal file
109
WingsOfTheWorldTests/DataModelTests/DeliveryDataModelTest.cs
Normal file
@ -0,0 +1,109 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
using static NUnit.Framework.Internal.OSPlatform;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class DeliveryDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var delivery = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
delivery = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var delivery = CreateDataModel("invalid_id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AirPlaneIdIsNullOrEmptyTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
delivery = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AirPlaneIdIsNotGuidTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), "invalid_id", Guid.NewGuid().ToString(), 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PlaceIsNullOrEmptyTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PlaceIsNotGuidTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid_place", 10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10, 100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 0);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
delivery = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, -100);
|
||||
Assert.That(() => delivery.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var airPlaneId = Guid.NewGuid().ToString();
|
||||
var place = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var price = 100;
|
||||
var delivery = CreateDataModel(id, airPlaneId, place, count, price);
|
||||
|
||||
Assert.That(() => delivery.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(delivery.Id, Is.EqualTo(id));
|
||||
Assert.That(delivery.AirPlaneId, Is.EqualTo(airPlaneId));
|
||||
Assert.That(delivery.Place, Is.EqualTo(place));
|
||||
Assert.That(delivery.Count, Is.EqualTo(count));
|
||||
Assert.That(delivery.Price, Is.EqualTo(price));
|
||||
});
|
||||
}
|
||||
|
||||
private static DeliveryDataModel CreateDataModel(string? id, string? airPlaneId, string? place, int count, int price) =>
|
||||
new(id, airPlaneId, place, count, price);
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class DeliveryHistoryDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void AirplaneIdIsNullOrEmptyTest()
|
||||
{
|
||||
var history = CreateDataModel(null, 100);
|
||||
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
history = CreateDataModel(string.Empty, 100);
|
||||
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AirplaneIdIsNotGuidTest()
|
||||
{
|
||||
var history = CreateDataModel("invalid_id", 100);
|
||||
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrEqualZeroTest()
|
||||
{
|
||||
var history = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
history = CreateDataModel(Guid.NewGuid().ToString(), -100);
|
||||
Assert.That(() => history.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var airplaneId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 150.5;
|
||||
var history = CreateDataModel(airplaneId, oldPrice);
|
||||
|
||||
Assert.That(() => history.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(history.AirplaneId, Is.EqualTo(airplaneId));
|
||||
Assert.That(history.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(history.ChangeDate, Is.LessThanOrEqualTo(DateTime.UtcNow));
|
||||
});
|
||||
}
|
||||
|
||||
private static DeliveryHistoryDataModel CreateDataModel(string? airplaneId, double oldPrice) =>
|
||||
new(airplaneId, oldPrice);
|
||||
}
|
97
WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs
Normal file
97
WingsOfTheWorldTests/DataModelTests/PostDataModelTest.cs
Normal file
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Enums;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class PostDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Assistent, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.None, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType.Assistent, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", PostType. Assistent, -10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Assistent;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate);
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
Assert.That(post.PostId, Is.EqualTo(postPostId));
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new(id, postId, postName, postType, salary, isActual, changeDate);
|
||||
}
|
56
WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs
Normal file
56
WingsOfTheWorldTests/DataModelTests/SalaryDataModelTests.cs
Normal file
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
internal class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WorkerIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("workerId", DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var workerSalary = 10;
|
||||
var salary = CreateDataModel(workerId, salaryDate, workerSalary);
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(workerSalary));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? workerId, DateTime salaryDate, double workerSalary) =>
|
||||
new(workerId, salaryDate, workerSalary);
|
||||
}
|
90
WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs
Normal file
90
WingsOfTheWorldTests/DataModelTests/WorkerDataModelTest.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel("id", "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDelete = false;
|
||||
var worker = CreateDataModel(workerId, fio, postId, birthDate, employmentDate, isDelete);
|
||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(worker.Id, Is.EqualTo(workerId));
|
||||
Assert.That(worker.FIO, Is.EqualTo(fio));
|
||||
Assert.That(worker.PostId, Is.EqualTo(postId));
|
||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(worker.EmploymentDate, Is.EqualTo(employmentDate));
|
||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static WorkerDataModel CreateDataModel(string? id, string? fio, string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
||||
}
|
@ -0,0 +1,106 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WingsOfTheWorldContratcs.DataModels;
|
||||
using WingsOfTheWorldContratcs.Exceptions;
|
||||
|
||||
namespace WingsOfTheWorldTests.DataModelTests;
|
||||
|
||||
|
||||
|
||||
internal class CarrierCompanyDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var company = CreateDataModel(null, "CompanyName", "+79123456789", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(string.Empty, "CompanyName", "+79123456789", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var company = CreateDataModel("invalid_id", "CompanyName", "+79123456789", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void NameIsNullOrEmptyTest()
|
||||
{
|
||||
var company = CreateDataModel(Guid.NewGuid().ToString(), null, "+79123456789", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+79123456789", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", null, 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", string.Empty, 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsInvalidTest()
|
||||
{
|
||||
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "123456", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "abcdefg", 10, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrEqualZeroTest()
|
||||
{
|
||||
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 0, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", -5, 1000);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrEqualZeroTest()
|
||||
{
|
||||
var company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, 0);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
company = CreateDataModel(Guid.NewGuid().ToString(), "CompanyName", "+79123456789", 10, -100);
|
||||
Assert.That(() => company.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsAreCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var name = "CompanyName";
|
||||
var phoneNumber = "+79123456789";
|
||||
var count = 10;
|
||||
var price = 1000;
|
||||
var company = CreateDataModel(id, name, phoneNumber, count, price);
|
||||
|
||||
Assert.That(() => company.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(company.Id, Is.EqualTo(id));
|
||||
Assert.That(company.Name, Is.EqualTo(name));
|
||||
Assert.That(company.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||
Assert.That(company.Count, Is.EqualTo(count));
|
||||
Assert.That(company.Price, Is.EqualTo(price));
|
||||
});
|
||||
}
|
||||
|
||||
private static СarrierСompanyDataModel CreateDataModel(string? id, string? name, string? phoneNumber, int count, int price) =>
|
||||
new(id, name, phoneNumber, count, price);
|
||||
}
|
27
WingsOfTheWorldTests/WingsOfTheWorldTests.csproj
Normal file
27
WingsOfTheWorldTests/WingsOfTheWorldTests.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.12.0" />
|
||||
<PackageReference Include="NUnit" Version="4.2.2" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.4.0" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\WingsOfTheWorldContratcs\WingsOfTheWorldContratcs.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user