52 lines
1.9 KiB
C#
52 lines
1.9 KiB
C#
|
using SnowMaidenContracts.DataModels;
|
|||
|
using SnowMaidenContracts.Exceptions;
|
|||
|
|
|||
|
namespace SnowMaidenTests.DataModelsTests;
|
|||
|
|
|||
|
[TestFixture]
|
|||
|
internal class IceCreamHistoryDataModelTests
|
|||
|
{
|
|||
|
[Test]
|
|||
|
public void IceCreamIdIsNullOrEmptyTest()
|
|||
|
{
|
|||
|
var product = CreateDataModel(null, 10);
|
|||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
product = CreateDataModel(string.Empty, 10);
|
|||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void IceCreamIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var product = CreateDataModel("id", 10);
|
|||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void OldPriceIsLessOrZeroTest()
|
|||
|
{
|
|||
|
var product = CreateDataModel(Guid.NewGuid().ToString(), 0);
|
|||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
product = CreateDataModel(Guid.NewGuid().ToString(), -10);
|
|||
|
Assert.That(() => product.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void AllFieldsIsCorrectTest()
|
|||
|
{
|
|||
|
var icecreamId = Guid.NewGuid().ToString();
|
|||
|
var oldPrice = 10;
|
|||
|
var productHistory = CreateDataModel(icecreamId, oldPrice);
|
|||
|
Assert.That(() => productHistory.Validate(), Throws.Nothing);
|
|||
|
Assert.Multiple(() =>
|
|||
|
{
|
|||
|
Assert.That(productHistory.IceCreamId, Is.EqualTo(icecreamId));
|
|||
|
Assert.That(productHistory.OldPrice, Is.EqualTo(oldPrice));
|
|||
|
Assert.That(productHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
|
|||
|
Assert.That(productHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
private static IceCreamHistoryDataModel CreateDataModel(string? icecreamId, double oldPrice) =>
|
|||
|
new(icecreamId, oldPrice);
|
|||
|
}
|