84 lines
2.7 KiB
C#
84 lines
2.7 KiB
C#
using WildPlumContracts.DataModels;
|
|
using WildPlumContracts.Exceptions;
|
|
|
|
namespace WildPlumTests.DataModelTests;
|
|
|
|
[TestFixture]
|
|
public class OrderProductDataModelTests
|
|
{
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenProductIdIsNullOrEmpty()
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(() => CreateDataModel(null, Guid.NewGuid().ToString(), 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
|
|
Assert.That(() => CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenProductIdIsNotGuid()
|
|
{
|
|
Assert.That(() => CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenOrderIdIsNullOrEmpty()
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), null, 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenOrderIdIsNotGuid()
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void Validate_ThrowsException_WhenCountIsLessThanOrEqualToZero()
|
|
{
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
|
|
Assert.That(() => CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1).Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
});
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsAreCorrectTest()
|
|
{
|
|
var productId = Guid.NewGuid().ToString();
|
|
var orderId = Guid.NewGuid().ToString();
|
|
var count = 5;
|
|
|
|
var orderProduct = CreateDataModel(productId, orderId, count);
|
|
|
|
Assert.That(() => orderProduct.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(orderProduct.ProductId, Is.EqualTo(productId));
|
|
Assert.That(orderProduct.OrderId, Is.EqualTo(orderId));
|
|
Assert.That(orderProduct.Count, Is.EqualTo(count));
|
|
});
|
|
}
|
|
|
|
private static OrderProductDataModel CreateDataModel(string? productId, string? orderId, int count) =>
|
|
new(productId!, orderId!, count);
|
|
}
|
|
|