using SoftwareInstallationContracts.DataModels; using SoftwareInstallationContracts.Enums; using SoftwareInstallationContracts.Exceptions; namespace SoftwareInstallationTests.DataModelsTests; [TestFixture] internal class SoftwareDataModelTests { private SoftwareDataModel software; [Test] public void IdIsNullOrEmptyTest() { software = CreateDataModel(null, "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); software = CreateDataModel(string.Empty, "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { software = CreateDataModel("id", "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void SoftwareNameIsEmptyTest() { software = CreateDataModel(Guid.NewGuid().ToString(), null, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void SoftwareTypeIsNoneTest() { software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.None, Guid.NewGuid().ToString(), 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void CompanyIdIsNullOrEmptyTest() { software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, null, 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, string.Empty, 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void CompanyIdIsNotGuidTest() { software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, "companyId", 10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void PriceIsLessOrZeroTest() { software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 0, false); Assert.That(() => software.Validate(), Throws.TypeOf()); software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), -10, false); Assert.That(() => software.Validate(), Throws.TypeOf()); } [Test] public void AllFieldsIsCorrectTest() { string softwareId = Guid.NewGuid().ToString(); string softwareName = "name"; SoftwareType softwareType = SoftwareType.ApplicationSoftware; string softwareCompanyId = Guid.NewGuid().ToString(); double softwarePrice = 10; bool softwareIsDelete = false; SoftwareDataModel software = CreateDataModel(softwareId, softwareName, softwareType, softwareCompanyId, softwarePrice, softwareIsDelete); Assert.That(() => software.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(software.Id, Is.EqualTo(softwareId)); Assert.That(software.SoftwareName, Is.EqualTo(softwareName)); Assert.That(software.SoftwareType, Is.EqualTo(softwareType)); Assert.That(software.CompanyId, Is.EqualTo(softwareCompanyId)); Assert.That(software.Price, Is.EqualTo(softwarePrice)); Assert.That(software.IsDeleted, Is.EqualTo(softwareIsDelete)); }); } private static SoftwareDataModel CreateDataModel(string? id, string? softwareName, SoftwareType softwareType, string? companyId, double price, bool isDeleted) => new(id, softwareName, softwareType, companyId, price, isDeleted); }