Тесты
This commit is contained in:
parent
34d784392f
commit
fa7a9e990e
@ -1,4 +1,5 @@
|
||||
using PimpMyRideContracts.Enums;
|
||||
|
||||
using PimpMyRideContracts.Enums;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.Extensions;
|
||||
using PimpMyRideContracts.Infrastructure;
|
||||
@ -19,6 +20,9 @@ public class OperationDataModel(string operationId, OperationType operationType,
|
||||
if (!OperationId.IsGuid())
|
||||
throw new ValidationException("The value in the field OperationId is not a unique identifier");
|
||||
|
||||
if (OperationType == OperationType.None)
|
||||
throw new ValidationException("Field OperationType is empty");
|
||||
|
||||
if ((Supplies?.Count ?? 0) == 0)
|
||||
throw new ValidationException("The operation must include supplies");
|
||||
}
|
||||
|
@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
@ -10,10 +7,83 @@ namespace PimpMyRideTests.DataModelsTests;
|
||||
internal class CarDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void Test()
|
||||
public void CarIdIsNullOrEmptyTest()
|
||||
{
|
||||
var model = new { test = "sfdg" };
|
||||
Assert.That(model, Is.Not.Null);
|
||||
Assert.That(model.test, Is.EqualTo("sfdg"));
|
||||
var car = CreateDataModel(null, "Toyota", "Supra", "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
car = CreateDataModel(string.Empty, "Toyota", "Supra", "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarIdIsNotGuidTest()
|
||||
{
|
||||
var car = CreateDataModel("id", "Toyota", "Supra", "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void CarMarkIsNullOrEmptyTest()
|
||||
{
|
||||
var car = CreateDataModel(Guid.NewGuid().ToString(), null, "Supra", "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
car = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "Supra", "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarModelIsNullOrEmptyTest()
|
||||
{
|
||||
var car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", null, "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", string.Empty, "Р243ПТ73");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarNumberIsNullOrEmptyTest()
|
||||
{
|
||||
var car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", "Supra", null);
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", "Supra", string.Empty);
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarNumberIsIncorrectTest()
|
||||
{
|
||||
var car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", "Supra", "Р24373");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
car = CreateDataModel(Guid.NewGuid().ToString(), "Toyota", "Supra", "Р243РХ1173");
|
||||
Assert.That(() => car.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var carId = Guid.NewGuid().ToString();
|
||||
var carMark = "Toyota";
|
||||
var carModel = "Supra";
|
||||
var carNumber = "М243РХ73";
|
||||
|
||||
var car = CreateDataModel(carId, carMark, carModel, carNumber);
|
||||
Assert.That(() => car.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(car.CarId, Is.EqualTo(carId));
|
||||
Assert.That(car.CarMark, Is.EqualTo(carMark));
|
||||
Assert.That(car.CarModel, Is.EqualTo(carModel));
|
||||
Assert.That(car.CarNumber, Is.EqualTo(carNumber));
|
||||
});
|
||||
}
|
||||
|
||||
private static CarDataModel CreateDataModel(string? carId, string? carMark, string? carModel, string? carNumber) =>
|
||||
new (carId, carMark, carModel, carNumber);
|
||||
}
|
||||
|
@ -0,0 +1,67 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OperationDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void OperationIdIsNullOrEmptyTest()
|
||||
{
|
||||
var operation = CreateDataModel(null, OperationType.TireReplacement, CreateSubDataModel());
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
operation = CreateDataModel(string.Empty, OperationType.TireReplacement, CreateSubDataModel());
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OperationIdIsNotGuidTest()
|
||||
{
|
||||
var operation = CreateDataModel("id", OperationType.TireReplacement, CreateSubDataModel());
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OperationTypeIsNoneTest()
|
||||
{
|
||||
var operation = CreateDataModel(Guid.NewGuid().ToString(), OperationType.None, CreateSubDataModel());
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SuppliesAreNullOrEmpty()
|
||||
{
|
||||
var operation = CreateDataModel(Guid.NewGuid().ToString(), OperationType.TireReplacement, null);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
operation = CreateDataModel(Guid.NewGuid().ToString(), OperationType.BodyPainting, []);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var operationId = Guid.NewGuid().ToString();
|
||||
var operationType = OperationType.BodyPainting;
|
||||
var supplies = CreateSubDataModel();
|
||||
|
||||
var operation = CreateDataModel(operationId, operationType, supplies);
|
||||
Assert.That(() => operation.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(operation.OperationId, Is.EqualTo(operationId));
|
||||
Assert.That(operation.OperationType, Is.EqualTo(operationType));
|
||||
Assert.That(operation.Supplies, Is.EqualTo(supplies));
|
||||
});
|
||||
}
|
||||
|
||||
private static OperationDataModel CreateDataModel(string? operationId, OperationType operationType, List<OperationSupplieDataModel>? supplies) =>
|
||||
new(operationId, operationType, supplies);
|
||||
|
||||
private static List<OperationSupplieDataModel> CreateSubDataModel() =>
|
||||
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)];
|
||||
}
|
@ -0,0 +1,73 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class OperationSuppliesDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void OperationIdIsNullOrEmptyTest()
|
||||
{
|
||||
var operation = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
operation = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OperationIdIsNotGuidTest()
|
||||
{
|
||||
var operation = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieIdIsNullOrEmptyTest()
|
||||
{
|
||||
var operation = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
operation = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieIdIsNotGuidTest()
|
||||
{
|
||||
var operation = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieCountIsNotCorrect()
|
||||
{
|
||||
var operation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
operation = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -5);
|
||||
Assert.That(() => operation.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var operationId = Guid.NewGuid().ToString();
|
||||
var supplieId = Guid.NewGuid().ToString();
|
||||
var supplieCount = 1;
|
||||
|
||||
var operation = CreateDataModel(operationId, supplieId, supplieCount);
|
||||
Assert.That(() => operation.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(operation.OperationId, Is.EqualTo(operationId));
|
||||
Assert.That(operation.SupplieId, Is.EqualTo(supplieId));
|
||||
Assert.That(operation.SupplieCount, Is.EqualTo(supplieCount));
|
||||
});
|
||||
}
|
||||
|
||||
private static OperationSupplieDataModel CreateDataModel(string? operationId, string? supplieId, int supplieCount) =>
|
||||
new(operationId, supplieId, supplieCount);
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ServiceDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void ServiceIdIsNullOrEmptyTest()
|
||||
{
|
||||
var service = CreateDataModel(null, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ServiceIdIsNotGuidTest()
|
||||
{
|
||||
var service = CreateDataModel("id", Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), null, Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), "id", Guid.NewGuid().ToString(), CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarIdIsNullOrEmptyTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null, CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), string.Empty, CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void CarIdIsNotGuidTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), "id", CreateSubDataModel());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void OperationsAreNullOrEmpty()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), []);
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var serviceId = Guid.NewGuid().ToString();
|
||||
var workerId = Guid.NewGuid().ToString();
|
||||
var carId = Guid.NewGuid().ToString();
|
||||
var operations = CreateSubDataModel();
|
||||
|
||||
var service = CreateDataModel(serviceId, workerId, carId, operations);
|
||||
Assert.That(() => service.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(service.ServiceId, Is.EqualTo(serviceId));
|
||||
Assert.That(service.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(service.CarId, Is.EqualTo(carId));
|
||||
Assert.That(service.Operations, Is.EqualTo(operations));
|
||||
});
|
||||
}
|
||||
|
||||
private static ServiceDataModel CreateDataModel(string? serviceId, string? workerId, string? carId, List<ServiceOperationDataModel>? operations) =>
|
||||
new(serviceId, workerId, carId, operations);
|
||||
|
||||
private static List<ServiceOperationDataModel> CreateSubDataModel() =>
|
||||
[new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString())];
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class ServiceOperationDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void ServiceIdIsNullOrEmptyTest()
|
||||
{
|
||||
var service = CreateDataModel(null, Guid.NewGuid().ToString());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(string.Empty, Guid.NewGuid().ToString());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ServiceIdIsNotGuidTest()
|
||||
{
|
||||
var service = CreateDataModel("id", Guid.NewGuid().ToString());
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OperationIdIsNullOrEmptyTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), null);
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
service = CreateDataModel(Guid.NewGuid().ToString(), string.Empty);
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OperationIdIsNotGuidTest()
|
||||
{
|
||||
var service = CreateDataModel(Guid.NewGuid().ToString(), "id");
|
||||
Assert.That(() => service.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var serviceId = Guid.NewGuid().ToString();
|
||||
var operationId = Guid.NewGuid().ToString();
|
||||
|
||||
var service = CreateDataModel(serviceId, operationId);
|
||||
Assert.That(() => service.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(service.ServiceId, Is.EqualTo(serviceId));
|
||||
Assert.That(service.OperationId, Is.EqualTo(operationId));
|
||||
});
|
||||
}
|
||||
|
||||
private static ServiceOperationDataModel CreateDataModel(string? serviceId, string? operationId) =>
|
||||
new(serviceId, operationId);
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class SuppliesDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void SupplieIdIsNullOrEmptyTest()
|
||||
{
|
||||
var supplie = CreateDataModel(null, "Sport rim", SuppliesType.Rims);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplie = CreateDataModel(string.Empty, "Sport rim", SuppliesType.Rims);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieIdIsNotGuidTest()
|
||||
{
|
||||
var supplie = CreateDataModel("id", "Sport rim", SuppliesType.Rims);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieNameIsNullOrEmptyTest()
|
||||
{
|
||||
var supplie = CreateDataModel(Guid.NewGuid().ToString(), null, SuppliesType.Rims);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
supplie = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, SuppliesType.Rims);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SupplieTypeIsNoneTest()
|
||||
{
|
||||
var supplie = CreateDataModel(Guid.NewGuid().ToString(), "Sport rim", SuppliesType.None);
|
||||
Assert.That(() => supplie.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AllFieldsIsCorrectTest()
|
||||
{
|
||||
var supplieId = Guid.NewGuid().ToString();
|
||||
var supplieName = "Sport rim";
|
||||
var supplieType = SuppliesType.Rims;
|
||||
|
||||
var supplie = CreateDataModel(supplieId, supplieName, supplieType);
|
||||
Assert.That(() => supplie.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(supplie.SupplieId, Is.EqualTo(supplieId));
|
||||
Assert.That(supplie.SupplieName, Is.EqualTo(supplieName));
|
||||
Assert.That(supplie.SupplieType, Is.EqualTo(supplieType));
|
||||
});
|
||||
}
|
||||
|
||||
private static SuppliesDataModel CreateDataModel(string? supplieId, string? supplieName, SuppliesType supplieType) =>
|
||||
new(supplieId, supplieName, supplieType);
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
using PimpMyRideContracts.Exceptions;
|
||||
using PimpMyRideContracts.DataModels;
|
||||
using PimpMyRideContracts.Enums;
|
||||
|
||||
namespace PimpMyRideTests.DataModelsTests;
|
||||
|
||||
[TestFixture]
|
||||
internal class WorkerDataModelTest
|
||||
{
|
||||
[Test]
|
||||
public void WorkerIdIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(null, "FIO", PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
worker = CreateDataModel(string.Empty, "FIO", PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerIdIsNotGuidTest()
|
||||
{
|
||||
var worker = CreateDataModel("id", "FIO", PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WorkerFIOIsNullOrEmptyTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), null, PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void PostTypeIsNoneTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", PostType.None, 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", PostType.CarElectrician, DateTime.Now.AddYears(-16).AddDays(1), DateTime.Now, false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void BirthDateAndEmployementDateAreNotCorrectTest()
|
||||
{
|
||||
var worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", PostType.CarElectrician, DateTime.Now.AddYears(-18), DateTime.Now.AddYears(-18).AddDays(-1), false);
|
||||
Assert.That(() => worker.Validate(), Throws.TypeOf<ValidationException>());
|
||||
|
||||
worker = CreateDataModel(Guid.NewGuid().ToString(), "FIO", PostType.CarElectrician, 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 workerFIO = "FIO";
|
||||
var postType = PostType.BodyRepairSpecialist;
|
||||
var birthDate = DateTime.Now.AddYears(-16).AddDays(-1);
|
||||
var employementDate = DateTime.Now;
|
||||
var isDeleted = false;
|
||||
|
||||
var worker = CreateDataModel(workerId, workerFIO, postType, birthDate, employementDate, isDeleted);
|
||||
Assert.That(() => worker.Validate(), Throws.Nothing);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(worker.WorkerId, Is.EqualTo(workerId));
|
||||
Assert.That(worker.WorkerFIO, Is.EqualTo(workerFIO));
|
||||
Assert.That(worker.PostType, Is.EqualTo(postType));
|
||||
Assert.That(worker.BirthDate, Is.EqualTo(birthDate));
|
||||
Assert.That(worker.EmploymentDate, Is.EqualTo(employementDate));
|
||||
Assert.That(worker.IsDeleted, Is.EqualTo(isDeleted));
|
||||
});
|
||||
}
|
||||
|
||||
private static WorkerDataModel CreateDataModel(string? workerId, string? workerFIO, PostType postType, DateTime birthDate, DateTime employmentDate, bool isDeleted) =>
|
||||
new(workerId, workerFIO, postType, birthDate, employmentDate, isDeleted);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user