delete client model
This commit is contained in:
parent
8d3154953b
commit
4141cca5d8
@ -1,33 +0,0 @@
|
|||||||
using System.Text.RegularExpressions;
|
|
||||||
using TheCyclopsContracts.Exceptions;
|
|
||||||
using TheCyclopsContracts.Extensions;
|
|
||||||
using TheCyclopsContracts.Infrastructure;
|
|
||||||
|
|
||||||
namespace TheCyclopsContracts.DataModels;
|
|
||||||
|
|
||||||
public class ClientDataModel(string id, string fio, string email) : IValidation
|
|
||||||
{
|
|
||||||
public string Id { get; private set; } = id;
|
|
||||||
|
|
||||||
public string FIO { get; private set; } = fio;
|
|
||||||
|
|
||||||
public string Email { get; private set; } = email;
|
|
||||||
|
|
||||||
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 (Email.IsEmpty())
|
|
||||||
throw new ValidationException("Field Email is empty");
|
|
||||||
|
|
||||||
if (!Regex.IsMatch(Email, @"^\S+@\S+\.\S+$"))
|
|
||||||
throw new ValidationException("Field Email is not an email address");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,15 +1,19 @@
|
|||||||
using TheCyclopsContracts.Exceptions;
|
using System.Text.RegularExpressions;
|
||||||
|
using TheCyclopsContracts.Exceptions;
|
||||||
using TheCyclopsContracts.Extensions;
|
using TheCyclopsContracts.Extensions;
|
||||||
using TheCyclopsContracts.Infrastructure;
|
using TheCyclopsContracts.Infrastructure;
|
||||||
|
|
||||||
namespace TheCyclopsContracts.DataModels;
|
namespace TheCyclopsContracts.DataModels;
|
||||||
|
|
||||||
public class EmployeeDataModel(string id, string fio, string postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
public class EmployeeDataModel(string id, string fio, string email, string postId,
|
||||||
|
DateTime birthDate, DateTime employmentDate, bool isDeleted) : IValidation
|
||||||
{
|
{
|
||||||
public string Id { get; private set; } = id;
|
public string Id { get; private set; } = id;
|
||||||
|
|
||||||
public string FIO { get; private set; } = fio;
|
public string FIO { get; private set; } = fio;
|
||||||
|
|
||||||
|
public string Email { get; private set; } = email;
|
||||||
|
|
||||||
public string PostId { get; private set; } = postId;
|
public string PostId { get; private set; } = postId;
|
||||||
|
|
||||||
public DateTime BirthDate { get; private set; } = birthDate;
|
public DateTime BirthDate { get; private set; } = birthDate;
|
||||||
@ -29,6 +33,12 @@ public class EmployeeDataModel(string id, string fio, string postId, DateTime bi
|
|||||||
if (FIO.IsEmpty())
|
if (FIO.IsEmpty())
|
||||||
throw new ValidationException("Field FIO is empty");
|
throw new ValidationException("Field FIO is empty");
|
||||||
|
|
||||||
|
if (Email.IsEmpty())
|
||||||
|
throw new ValidationException("Field Email is empty");
|
||||||
|
|
||||||
|
if (!Regex.IsMatch(Email, @"^\S+@\S+\.\S+$"))
|
||||||
|
throw new ValidationException("Field Email is not an email address");
|
||||||
|
|
||||||
if (PostId.IsEmpty())
|
if (PostId.IsEmpty())
|
||||||
throw new ValidationException("Field PostId is empty");
|
throw new ValidationException("Field PostId is empty");
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ using TheCyclopsContracts.Infrastructure;
|
|||||||
|
|
||||||
namespace TheCyclopsContracts.DataModels;
|
namespace TheCyclopsContracts.DataModels;
|
||||||
|
|
||||||
public class InstallationDataModel(string id, string employeeId, string? clientId,
|
public class InstallationDataModel(string id, string employeeId,
|
||||||
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
|
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
|
||||||
List<InstallationComponentDataModel> components) : IValidation
|
List<InstallationComponentDataModel> components) : IValidation
|
||||||
{
|
{
|
||||||
@ -12,8 +12,6 @@ public class InstallationDataModel(string id, string employeeId, string? clientI
|
|||||||
|
|
||||||
public string EmployeeId { get; private set; } = employeeId;
|
public string EmployeeId { get; private set; } = employeeId;
|
||||||
|
|
||||||
public string? ClientId { get; private set; } = clientId;
|
|
||||||
|
|
||||||
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
public DateTime SaleDate { get; private set; } = DateTime.UtcNow;
|
||||||
|
|
||||||
public DateTime InstallationDate { get; private set; } = installationDate;
|
public DateTime InstallationDate { get; private set; } = installationDate;
|
||||||
@ -40,9 +38,6 @@ public class InstallationDataModel(string id, string employeeId, string? clientI
|
|||||||
if (!EmployeeId.IsGuid())
|
if (!EmployeeId.IsGuid())
|
||||||
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
throw new ValidationException("The value in the field EmployeeId is not a unique identifier");
|
||||||
|
|
||||||
if (!ClientId?.IsGuid() ?? !ClientId?.IsEmpty() ?? false)
|
|
||||||
throw new ValidationException("The value in the field ClientId is not a unique identifier");
|
|
||||||
|
|
||||||
if (InstallationPrice <= 0)
|
if (InstallationPrice <= 0)
|
||||||
throw new ValidationException("Field InstallationPrice is less than or equal to 0");
|
throw new ValidationException("Field InstallationPrice is less than or equal to 0");
|
||||||
|
|
||||||
|
@ -1,73 +0,0 @@
|
|||||||
using TheCyclopsContracts.DataModels;
|
|
||||||
using TheCyclopsContracts.Exceptions;
|
|
||||||
|
|
||||||
namespace TheCyclopsTests.DataModelsTests;
|
|
||||||
|
|
||||||
[TestFixture]
|
|
||||||
internal class ClientDataModelTests
|
|
||||||
{
|
|
||||||
[Test]
|
|
||||||
public void IdIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var client = CreateDataModel(null, "fio", "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
|
|
||||||
client = CreateDataModel(string.Empty, "fio", "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void IdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var client = CreateDataModel("id", "fio", "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void FIOIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var client = CreateDataModel(Guid.NewGuid().ToString(), null, "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
|
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void EmailIsNullOrEmptyTest()
|
|
||||||
{
|
|
||||||
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null);
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
|
|
||||||
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty);
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void EmailIsIncorrectTest()
|
|
||||||
{
|
|
||||||
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "email");
|
|
||||||
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void AllFieldsIsCorrectTest()
|
|
||||||
{
|
|
||||||
var clientId = Guid.NewGuid().ToString();
|
|
||||||
var fio = "Fio";
|
|
||||||
var email = "email.email@email.com";
|
|
||||||
var client = CreateDataModel(clientId, fio, email);
|
|
||||||
|
|
||||||
Assert.That(() => client.Validate(), Throws.Nothing);
|
|
||||||
|
|
||||||
Assert.Multiple(() =>
|
|
||||||
{
|
|
||||||
Assert.That(client.Id, Is.EqualTo(clientId));
|
|
||||||
Assert.That(client.FIO, Is.EqualTo(fio));
|
|
||||||
Assert.That(client.Email, Is.EqualTo(email));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ClientDataModel CreateDataModel(string? id, string? fio, string? email) =>
|
|
||||||
new(id, fio, email);
|
|
||||||
}
|
|
@ -9,11 +9,11 @@ internal class EmployeeDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(),
|
var employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(),
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(),
|
employee = CreateDataModel(null, "fio", "mail@mail.com", Guid.NewGuid().ToString(),
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ internal class EmployeeDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(),
|
var employee = CreateDataModel("id", "fio", "mail@mail.com", Guid.NewGuid().ToString(),
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -29,11 +29,31 @@ internal class EmployeeDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void FIOIsNullOrEmptyTest()
|
public void FIOIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(),
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, "mail@mail.com", Guid.NewGuid().ToString(),
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(),
|
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "mail@mail.com", Guid.NewGuid().ToString(),
|
||||||
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailIsNullOrEmptyTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, Guid.NewGuid().ToString(),
|
||||||
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
|
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, Guid.NewGuid().ToString(),
|
||||||
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void EmailIsIncorrectTest()
|
||||||
|
{
|
||||||
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail", Guid.NewGuid().ToString(),
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -41,11 +61,11 @@ internal class EmployeeDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void PostIdIsNullOrEmptyTest()
|
public void PostIdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", null,
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty,
|
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com", string.Empty,
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -53,28 +73,28 @@ internal class EmployeeDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void PostIdIsNotGuidTest()
|
public void PostIdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId",
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
"postId", DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void BirthDateIsNotCorrectTest()
|
public void BirthDateIsNotCorrectTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
|
||||||
DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||||
{
|
{
|
||||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "mail@mail.com",
|
||||||
DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
Guid.NewGuid().ToString(), DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,11 +103,12 @@ internal class EmployeeDataModelTests
|
|||||||
{
|
{
|
||||||
var employeeId = Guid.NewGuid().ToString();
|
var employeeId = Guid.NewGuid().ToString();
|
||||||
var fio = "fio";
|
var fio = "fio";
|
||||||
|
var email = "mail@mail.com";
|
||||||
var postId = Guid.NewGuid().ToString();
|
var postId = Guid.NewGuid().ToString();
|
||||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||||
var employmentDate = DateTime.Now;
|
var employmentDate = DateTime.Now;
|
||||||
var isDeleted = false;
|
var isDeleted = false;
|
||||||
var employee = CreateDataModel(employeeId, fio, postId, birthDate, employmentDate, isDeleted);
|
var employee = CreateDataModel(employeeId, fio, email, postId, birthDate, employmentDate, isDeleted);
|
||||||
|
|
||||||
Assert.That(() => employee.Validate(), Throws.Nothing);
|
Assert.That(() => employee.Validate(), Throws.Nothing);
|
||||||
|
|
||||||
@ -95,6 +116,7 @@ internal class EmployeeDataModelTests
|
|||||||
{
|
{
|
||||||
Assert.That(employee.Id, Is.EqualTo(employeeId));
|
Assert.That(employee.Id, Is.EqualTo(employeeId));
|
||||||
Assert.That(employee.FIO, Is.EqualTo(fio));
|
Assert.That(employee.FIO, Is.EqualTo(fio));
|
||||||
|
Assert.That(employee.Email, Is.EqualTo(email));
|
||||||
Assert.That(employee.PostId, Is.EqualTo(postId));
|
Assert.That(employee.PostId, Is.EqualTo(postId));
|
||||||
Assert.That(employee.BirthDate, Is.EqualTo(birthDate));
|
Assert.That(employee.BirthDate, Is.EqualTo(birthDate));
|
||||||
Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate));
|
Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate));
|
||||||
@ -102,7 +124,7 @@ internal class EmployeeDataModelTests
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId,
|
private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? email,
|
||||||
DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
string? postId, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||||
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
new(id, fio, email, postId, birthDate, employmentDate, isDeleted);
|
||||||
}
|
}
|
||||||
|
@ -9,11 +9,11 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNullOrEmptyTest()
|
public void IdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
var installation = CreateDataModel(null, Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void IdIsNotGuidTest()
|
public void IdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
var installation = CreateDataModel("id", Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -29,11 +29,11 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void EmployeeIdIsNullOrEmptyTest()
|
public void EmployeeIdIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(),
|
var installation = CreateDataModel(Guid.NewGuid().ToString(), null,
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(),
|
installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -41,15 +41,7 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void EmployeeIdIsNotGuidTest()
|
public void EmployeeIdIsNotGuidTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(),
|
var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId",
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void ClientIdIsNotGuidTest()
|
|
||||||
{
|
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
|
||||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -57,11 +49,11 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void InstallationPriceIsLessOrZeroTest()
|
public void InstallationPriceIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 0, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, 0, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, -10, 20, false, CreateSubDataModel());
|
DateTime.UtcNow, -10, 20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -69,11 +61,11 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void SumIsLessOrZeroTest()
|
public void SumIsLessOrZeroTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 0, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, 0, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, -20, false, CreateSubDataModel());
|
DateTime.UtcNow, 10, -20, false, CreateSubDataModel());
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -81,11 +73,11 @@ internal class InstallationDataModelTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void ProductsIsNullOrEmptyTest()
|
public void ProductsIsNullOrEmptyTest()
|
||||||
{
|
{
|
||||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 20, false, null);
|
DateTime.UtcNow, 10, 20, false, null);
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
|
|
||||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||||
DateTime.UtcNow, 10, 20, false, []);
|
DateTime.UtcNow, 10, 20, false, []);
|
||||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||||
}
|
}
|
||||||
@ -95,12 +87,11 @@ internal class InstallationDataModelTests
|
|||||||
{
|
{
|
||||||
var installationId = Guid.NewGuid().ToString();
|
var installationId = Guid.NewGuid().ToString();
|
||||||
var employeeId = Guid.NewGuid().ToString();
|
var employeeId = Guid.NewGuid().ToString();
|
||||||
var client = Guid.NewGuid().ToString();
|
|
||||||
var installationPrice = 10;
|
var installationPrice = 10;
|
||||||
var sum = 20;
|
var sum = 20;
|
||||||
var isCanceled = true;
|
var isCanceled = true;
|
||||||
var components = CreateSubDataModel();
|
var components = CreateSubDataModel();
|
||||||
var installation = CreateDataModel(installationId, employeeId, client,
|
var installation = CreateDataModel(installationId, employeeId,
|
||||||
DateTime.UtcNow, installationPrice, sum, isCanceled, components);
|
DateTime.UtcNow, installationPrice, sum, isCanceled, components);
|
||||||
|
|
||||||
Assert.That(() => installation.Validate(), Throws.Nothing);
|
Assert.That(() => installation.Validate(), Throws.Nothing);
|
||||||
@ -109,17 +100,16 @@ internal class InstallationDataModelTests
|
|||||||
{
|
{
|
||||||
Assert.That(installation.Id, Is.EqualTo(installationId));
|
Assert.That(installation.Id, Is.EqualTo(installationId));
|
||||||
Assert.That(installation.EmployeeId, Is.EqualTo(employeeId));
|
Assert.That(installation.EmployeeId, Is.EqualTo(employeeId));
|
||||||
Assert.That(installation.ClientId, Is.EqualTo(client));
|
|
||||||
Assert.That(installation.Sum, Is.EqualTo(sum));
|
Assert.That(installation.Sum, Is.EqualTo(sum));
|
||||||
Assert.That(installation.IsCanceled, Is.EqualTo(isCanceled));
|
Assert.That(installation.IsCanceled, Is.EqualTo(isCanceled));
|
||||||
Assert.That(installation.Components, Is.EquivalentTo(components));
|
Assert.That(installation.Components, Is.EquivalentTo(components));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static InstallationDataModel CreateDataModel(string id, string employeeId, string? clientId,
|
private static InstallationDataModel CreateDataModel(string id, string employeeId,
|
||||||
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
|
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
|
||||||
List<InstallationComponentDataModel> components) =>
|
List<InstallationComponentDataModel> components) =>
|
||||||
new(id, employeeId, clientId, installationDate, installationPrice, sum, isCanceled, components);
|
new(id, employeeId, installationDate, installationPrice, sum, isCanceled, components);
|
||||||
|
|
||||||
private static List<InstallationComponentDataModel> CreateSubDataModel()
|
private static List<InstallationComponentDataModel> CreateSubDataModel()
|
||||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user