54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using RomashkiContract.DataModels;
|
|||
|
using RomashkiContracts.Exceptions;
|
|||
|
|
|||
|
namespace RomashkiTests;
|
|||
|
|
|||
|
internal class DiscountDataModelTests
|
|||
|
{
|
|||
|
[Test]
|
|||
|
public void BuyerIdIsEmptyTest()
|
|||
|
{
|
|||
|
var discount = CreateDataModel(null, DateTime.Now, 10);
|
|||
|
Assert.That(() => discount.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
discount = CreateDataModel(string.Empty, DateTime.Now, 10);
|
|||
|
Assert.That(() => discount.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
[Test]
|
|||
|
public void BuyerIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var discount = CreateDataModel("buyerId", DateTime.Now, 10);
|
|||
|
Assert.That(() => discount.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
[Test]
|
|||
|
public void DiscountIsLessOrMoreTest()
|
|||
|
{
|
|||
|
var discount = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, -1);
|
|||
|
Assert.That(() => discount.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
discount = CreateDataModel(Guid.NewGuid().ToString(), DateTime.Now, 101);
|
|||
|
Assert.That(() => discount.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
[Test]
|
|||
|
public void AllFieldsIsCorrectTest()
|
|||
|
{
|
|||
|
var buyerId = Guid.NewGuid().ToString();
|
|||
|
var discountDate = DateTime.Now.AddDays(-3).AddMinutes(-5);
|
|||
|
var discountSize = 10;
|
|||
|
var discount = CreateDataModel(buyerId, discountDate, discountSize);
|
|||
|
Assert.That(() => discount.Validate(), Throws.Nothing);
|
|||
|
Assert.Multiple(() =>
|
|||
|
{
|
|||
|
Assert.That(discount.BuyerId, Is.EqualTo(buyerId));
|
|||
|
Assert.That(discount.DiscountDate, Is.EqualTo(discountDate));
|
|||
|
Assert.That(discount.DiscountSize, Is.EqualTo(discountSize));
|
|||
|
});
|
|||
|
}
|
|||
|
private static DiscountDataModel CreateDataModel(string? buyerId, DateTime discountDate, double discountSize) =>
|
|||
|
new(buyerId, discountDate, discountSize);
|
|||
|
|
|||
|
}
|