89 lines
3.8 KiB
C#
89 lines
3.8 KiB
C#
using SoftwareInstallationContracts.DataModels;
|
|
using SoftwareInstallationContracts.Exceptions;
|
|
|
|
namespace SoftwareInstallationTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class SoftwareSupplyDataModelTests
|
|
{
|
|
private SoftwareSupplyDataModel softwareSupply;
|
|
|
|
[Test]
|
|
public void IdIsNullOrEmptyTest()
|
|
{
|
|
softwareSupply = CreateDataModel(null, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
softwareSupply = CreateDataModel(string.Empty, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void IdIsNotGuidTest()
|
|
{
|
|
softwareSupply = CreateDataModel("id", 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SoftwareIdIsNullOrEmptyTest()
|
|
{
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, null, Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, string.Empty, Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SoftwareIdIsNotGuidTest()
|
|
{
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, "softwareId", Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SupplyIdIsNullOrEmptyTest()
|
|
{
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), null);
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), string.Empty);
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SupplyIdIsNotGuidTest()
|
|
{
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), "supplyId");
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void CountIsLessOrZeroTest()
|
|
{
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString());
|
|
Assert.That(() => softwareSupply.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
string id = Guid.NewGuid().ToString();
|
|
string softwareId = Guid.NewGuid().ToString();
|
|
string supplyId = Guid.NewGuid().ToString();
|
|
int count = 10;
|
|
softwareSupply = CreateDataModel(id, count, softwareId, supplyId);
|
|
Assert.That(() => softwareSupply.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(softwareSupply.Id, Is.EqualTo(id));
|
|
Assert.That(softwareSupply.SoftwareId, Is.EqualTo(softwareId));
|
|
Assert.That(softwareSupply.SupplyId, Is.EqualTo(supplyId));
|
|
Assert.That(softwareSupply.Count, Is.EqualTo(count));
|
|
});
|
|
}
|
|
|
|
private static SoftwareSupplyDataModel CreateDataModel(string? id, int count, string? softwareId, string? supplyId)
|
|
=> new(id, count, softwareId, supplyId);
|
|
}
|