61 lines
2.0 KiB
C#
61 lines
2.0 KiB
C#
using SquirrelBarContracts.DataModels;
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
namespace SquirrelBarTests.DataModelsTests;
|
|
|
|
[TestFixture]
|
|
internal class ClientDiscountDataModelTests
|
|
{
|
|
[Test]
|
|
public void BuyerIdIsNullOrEmptyTest()
|
|
{
|
|
var product = CreateDataModel(null, 100,10);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
product = CreateDataModel(string.Empty, 100,10);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void ProductIdIsNotGuidTest()
|
|
{
|
|
var product = CreateDataModel("id", 100,10);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
[Test]
|
|
public void personalDiscountIsLessThenZeroTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), -100, 10);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TotalSumIsLessThenZeroTest()
|
|
{
|
|
var product = CreateDataModel(Guid.NewGuid().ToString(), -100, 10);
|
|
Assert.That(() => product.Validate(),
|
|
Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
var buyerId = Guid.NewGuid().ToString();
|
|
var totalSum = 100;
|
|
var personalDiscount = 10;
|
|
var clientDiscount = CreateDataModel(buyerId, totalSum, personalDiscount);
|
|
Assert.That(() => clientDiscount.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(clientDiscount.BuyerId, Is.EqualTo(buyerId));
|
|
Assert.That(clientDiscount.TotalSum, Is.EqualTo(totalSum));
|
|
Assert.That(clientDiscount.PersonalDiscount, Is.EqualTo(personalDiscount));
|
|
|
|
});
|
|
}
|
|
private static ClientDiscountDataModel CreateDataModel(string? buyerId, double totalSum, double personalDiscount) =>
|
|
new(buyerId, totalSum, personalDiscount);
|
|
}
|