2025-02-03 01:12:50 +04:00

74 lines
2.4 KiB
C#

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);
}