79 lines
2.8 KiB
C#
79 lines
2.8 KiB
C#
using SoftwareInstallationContracts.DataModels;
|
|
using SoftwareInstallationContracts.Exceptions;
|
|
|
|
namespace SoftwareInstallationTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class ClientDataModelTests
|
|
{
|
|
private ClientDataModel client;
|
|
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
client = CreateDataModel(null, "Fio Fio Fio", "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
client = CreateDataModel(string.Empty, "Fio Fio Fio", "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
client = CreateDataModel("id", "Fio Fio Fio", "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void FIOIsNullOrEmptyTest()
|
|
{
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), null, "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void FIOIsIncorrectTest()
|
|
{
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "+7-777-777-77-77");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PhoneNumberIsNullOrEmptyTest()
|
|
{
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", null);
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", string.Empty);
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void PhoneNumberIsIncorrectTest()
|
|
{
|
|
client = CreateDataModel(Guid.NewGuid().ToString(), "Fio Fio Fio", "777");
|
|
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
string phoneNumber = "+7-777-777-77-77";
|
|
string fio = "Vasiliy Vasiliev Vasilievich";
|
|
string id = Guid.NewGuid().ToString();
|
|
client = CreateDataModel(id, fio, phoneNumber);
|
|
Assert.That(() => client.Validate(), Throws.Nothing);
|
|
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(client.Id, Is.EqualTo(id));
|
|
Assert.That(client.FIO, Is.EqualTo(fio));
|
|
Assert.That(client.PhoneNumber, Is.EqualTo(phoneNumber));
|
|
});
|
|
}
|
|
|
|
private static ClientDataModel CreateDataModel(string? id, string? fio, string? phoneNumber) =>
|
|
new(id, fio, phoneNumber);
|
|
}
|