Files
Pibd-21_Semin_D.A._SmallSof…/SmallSoftwareProject/SmallSoftwareTests/DataModelsTests/SupplyDataModelTests.cs
2025-04-24 11:19:47 +04:00

82 lines
3.2 KiB
C#

using SmallSoftwareContracts.DataModels;
using SmallSoftwareContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmallSoftwareTests.DataModelsTests;
[TestFixture]
internal class SupplyDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var supply = CreateDataModel(null, Guid.NewGuid().ToString(), DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var supply = CreateDataModel("invalid-id", Guid.NewGuid().ToString(), DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNullOrEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), null, DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
supply = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void StorageIdIsNotGuidTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), "invalid-storage-id", DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void SupplyIngredientsIsEmptyTest()
{
var supply = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), DateTime.UtcNow, new List<SupplySoftwareDataModel>());
Assert.That(() => supply.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsAreCorrectTest()
{
var supplyId = Guid.NewGuid().ToString();
var storageId = Guid.NewGuid().ToString();
var supplyDate = DateTime.UtcNow;
var supplySoftwarees = new List<SupplySoftwareDataModel>
{
new SupplySoftwareDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 10)
};
var supply = CreateDataModel(supplyId, storageId, supplyDate, supplySoftwarees);
Assert.That(() => supply.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(supply.Id, Is.EqualTo(supplyId));
Assert.That(supply.StorageId, Is.EqualTo(storageId));
Assert.That(supply.SupplyDate, Is.EqualTo(supplyDate));
Assert.That(supply.Softwares, Is.EqualTo(supplySoftwarees));
});
}
private static SupplyDataModel CreateDataModel(string? id, string? storageId, DateTime supplyDate, List<SupplySoftwareDataModel> supplySoftwarees)
{
return new SupplyDataModel(id, storageId, supplyDate, supplySoftwarees);
}
}