Compare commits
3 Commits
main
...
Task_1_Mod
Author | SHA1 | Date | |
---|---|---|---|
|
094c7f18f6 | ||
|
cc66aa935e | ||
|
a642c1f2b9 |
@ -1,10 +1,12 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.12.35707.178 d17.12
|
||||
VisualStudioVersion = 17.12.35707.178
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WildPlum", "WildPlum\WildPlum.csproj", "{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WildPlumTests", "WildPlumTests\WildPlumTests.csproj", "{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{07BA0D97-C05C-4E48-9661-A5F7FD5EAC46}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1ABD4AED-38DE-4511-ACCF-6B2DCBC4DE86}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
39
WildPlum/WildPlum/DataModels/BuyerDataModel.cs
Normal file
39
WildPlum/WildPlum/DataModels/BuyerDataModel.cs
Normal file
@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class BuyerDataModel(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 a 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, @"^((8|\+7)[\- ]?)?(\(?\d{3}\)?[\-]?)?[\d\- ]{7,10}$"))
|
||||
throw new ValidationException("Field PhoneNumber is not a phone number");
|
||||
}
|
||||
}
|
40
WildPlum/WildPlum/DataModels/JobTitleDataModel.cs
Normal file
40
WildPlum/WildPlum/DataModels/JobTitleDataModel.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using WildPlum.Enums;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class JobTitleDataModel(string id, string postId, string postName, JobTitleType jobTitleType, 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 JobTitleType JobTitleType { get; private set; } = jobTitleType;
|
||||
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 (JobTitleType == JobTitleType.None)
|
||||
throw new ValidationException("Field PostType is empty");
|
||||
if (Salary <= 0)
|
||||
throw new ValidationException("Field Salary is empty");
|
||||
}
|
||||
}
|
41
WildPlum/WildPlum/DataModels/OrderDataModel.cs
Normal file
41
WildPlum/WildPlum/DataModels/OrderDataModel.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class OrderDataModel (string id, string buyerId, string workerId, int price, DateTime dateStart, DateTime dateEnd, List<OrderProductDataModel> products) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string BuyerId { get; private set; } = buyerId;
|
||||
public string WorkerId { get; private set; } = workerId;
|
||||
public int Price { get; private set; } = price;
|
||||
public DateTime DateStart { get; private set; } = dateStart;
|
||||
public DateTime DateEnd { get; private set; } = dateEnd;
|
||||
public List<OrderProductDataModel> Products { get; private set; } = products;
|
||||
|
||||
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 (BuyerId.IsEmpty())
|
||||
throw new ValidationException("Field BuyerId is empty");
|
||||
if (!BuyerId.IsGuid())
|
||||
throw new ValidationException("The value in the field BuyerId is not a 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 a unique identifier");
|
||||
if (DateEnd < DateStart)
|
||||
throw new ValidationException("The end date of the order cannot be less than the start date");
|
||||
if ((Products?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The sale must include products");
|
||||
}
|
||||
}
|
31
WildPlum/WildPlum/DataModels/OrderProductDataModel.cs
Normal file
31
WildPlum/WildPlum/DataModels/OrderProductDataModel.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class OrderProductDataModel (string orderId, string productId, int count) : IValidation
|
||||
{
|
||||
public string OrderId { get; private set; } = orderId;
|
||||
public string ProductId { get; private set; } = productId;
|
||||
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 (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.IsGuid())
|
||||
throw new ValidationException("The value in the field Id is not a unique identifier");
|
||||
if (Count <= 0)
|
||||
throw new ValidationException("Field Count is less than or equal to 0");
|
||||
}
|
||||
}
|
34
WildPlum/WildPlum/DataModels/ProductDataModel.cs
Normal file
34
WildPlum/WildPlum/DataModels/ProductDataModel.cs
Normal file
@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using WildPlum.Enums;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class ProductDataModel (string id, string productName, ProductType productType, double price, bool isDeleted) : IValidation
|
||||
{
|
||||
public string Id { get; private set; } = id;
|
||||
public string ProductName { get; private set; } = productName;
|
||||
public ProductType ProductType { get; private set; } = productType;
|
||||
public double Price { get; private set; } = price;
|
||||
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 (ProductName.IsEmpty())
|
||||
throw new ValidationException("Field ProductName is empty");
|
||||
if (ProductType == ProductType.None)
|
||||
throw new ValidationException("Field ProductType is empty");
|
||||
if (Price <= 0)
|
||||
throw new ValidationException("Field Price is less than or equal to 0");
|
||||
}
|
||||
}
|
26
WildPlum/WildPlum/DataModels/ProductHistoryDataModel.cs
Normal file
26
WildPlum/WildPlum/DataModels/ProductHistoryDataModel.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.DataModels;
|
||||
|
||||
public class ProductHistoryDataModel(string productId, double oldPrice) : IValidation
|
||||
{
|
||||
public string ProductId { get; private set; } = productId;
|
||||
public double OldPrice { get; private set; } = oldPrice;
|
||||
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
|
||||
public void Validate()
|
||||
{
|
||||
if (ProductId.IsEmpty())
|
||||
throw new ValidationException("Field ProductId is empty");
|
||||
if (!ProductId.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");
|
||||
}
|
||||
}
|
26
WildPlum/WildPlum/DataModels/SalaryDataModel.cs
Normal file
26
WildPlum/WildPlum/DataModels/SalaryDataModel.cs
Normal file
@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
|
||||
namespace WildPlum.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");
|
||||
}
|
||||
}
|
42
WildPlum/WildPlum/DataModels/WorkerDataModel.cs
Normal file
42
WildPlum/WildPlum/DataModels/WorkerDataModel.cs
Normal file
@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml;
|
||||
using WildPlum.Extensions;
|
||||
using WildPlum.Infrastructure;
|
||||
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||
|
||||
namespace WildPlum.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()})");
|
||||
}
|
||||
}
|
15
WildPlum/WildPlum/Enums/JobTitleType.cs
Normal file
15
WildPlum/WildPlum/Enums/JobTitleType.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WildPlum.Enums;
|
||||
|
||||
public enum JobTitleType
|
||||
{
|
||||
None = 0,
|
||||
Operator = 1,
|
||||
Delivaryman = 2,
|
||||
Loader = 3
|
||||
}
|
16
WildPlum/WildPlum/Enums/ProductType.cs
Normal file
16
WildPlum/WildPlum/Enums/ProductType.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WildPlum.Enums;
|
||||
|
||||
public enum ProductType
|
||||
{
|
||||
None = 0,
|
||||
Cloth = 1,
|
||||
Shoes = 2,
|
||||
Toy = 3,
|
||||
Office = 4
|
||||
}
|
11
WildPlum/WildPlum/Exceptions/ValidationException.cs
Normal file
11
WildPlum/WildPlum/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 WildPlum.Exceptions;
|
||||
|
||||
public class ValidationException(string message) : Exception(message)
|
||||
{
|
||||
}
|
19
WildPlum/WildPlum/Extensions/StringExtensions.cs
Normal file
19
WildPlum/WildPlum/Extensions/StringExtensions.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace WildPlum.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 _);
|
||||
}
|
||||
}
|
12
WildPlum/WildPlum/Infrastructure/IValidation.cs
Normal file
12
WildPlum/WildPlum/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 WildPlum.Infrastructure;
|
||||
|
||||
public interface IValidation
|
||||
{
|
||||
void Validate();
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class BuyerDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(null, "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(string.Empty, "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var buyer = CreateDataModel("id", "fio", "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), null, "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PhoneNumberIsIncorrectTest()
|
||||
{
|
||||
var buyer = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777");
|
||||
Assert.That(() => buyer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var fio = "Fio";
|
||||
var phoneNumber = "+7-777-777-77-77";
|
||||
var buyer = CreateDataModel(buyerId, fio, phoneNumber);
|
||||
Assert.That(() => buyer.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(buyer.Id, Is.EqualTo(buyerId));
|
||||
Assert.That(buyer.FIO, Is.EqualTo(fio));
|
||||
Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber));
|
||||
});
|
||||
}
|
||||
private static BuyerDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) => new(id, fio, phoneNumber);
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
using WildPlum.Enums;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class JobTitleDateModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "name", JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "name", JobTitleType.Delivaryman, 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, JobTitleType.Delivaryman, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, JobTitleType.Delivaryman, 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", JobTitleType.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", JobTitleType.Delivaryman, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "name", JobTitleType.Delivaryman, -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 = JobTitleType.Delivaryman;
|
||||
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.JobTitleType, 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 JobTitleDataModel CreateDataModel(string? id, string? postId, string? postName, JobTitleType jobTitleType, double salary, bool isActual, DateTime
|
||||
changeDate) => new(id, postId, postName, jobTitleType, salary, isActual, changeDate);
|
||||
|
||||
}
|
107
WildPlum/WildPlumTests/DataModelsTests/OrderDataModelTests.cs
Normal file
107
WildPlum/WildPlumTests/DataModelsTests/OrderDataModelTests.cs
Normal file
@ -0,0 +1,107 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
using WildPlum.Enums;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class OrderDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("1", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuyerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BuyerIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "1", Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(),Guid.NewGuid().ToString(), "1", 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(1), CreateSubDataModel());
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void StartDateAndEndDateIsNotCorrect()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow.AddDays(2), DateTime.UtcNow, CreateSubDataModel());
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(2), null);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 100, DateTime.UtcNow, DateTime.UtcNow.AddDays(2), []);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var id = Guid.NewGuid().ToString();
|
||||
var buyerId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var price = 10;
|
||||
var dateStart = DateTime.UtcNow;
|
||||
var dateEnd = DateTime.UtcNow.AddDays(2);
|
||||
var products = CreateSubDataModel();
|
||||
var order = CreateDataModel(id, buyerId, workerId, price, dateStart, dateEnd, products);
|
||||
Assert.That(() => order.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(order.Id, Is.EqualTo(id));
|
||||
Assert.That(order.BuyerId, Is.EqualTo(buyerId));
|
||||
Assert.That(order.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(order.Price, Is.EqualTo(price));
|
||||
Assert.That(order.DateStart, Is.EqualTo(dateStart));
|
||||
Assert.That(order.DateEnd, Is.EqualTo(dateEnd));
|
||||
Assert.That(order.Products, Is.EqualTo(products));
|
||||
});
|
||||
}
|
||||
|
||||
private static OrderDataModel CreateDataModel(string? id, string? buyerId, string? workerId, int price,
|
||||
DateTime dateStart, DateTime dateEnd, List<OrderProductDataModel> products) => new(id, buyerId, workerId, price, dateStart, dateEnd, products);
|
||||
|
||||
private static List<OrderProductDataModel> CreateSubDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OrderProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void OrderIdIsNullOrEmptyTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
order = CreateDataModel( Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OrderIdIsNotGuidTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountNotCorrectTest()
|
||||
{
|
||||
var order = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var orderId = Guid.NewGuid().ToString();
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var orderProduct = CreateDataModel(orderId, productId, count);
|
||||
Assert.That(() => orderProduct.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(orderProduct.OrderId, Is.EqualTo(orderId));
|
||||
Assert.That(orderProduct.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(orderProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static OrderProductDataModel CreateDataModel(string? orderId, string? productId, int count) =>
|
||||
new(orderId, productId, count);
|
||||
}
|
@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
using WildPlum.Enums;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ProductDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, "name", ProductType.Cloth, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, "name", ProductType.Cloth, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", "name", ProductType.Cloth, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.Cloth, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ProductType.Cloth, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductTypeIsNoneTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), null, ProductType.None, 10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cloth, 0, false);
|
||||
Assert.That(() => product.Validate(),
|
||||
Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), "name", ProductType.Cloth, -10, false);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var productName = "name";
|
||||
var productType = ProductType.Cloth;
|
||||
var productPrice = 10;
|
||||
var productIsDelete = false;
|
||||
var product = CreateDataModel(productId, productName, productType, productPrice, productIsDelete);
|
||||
Assert.That(() => product.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(product.Id, Is.EqualTo(productId));
|
||||
Assert.That(product.ProductName, Is.EqualTo(productName));
|
||||
Assert.That(product.ProductType, Is.EqualTo(productType));
|
||||
Assert.That(product.Price, Is.EqualTo(productPrice));
|
||||
Assert.That(product.IsDeleted, Is.EqualTo(productIsDelete));
|
||||
});
|
||||
}
|
||||
private static ProductDataModel CreateDataModel(string? id, string? productName, ProductType productType,
|
||||
double price, bool isDeleted) => new(id, productName, productType, price, isDeleted);
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public class ProductHistoryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void ProductIdIsNullOrEmptyTest()
|
||||
{
|
||||
var product = CreateDataModel(null, 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(string.Empty, 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductIdIsNotGuidTest()
|
||||
{
|
||||
var product = CreateDataModel("id", 10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OldPriceIsLessOrZeroTest()
|
||||
{
|
||||
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var productId = Guid.NewGuid().ToString();
|
||||
var oldPrice = 10;
|
||||
var productHistory = CreateDataModel(productId, oldPrice);
|
||||
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(productHistory.ProductId, Is.EqualTo(productId));
|
||||
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
||||
Assert.That(productHistory.ChangeDate,
|
||||
Is.LessThan(DateTime.UtcNow));
|
||||
Assert.That(productHistory.ChangeDate,
|
||||
Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
||||
});
|
||||
}
|
||||
private static ProductHistoryDataModel CreateDataModel(string? productId, double oldPrice) =>
|
||||
new(productId, oldPrice);
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
public 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);
|
||||
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using WildPlum.DataModels;
|
||||
|
||||
namespace WildPlumTests.DataModelsTests;
|
||||
|
||||
public 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);
|
||||
|
||||
|
||||
}
|
27
WildPlum/WildPlumTests/WildPlumTests.csproj
Normal file
27
WildPlum/WildPlumTests/WildPlumTests.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="..\WildPlum\WildPlum.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user