add tests
This commit is contained in:
parent
5790aecef2
commit
8d3154953b
@ -5,6 +5,8 @@ VisualStudioVersion = 17.12.35707.178 d17.12
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsContracts", "TheCyclopsContracts\TheCyclopsContracts.csproj", "{01934235-715E-4B95-B859-48E8C89DA7CB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TheCyclopsTests", "TheCyclopsTests\TheCyclopsTests.csproj", "{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -15,6 +17,10 @@ Global
|
||||
{01934235-715E-4B95-B859-48E8C89DA7CB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{01934235-715E-4B95-B859-48E8C89DA7CB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{78C9F1B1-ABD3-4ED2-A5DC-84766DEEFC77}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -0,0 +1,73 @@
|
||||
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);
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Enums;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ComponentDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(null, "name", ComponentType.Other, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(string.Empty, "name", ComponentType.Other, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var component = CreateDataModel("id", "name", ComponentType.Other, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductNameIsEmptyTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.Other, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, ComponentType.Other, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentTypeIsNoneTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), null, ComponentType.None, 10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PriceIsLessOrZeroTest()
|
||||
{
|
||||
var component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, 0, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
component = CreateDataModel(Guid.NewGuid().ToString(), "name", ComponentType.Other, -10, false);
|
||||
Assert.That(() => component.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var componentName = "name";
|
||||
var componentType = ComponentType.Other;
|
||||
var componentManufacturerId = Guid.NewGuid().ToString();
|
||||
var componentPrice = 10;
|
||||
var componentIsDelete = false;
|
||||
var component = CreateDataModel(componentId, componentName, componentType, componentPrice, componentIsDelete);
|
||||
|
||||
Assert.That(() => component.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(component.Id, Is.EqualTo(componentId));
|
||||
Assert.That(component.ComponentName, Is.EqualTo(componentName));
|
||||
Assert.That(component.ComponentType, Is.EqualTo(componentType));
|
||||
Assert.That(component.Price, Is.EqualTo(componentPrice));
|
||||
Assert.That(component.IsDeleted, Is.EqualTo(componentIsDelete));
|
||||
});
|
||||
}
|
||||
|
||||
private static ComponentDataModel CreateDataModel(string? id, string? componentName,
|
||||
ComponentType componentType, double price, bool isDeleted) =>
|
||||
new(id, componentName, componentType, price, isDeleted);
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class EmployeeDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(null, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
employee = CreateDataModel(string.Empty, "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel("id", "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void FIOIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullOrEmptyTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", null,
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty,
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", "postId",
|
||||
DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmploymentDateIsNotCorrectTest()
|
||||
{
|
||||
var employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
employee = CreateDataModel(Guid.NewGuid().ToString(), "fio", Guid.NewGuid().ToString(),
|
||||
DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-16), false);
|
||||
Assert.That(() => employee.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var fio = "fio";
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employmentDate = DateTime.Now;
|
||||
var isDeleted = false;
|
||||
var employee = CreateDataModel(employeeId, fio, postId, birthDate, employmentDate, isDeleted);
|
||||
|
||||
Assert.That(() => employee.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(employee.Id, Is.EqualTo(employeeId));
|
||||
Assert.That(employee.FIO, Is.EqualTo(fio));
|
||||
Assert.That(employee.PostId, Is.EqualTo(postId));
|
||||
Assert.That(employee.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(employee.EmploymentDate, Is.EqualTo(employmentDate));
|
||||
Assert.That(employee.IsDeleted, Is.EqualTo(isDeleted));
|
||||
});
|
||||
}
|
||||
|
||||
private static EmployeeDataModel CreateDataModel(string? id, string? fio, string? postId,
|
||||
DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(id, fio, postId, birthDate, employmentDate, isDeleted);
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class InstallationComponentDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void InstallationIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstallationIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel("installationId", Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNullOrEmptyTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
saleProduct = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ComponentIdIsNotGuidTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), "componentId", 10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CountIsLessOrZeroTest()
|
||||
{
|
||||
var saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
saleProduct = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
||||
Assert.That(() => saleProduct.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var installationId = Guid.NewGuid().ToString();
|
||||
var componentId = Guid.NewGuid().ToString();
|
||||
var count = 10;
|
||||
var saleProduct = CreateDataModel(installationId, componentId, count);
|
||||
|
||||
Assert.That(() => saleProduct.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(saleProduct.InstallationId, Is.EqualTo(installationId));
|
||||
Assert.That(saleProduct.ComponentId, Is.EqualTo(componentId));
|
||||
Assert.That(saleProduct.Count, Is.EqualTo(count));
|
||||
});
|
||||
}
|
||||
|
||||
private static InstallationComponentDataModel CreateDataModel(string? installationId, string? componentId, int count) =>
|
||||
new(installationId, componentId, count);
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class InstallationDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var installation = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
installation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var installation = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(),
|
||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNullOrEmptyTest()
|
||||
{
|
||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(),
|
||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
installation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(),
|
||||
DateTime.UtcNow, 10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EmployeeIdIsNotGuidTest()
|
||||
{
|
||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), "employeeId", Guid.NewGuid().ToString(),
|
||||
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());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void InstallationPriceIsLessOrZeroTest()
|
||||
{
|
||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, 0, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, -10, 20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SumIsLessOrZeroTest()
|
||||
{
|
||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, 10, 0, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, 10, -20, false, CreateSubDataModel());
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ProductsIsNullOrEmptyTest()
|
||||
{
|
||||
var installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, 10, 20, false, null);
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
installation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "buyerId",
|
||||
DateTime.UtcNow, 10, 20, false, []);
|
||||
Assert.That(() => installation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var installationId = Guid.NewGuid().ToString();
|
||||
var employeeId = Guid.NewGuid().ToString();
|
||||
var client = Guid.NewGuid().ToString();
|
||||
var installationPrice = 10;
|
||||
var sum = 20;
|
||||
var isCanceled = true;
|
||||
var components = CreateSubDataModel();
|
||||
var installation = CreateDataModel(installationId, employeeId, client,
|
||||
DateTime.UtcNow, installationPrice, sum, isCanceled, components);
|
||||
|
||||
Assert.That(() => installation.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(installation.Id, Is.EqualTo(installationId));
|
||||
Assert.That(installation.EmployeeId, Is.EqualTo(employeeId));
|
||||
Assert.That(installation.ClientId, Is.EqualTo(client));
|
||||
Assert.That(installation.Sum, Is.EqualTo(sum));
|
||||
Assert.That(installation.IsCanceled, Is.EqualTo(isCanceled));
|
||||
Assert.That(installation.Components, Is.EquivalentTo(components));
|
||||
});
|
||||
}
|
||||
|
||||
private static InstallationDataModel CreateDataModel(string id, string employeeId, string? clientId,
|
||||
DateTime installationDate, double installationPrice, double sum, bool isCanceled,
|
||||
List<InstallationComponentDataModel> components) =>
|
||||
new(id, employeeId, clientId, installationDate, installationPrice, sum, isCanceled, components);
|
||||
|
||||
private static List<InstallationComponentDataModel> CreateSubDataModel()
|
||||
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,110 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Enums;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class PostDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void IdIsNullOrEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(null, Guid.NewGuid().ToString(), "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void IdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel("id", Guid.NewGuid().ToString(), "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNullEmptyTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), null, "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostIdIsNotGuidTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), "postId", "post",
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostNameIsEmptyTest()
|
||||
{
|
||||
var manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null,
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
manufacturer = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty,
|
||||
PostType.Designer, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => manufacturer.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
||||
PostType.None, 10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SalaryIsLessOrZeroTest()
|
||||
{
|
||||
var post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
||||
PostType.Designer, 0, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
post = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "post",
|
||||
PostType.Designer, -10, true, DateTime.UtcNow);
|
||||
Assert.That(() => post.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var postId = Guid.NewGuid().ToString();
|
||||
var postPostId = Guid.NewGuid().ToString();
|
||||
var postName = "name";
|
||||
var postType = PostType.Designer;
|
||||
var salary = 10;
|
||||
var isActual = false;
|
||||
var changeDate = DateTime.UtcNow.AddDays(-1);
|
||||
var post = CreateDataModel(postId, postPostId, postName, postType, salary, isActual, changeDate);
|
||||
|
||||
Assert.That(() => post.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(post.Id, Is.EqualTo(postId));
|
||||
Assert.That(post.PostId, Is.EqualTo(postPostId));
|
||||
Assert.That(post.PostName, Is.EqualTo(postName));
|
||||
Assert.That(post.PostType, Is.EqualTo(postType));
|
||||
Assert.That(post.Salary, Is.EqualTo(salary));
|
||||
Assert.That(post.IsActual, Is.EqualTo(isActual));
|
||||
Assert.That(post.ChangeDate, Is.EqualTo(changeDate));
|
||||
});
|
||||
}
|
||||
|
||||
private static PostDataModel CreateDataModel(string? id, string? postId, string? postName, PostType postType, double salary, bool isActual, DateTime changeDate) =>
|
||||
new(id, postId, postName, postType, salary, isActual, changeDate);
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
using TheCyclopsContracts.DataModels;
|
||||
using TheCyclopsContracts.Exceptions;
|
||||
|
||||
namespace TheCyclopsTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SalaryDataModelTests
|
||||
{
|
||||
[Test]
|
||||
public void WorkerIdIsEmptyTest()
|
||||
{
|
||||
var salary = CreateDataModel(null, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
salary = CreateDataModel(string.Empty, DateTime.Now, 10);
|
||||
Assert.That(() => salary.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var salary = CreateDataModel("employeeId", 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 employeeId = Guid.NewGuid().ToString();
|
||||
var salaryDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
||||
var employeeSalary = 10;
|
||||
var salary = CreateDataModel(employeeId, salaryDate, employeeSalary);
|
||||
|
||||
Assert.That(() => salary.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(salary.EmployeeId, Is.EqualTo(employeeId));
|
||||
Assert.That(salary.SalaryDate, Is.EqualTo(salaryDate));
|
||||
Assert.That(salary.Salary, Is.EqualTo(employeeSalary));
|
||||
});
|
||||
}
|
||||
|
||||
private static SalaryDataModel CreateDataModel(string? employeeId, DateTime salaryDate, double workerSalary) =>
|
||||
new(employeeId, salaryDate, workerSalary);
|
||||
}
|
27
TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.csproj
Normal file
27
TheCyclopsProject/TheCyclopsTests/TheCyclopsTests.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="..\TheCyclopsContracts\TheCyclopsContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Using Include="NUnit.Framework" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user