78 lines
2.9 KiB
C#
78 lines
2.9 KiB
C#
using WildPlumContracts.DataModels;
|
|
using WildPlumContracts.Enums;
|
|
using WildPlumContracts.Exceptions;
|
|
|
|
namespace WildPlumTests.DataModelTests;
|
|
|
|
[TestFixture]
|
|
public class RoleDataModelTests
|
|
{
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenIdIsNullOrEmpty()
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(() => CreateDataModel(null!, Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenIdIsNotGuid()
|
|
{
|
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenRoleIdIsNullOrEmpty()
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null!, WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenRoleIdIsNotGuid()
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", WorkerRole.Courier, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenRoleIsNone()
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), WorkerRole.None, true, DateTime.UtcNow).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsAreCorrectTest()
|
|
{
|
|
var id = Guid.NewGuid().ToString();
|
|
var roleId = Guid.NewGuid().ToString();
|
|
var role = WorkerRole.Courier;
|
|
var isActual = true;
|
|
var changeDate = DateTime.UtcNow;
|
|
|
|
var roleData = CreateDataModel(id, roleId, role, isActual, changeDate);
|
|
|
|
Assert.That(() => roleData.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(roleData.Id, Is.EqualTo(id));
|
|
Assert.That(roleData.WorkerRole, Is.EqualTo(role));
|
|
Assert.That(roleData.IsActual, Is.EqualTo(isActual));
|
|
Assert.That(roleData.ChangeDate, Is.EqualTo(changeDate).Within(TimeSpan.FromSeconds(1)));
|
|
});
|
|
}
|
|
|
|
private static RoleDataModel CreateDataModel(string id, string roleId, WorkerRole role, bool isActive, DateTime createdAt) =>
|
|
new(id, role, roleId, isActive, createdAt);
|
|
} |