2025-02-04 07:39:43 +04:00
|
|
|
|
using SoftwareInstallationContracts.DataModels;
|
|
|
|
|
using SoftwareInstallationContracts.Exceptions;
|
|
|
|
|
|
|
|
|
|
namespace SoftwareInstallationTests.DataModelsTests;
|
|
|
|
|
|
2025-02-10 23:01:23 +04:00
|
|
|
|
[TestFixture]
|
2025-02-04 07:39:43 +04:00
|
|
|
|
internal class InstallationSoftwareDataModelTests
|
|
|
|
|
{
|
|
|
|
|
private InstallationSoftwareDataModel installSoftware;
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void InstallIdIsNullOrEmptyTest()
|
|
|
|
|
{
|
|
|
|
|
installSoftware = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void InstallIdIsNotGuidTest()
|
|
|
|
|
{
|
|
|
|
|
installSoftware = CreateDataModel("installId", Guid.NewGuid().ToString(), 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SoftwareIdIsNullOrEmptyTest()
|
|
|
|
|
{
|
|
|
|
|
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
installSoftware = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SoftwareIdIsNotGuidTest()
|
|
|
|
|
{
|
|
|
|
|
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), "softwareId", 10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CountIsLessOrZeroTest()
|
|
|
|
|
{
|
|
|
|
|
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
installSoftware = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void AllFieldsIsCorrectTest()
|
|
|
|
|
{
|
|
|
|
|
string installId = Guid.NewGuid().ToString();
|
|
|
|
|
string softwareId = Guid.NewGuid().ToString();
|
|
|
|
|
int count = 10;
|
|
|
|
|
installSoftware = CreateDataModel(installId, softwareId, count);
|
|
|
|
|
Assert.That(() => installSoftware.Validate(), Throws.Nothing);
|
|
|
|
|
Assert.Multiple(() =>
|
|
|
|
|
{
|
2025-02-10 20:47:17 +04:00
|
|
|
|
Assert.That(installSoftware.InstallationId, Is.EqualTo(installId));
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(installSoftware.ProgramId, Is.EqualTo(softwareId));
|
|
|
|
|
Assert.That(installSoftware.Count, Is.EqualTo(count));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static InstallationSoftwareDataModel CreateDataModel(string? installId, string? softwareId, int count) =>
|
|
|
|
|
new(installId, softwareId, count);
|
|
|
|
|
}
|