Compare commits

...

4 Commits

Author SHA1 Message Date
maxim
b6f52294be Сдал 2025-02-17 16:34:59 +04:00
maxim
774921e24b исправил №2 2025-02-17 11:56:23 +04:00
maxim
2656467636 Исправил 2025-02-17 11:44:17 +04:00
maxim
0b21d14ff5 готово 2025-02-17 00:29:50 +04:00
23 changed files with 1071 additions and 1 deletions

View File

@ -1,10 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35527.113 d17.12
VisualStudioVersion = 17.12.35527.113
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketContratcs", "TwoFromTheCasketContratcs\TwoFromTheCasketContratcs.csproj", "{FEB72E65-6B7C-4255-A7E2-5AF08C8E378C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TwoFromTheCasketTest", "TwoFromTheCasketTest\TwoFromTheCasketTest.csproj", "{71E6B2F8-F494-4500-A887-481047D885DF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{FEB72E65-6B7C-4255-A7E2-5AF08C8E378C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FEB72E65-6B7C-4255-A7E2-5AF08C8E378C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FEB72E65-6B7C-4255-A7E2-5AF08C8E378C}.Release|Any CPU.Build.0 = Release|Any CPU
{71E6B2F8-F494-4500-A887-481047D885DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71E6B2F8-F494-4500-A887-481047D885DF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71E6B2F8-F494-4500-A887-481047D885DF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71E6B2F8-F494-4500-A887-481047D885DF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Runtime.InteropServices.JavaScript.JSType;
using System.Xml;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
using TwoFromTheCasketContratcs.Exceptions;
using System.Text.RegularExpressions;
namespace TwoFromTheCasketContratcs.DataModels;
public class MasterDataModel(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 (!Regex.IsMatch(FIO, @"^[А-ЯЁA-Z][а-яёa-z]*(?:-[А-ЯЁA-Z][а-яёa-z]*)?\s[А-ЯЁA-Z][а-яёa-z]*(?:\s[А-ЯЁA-Z][а-яёa-z]*)?$"))
throw new ValidationException("Field FIO is not FIO");
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)
throw new ValidationException($"Minors cannot be hired (EmploymentDate - {EmploymentDate.ToShortDateString()}, BirthDate - {BirthDate.ToShortDateString()})");
}
}

View File

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class OrderDataModel( string id, DateTime dataTime, StatusType status, RoomType roomType, List<ServiceOrderDataModel> serviceOrder ) : IValidation
{
public string Id { get; private set; } = id;
public DateTime Date { get; private set; } = dataTime;
public StatusType Status { get; private set; } = status;
public RoomType RoomType { get; private set; } = roomType;
public List<ServiceOrderDataModel> ServiceOrders { get; private set; } = serviceOrder;
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 (Date == default)
throw new ValidationException("Field Date is empty");
if (Status == StatusType.None)
throw new ValidationException("Field Status is empty");
if (RoomType == RoomType.None)
throw new ValidationException("Field RoomType is empty");
if(ServiceOrders == null)
{
throw new ValidationException("Field ServiceOrders is empty");
}
if (!ServiceOrders.Any())
{
throw new InvalidOperationException("ServiceOrders should not be empty");
}
}
}

View File

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.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");
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class SalaryDataModel(string masterId, DateTime salaryDate, double masterSalary, double prize) : IValidation
{
public string MasterId { get; private set; } = masterId;
public DateTime SalaryDate { get; private set; } = salaryDate;
public double Salary { get; private set; } = masterSalary;
public double Prize { get; private set; } = prize;
public void Validate()
{
if (MasterId.IsEmpty())
throw new ValidationException("Field MasterId is empty");
if (!MasterId.IsGuid())
throw new ValidationException("The value in the field MasterId is not a unique identifier");
if (Salary <= 0)
throw new ValidationException("Field Salary is less than or equal to 0");
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class ServiceDataModel(string id, string serviceName, ServiceType serviceType, string masterID, double price, bool isDeleted) : IValidation
{
public string Id { get; private set; } = id;
public string ServiceName { get; private set; } = serviceName;
public ServiceType ServiceType { get; private set; } = serviceType;
public string MasterId { get; private set; } = masterID;
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 (ServiceName.IsEmpty())
throw new ValidationException("Field ServiceName is empty");
if (ServiceType == ServiceType.None)
throw new ValidationException("Field ServiceType is empty");
if (MasterId.IsEmpty())
throw new ValidationException("Field MasterId is empty");
if (!MasterId.IsGuid())
throw new ValidationException("The value in the field MasterId is not a unique identifier");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
}
}

View File

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class ServiceHistoryDataModel(string serviceId, double oldPrice) :
IValidation
{
public string ServiceId { get; private set; } = serviceId;
public double OldPrice { get; private set; } = oldPrice;
public DateTime ChangeDate { get; private set; } = DateTime.UtcNow;
public void Validate()
{
if (ServiceId.IsEmpty())
throw new ValidationException("Field ServiceId is empty");
if (!ServiceId.IsGuid())
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
if (OldPrice <= 0)
throw new ValidationException("Field OldPrice is less than or equal to 0");
}
}

View File

@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.Exceptions;
using TwoFromTheCasketContratcs.Extensions;
using TwoFromTheCasketContratcs.Infrastructure;
namespace TwoFromTheCasketContratcs.DataModels;
public class ServiceOrderDataModel(string orderId, string serviceId, string masterId, int timeOfWorking) : IValidation
{
public string OrderId { get; private set; } = orderId;
public string ServiceId { get; private set; } = serviceId;
public string MasterId { get; private set; } = masterId;
public int TimeOfWorking { get; private set; }= timeOfWorking;
public void Validate()
{
if (OrderId.IsEmpty())
{
throw new ValidationException("Field OrderId is empty");
}
if (!OrderId.IsGuid())
{
throw new ValidationException("The value in the field OrderId is not a unique identifier");
}
if (ServiceId.IsEmpty())
{
throw new ValidationException("Field ServiceId is empty");
}
if (!ServiceId.IsGuid())
{
throw new ValidationException("The value in the field ServiceId is not a unique identifier");
}
if (MasterId.IsEmpty())
{
throw new ValidationException("Field MasterId is empty");
}
if (!MasterId.IsGuid())
{
throw new ValidationException("The value in the field MasterId is not a unique identifier");
}
if (TimeOfWorking == 0)
{
throw new ValidationException("Field TimeOfWorking is less than or equal to 0");
}
}
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Enums;
public enum PostType
{
None = 0,
Plasterer = 1,
Painter = 2,
Carpenter = 3
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Enums;
public enum RoomType
{
None = 0,
Residential = 1,
Industrial = 2,
Social =3
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Enums;
public enum ServiceType
{
None = 0,
Plastering = 1,
Painting = 2,
Carpentry = 3
}

View File

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Enums;
public enum StatusType
{
None = 0,
NotStarted = 1,
InProcess = 2,
Ready = 3
}

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Exceptions;
public class ValidationException(string message) : Exception(message)
{
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.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 _);
}
}

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TwoFromTheCasketContratcs.Infrastructure;
public interface IValidation
{
void Validate();
}

View File

@ -0,0 +1,102 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
internal class MasterDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var master = CreateDataModel(null, "fio", "11", new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(()=> master.Validate(), Throws.TypeOf<ValidationException>());
master = CreateDataModel(string.Empty, "fio", "11", new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var master = CreateDataModel("id", "fio", "11", new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FIOIsNotFio()
{
var master = CreateDataModel(Guid.NewGuid().ToString(),"1231" , "11", new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
var master = CreateDataModel("11", "fio", null, new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
master = CreateDataModel("11", "fio", string.Empty, new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var master = CreateDataModel("11", "fio", "id", new DateTime(2023, 10, 5), new DateTime(2003, 10, 5), true);
Assert.That(() => master.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateIsNotCorrectTest()
{
var master = CreateDataModel(Guid.NewGuid().ToString(), "fio",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now,
false);
Assert.That(() => master.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void BirthDateAndEmploymentDateIsNotCorrectTest()
{
var master = CreateDataModel(Guid.NewGuid().ToString(), "fio",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-15), DateTime.Now.Date, false);
Assert.That(() => master.Validate(),
Throws.TypeOf<ValidationException>());
master = CreateDataModel(Guid.NewGuid().ToString(), "fio",
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-20), DateTime.Now.AddYears(-21), false);
Assert.That(() => master.Validate(),
Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var id = Guid.NewGuid().ToString();
var fio = "Иван Иваныч Приколов";
var postId = Guid.NewGuid().ToString();
var birthDate = DateTime.Now.AddYears(-20).Date;
var employmentDate = DateTime.Now.Date;
var isDeleted = false;
var master = CreateDataModel(id, fio, postId, birthDate, employmentDate, isDeleted);
Assert.That(() => master.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(master.Id, Is.EqualTo(id));
Assert.That(master.FIO, Is.EqualTo(fio));
Assert.That(master.PostId, Is.EqualTo(postId));
Assert.That(master.BirthDate, Is.EqualTo(birthDate));
Assert.That(master.EmploymentDate, Is.EqualTo(employmentDate));
Assert.That(master.IsDeleted, Is.EqualTo(isDeleted));
});
}
private static MasterDataModel CreateDataModel(string? id, string? fio,string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
new(id, fio, postId, birthDate, employmentDate, isDeleted);
}

View File

@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class OrderDataModelTests
{
List<ServiceOrderDataModel> serviceOrders = new List<ServiceOrderDataModel>
{
new ServiceOrderDataModel("orderId1", "serviceId1", "masterId1", 60),
new ServiceOrderDataModel("orderId2", "serviceId2", "masterId2", 120)
};
[Test]
public void IdIsNullOrEmptyTest()
{
var order = CreateDataModel(string.Empty, DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var order = CreateDataModel("id", DateTime.Now, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DateIsEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), default, StatusType.Ready, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StatusIsNoneTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.None, RoomType.Social, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void RoomTypeIsNoneTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.Ready, RoomType.None, serviceOrders);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ListServiceOrderIsEmptyTest()
{
var order = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, StatusType.Ready, RoomType.Social, null);
Assert.That(() => order.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var date = DateTime.Now;
var status = StatusType.Ready;
var roomType = RoomType.Social;
var order = CreateDataModel(id, date, status, roomType, serviceOrders);
Assert.That(() => order.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(order.Id, Is.EqualTo(id));
Assert.That(order.Date, Is.EqualTo(date));
Assert.That(order.Status, Is.EqualTo(status));
Assert.That(order.RoomType, Is.EqualTo(roomType));
Assert.That(order.ServiceOrders, Is.EqualTo(serviceOrders));
});
}
private static OrderDataModel CreateDataModel(string id, DateTime date, StatusType status, RoomType roomType, List<ServiceOrderDataModel> serviceOrder)
{
return new OrderDataModel(id, date, status, roomType, serviceOrder);
}
}

View File

@ -0,0 +1,98 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class PostDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var post = CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNullOrEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Manager", PostType.Plasterer, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostIdIsNotGuidTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", "Manager", PostType.Plasterer, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostNameIsNullOrEmptyTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, PostType.Plasterer, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PostTypeIsNoneTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Manager", PostType.None, 50000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SalaryIsLessOrEqualToZeroTest()
{
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, 0, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "Manager", PostType.Plasterer, -1000, true, DateTime.Now);
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var postId = Guid.NewGuid().ToString();
var postName = "Manager";
var postType = PostType.Plasterer;
var salary = 50000.0;
var isActual = true;
var changeDate = DateTime.Now;
var post = CreateDataModel(id, postId, postName, postType, salary, isActual, changeDate);
Assert.That(() => post.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(post.Id, Is.EqualTo(id));
Assert.That(post.PostId, Is.EqualTo(postId));
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)
{
return new PostDataModel(id, postId, postName, postType, salary, isActual, changeDate);
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class SalaryDataModellTests
{
[Test]
public void MasterIdIsNullOrEmptyTest()
{
var salary = CreateDataModel(string.Empty, DateTime.Now, 50000, 1000);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MasterIdIsNotGuidTest()
{
var salary = CreateDataModel("invalid-guid", DateTime.Now, 50000, 1000);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SalaryIsLessOrEqualToZeroTest()
{
var salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 0, 1000);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
salary = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -1000, 1000);
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var masterId = Guid.NewGuid().ToString();
var salaryDate = DateTime.Now;
var masterSalary = 50000.0;
var prize = 1000.0;
var salary = CreateDataModel(masterId, salaryDate, masterSalary, prize);
Assert.That(() => salary.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(salary.MasterId, Is.EqualTo(masterId));
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
Assert.That(salary.Salary, Is.EqualTo(masterSalary));
Assert.That(salary.Prize, Is.EqualTo(prize));
});
}
private static SalaryDataModel CreateDataModel(string masterId, DateTime salaryDate, double masterSalary, double prize)
{
return new SalaryDataModel(masterId, salaryDate, masterSalary, prize);
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Enums;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class ServiceDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var service = CreateDataModel(string.Empty, "bb", ServiceType.Plastering, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var service = CreateDataModel("invalid-guid", "bb", ServiceType.Plastering, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceNameIsNullOrEmptyTest()
{
var service = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ServiceType.Plastering, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceTypeIsNoneTest()
{
var service = CreateDataModel(Guid.NewGuid().ToString(), "bb", ServiceType.None, Guid.NewGuid().ToString(), 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MasterIdIsNullOrEmptyTest()
{
var service = CreateDataModel(Guid.NewGuid().ToString(), "bb", ServiceType.Plastering, string.Empty, 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MasterIdIsNotGuidTest()
{
var service = CreateDataModel(Guid.NewGuid().ToString(), "bb", ServiceType.Plastering, "invalid-guid", 100.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrEqualToZeroTest()
{
var service = CreateDataModel(Guid.NewGuid().ToString(), "Haircut", ServiceType.Plastering, Guid.NewGuid().ToString(), 0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
service = CreateDataModel(Guid.NewGuid().ToString(), "Haircut", ServiceType.Plastering, Guid.NewGuid().ToString(), -50.0, false);
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var id = Guid.NewGuid().ToString();
var serviceName = "Haircut";
var serviceType = ServiceType.Plastering;
var masterId = Guid.NewGuid().ToString();
var price = 100.0;
var isDeleted = false;
var service = CreateDataModel(id, serviceName, serviceType, masterId, price, isDeleted);
Assert.That(() => service.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(service.Id, Is.EqualTo(id));
Assert.That(service.ServiceName, Is.EqualTo(serviceName));
Assert.That(service.ServiceType, Is.EqualTo(serviceType));
Assert.That(service.MasterId, Is.EqualTo(masterId));
Assert.That(service.Price, Is.EqualTo(price));
Assert.That(service.IsDeleted, Is.EqualTo(isDeleted));
});
}
private static ServiceDataModel CreateDataModel(string id, string serviceName, ServiceType serviceType, string masterId, double price, bool isDeleted)
{
return new ServiceDataModel(id, serviceName, serviceType, masterId, price, isDeleted);
}
}

View File

@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class ServiceHistoryDataModelTests
{
[Test]
public void ServiceIdIsNullOrEmptyTest()
{
var serviceHistory = CreateDataModel(string.Empty, 100.0);
Assert.That(() => serviceHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNotGuidTest()
{
var serviceHistory = CreateDataModel("invalid-guid", 100.0);
Assert.That(() => serviceHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OldPriceIsLessOrEqualToZeroTest()
{
var serviceHistory = CreateDataModel(Guid.NewGuid().ToString(), 0);
Assert.That(() => serviceHistory.Validate(), Throws.TypeOf<ValidationException>());
serviceHistory = CreateDataModel(Guid.NewGuid().ToString(), -50.0);
Assert.That(() => serviceHistory.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var serviceId = Guid.NewGuid().ToString();
var oldPrice = 100.0;
var serviceHistory = CreateDataModel(serviceId, oldPrice);
Assert.That(() => serviceHistory.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(serviceHistory.ServiceId, Is.EqualTo(serviceId));
Assert.That(serviceHistory.OldPrice, Is.EqualTo(oldPrice));
Assert.That(serviceHistory.ChangeDate, Is.EqualTo(DateTime.UtcNow).Within(TimeSpan.FromSeconds(1)));
});
}
private static ServiceHistoryDataModel CreateDataModel(string serviceId, double oldPrice)
{
return new ServiceHistoryDataModel(serviceId, oldPrice);
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TwoFromTheCasketContratcs.DataModels;
using TwoFromTheCasketContratcs.Exceptions;
namespace TwoFromTheCasketTest.DataModelsTest;
[TestFixture]
public class ServiceOrderDataModelTests
{
[Test]
public void OrderIdIsNullOrEmptyTest()
{
var serviceOrder = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OrderIdIsNotGuidTest()
{
var serviceOrder = CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNullOrEmptyTest()
{
var serviceOrder = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ServiceIdIsNotGuidTest()
{
var serviceOrder = CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", Guid.NewGuid().ToString(), 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MasterIdIsNullOrEmptyTest()
{
var serviceOrder = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void MasterIdIsNotGuidTest()
{
var serviceOrder = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "invalid-guid", 60);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TimeOfWorkingIsZeroTest()
{
var serviceOrder = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => serviceOrder.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var orderId = Guid.NewGuid().ToString();
var serviceId = Guid.NewGuid().ToString();
var masterId = Guid.NewGuid().ToString();
var timeOfWorking = 60;
var serviceOrder = CreateDataModel(orderId, serviceId, masterId, timeOfWorking);
Assert.That(() => serviceOrder.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(serviceOrder.OrderId, Is.EqualTo(orderId));
Assert.That(serviceOrder.ServiceId, Is.EqualTo(serviceId));
Assert.That(serviceOrder.MasterId, Is.EqualTo(masterId));
Assert.That(serviceOrder.TimeOfWorking, Is.EqualTo(timeOfWorking));
});
}
private static ServiceOrderDataModel CreateDataModel(string orderId, string serviceId, string masterId, int timeOfWorking)
{
return new ServiceOrderDataModel(orderId, serviceId, masterId, timeOfWorking);
}
}

View File

@ -0,0 +1,27 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TwoFromTheCasketContratcs\TwoFromTheCasketContratcs.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="NUnit.Framework" />
</ItemGroup>
</Project>