using SoftwareInstallationContracts.DataModels; using SoftwareInstallationContracts.Exceptions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoftwareInstallationTests.DataModelsTests; 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()); softwareSupply = CreateDataModel(string.Empty, 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { softwareSupply = CreateDataModel("id", 10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void SoftwareIdIsNullOrEmptyTest() { softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, null, Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, string.Empty, Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void SoftwareIdIsNotGuidTest() { softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, "softwareId", Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void SupplyIdIsNullOrEmptyTest() { softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), null); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), string.Empty); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void SupplyIdIsNotGuidTest() { softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 10, Guid.NewGuid().ToString(), "supplyId"); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [Test] public void CountIsLessOrZeroTest() { softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), 0, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); softwareSupply = CreateDataModel(Guid.NewGuid().ToString(), -10, Guid.NewGuid().ToString(), Guid.NewGuid().ToString()); Assert.That(() => softwareSupply.Validate(), Throws.TypeOf()); } [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); }