2025-02-04 07:39:43 +04:00
|
|
|
|
using SoftwareInstallationContracts.DataModels;
|
|
|
|
|
using SoftwareInstallationContracts.Enums;
|
|
|
|
|
using SoftwareInstallationContracts.Exceptions;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using static NUnit.Framework.Internal.OSPlatform;
|
|
|
|
|
|
|
|
|
|
namespace SoftwareInstallationTests.DataModelsTests;
|
|
|
|
|
|
2025-02-10 22:33:08 +04:00
|
|
|
|
[TestFixture]
|
2025-02-04 07:39:43 +04:00
|
|
|
|
internal class SoftwareDataModelTests
|
|
|
|
|
{
|
|
|
|
|
private SoftwareDataModel software;
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IdIsNullOrEmptyTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(null, "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(string.Empty, "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IdIsNotGuidTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel("id", "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SoftwareNameIsEmptyTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), null, SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), string.Empty,
|
|
|
|
|
SoftwareType.ApplicationSoftware, Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void SoftwareTypeIsNoneTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.None,
|
|
|
|
|
Guid.NewGuid().ToString(), 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CompanyIdIsNullOrEmptyTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
null, 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
string.Empty, 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CompanyIdIsNotGuidTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
"companyId", 10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void PriceIsLessOrZeroTest()
|
|
|
|
|
{
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), 0, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
2025-02-10 22:33:08 +04:00
|
|
|
|
software = CreateDataModel(Guid.NewGuid().ToString(), "name", SoftwareType.ApplicationSoftware,
|
|
|
|
|
Guid.NewGuid().ToString(), -10, false, CreateSubDataModel());
|
2025-02-04 07:39:43 +04:00
|
|
|
|
Assert.That(() => software.Validate(), Throws.TypeOf<ValidationFieldException>());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[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;
|
2025-02-10 22:33:08 +04:00
|
|
|
|
|
|
|
|
|
List<SoftwareWarehouseDataModel> warehouses = CreateSubDataModel();
|
|
|
|
|
|
|
|
|
|
software = CreateDataModel(softwareId, softwareName, softwareType, softwareCompanyId,
|
|
|
|
|
softwarePrice, softwareIsDelete, warehouses);
|
2025-02-04 07:39:43 +04:00
|
|
|
|
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,
|
2025-02-10 22:33:08 +04:00
|
|
|
|
string? companyId, double price, bool isDeleted, List<SoftwareWarehouseDataModel> warehouses) =>
|
|
|
|
|
new(id, softwareName, softwareType, companyId, price, isDeleted, warehouses);
|
|
|
|
|
|
|
|
|
|
private static List<SoftwareWarehouseDataModel> CreateSubDataModel()
|
|
|
|
|
=> [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10, 20)];
|
2025-02-04 07:39:43 +04:00
|
|
|
|
}
|