58 lines
1.9 KiB
C#
Raw Normal View History

2025-02-09 15:17:40 +04:00
using MagicCarpetContracts.DataModels;
using MagicCarpetContracts.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MagicCarpetTests.DataModelTests;
[TestFixture]
internal class TourHistoryDataModelTests
{
[Test]
public void CocktailIdIsNullOrEmptyTest()
{
var tour = CreateDataModel(null, 10);
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
tour = CreateDataModel(string.Empty, 10);
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void ProductIdIsNotGuidTest()
{
var tour = CreateDataModel("id", 10);
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OldPriceIsLessOrZeroTest()
{
var tour = CreateDataModel(Guid.NewGuid().ToString(), 0);
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
tour = CreateDataModel(Guid.NewGuid().ToString(), -10);
Assert.That(() => tour.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var tourId = Guid.NewGuid().ToString();
var oldPrice = 10;
var tourHistory = CreateDataModel(tourId, oldPrice);
Assert.That(() => tourHistory.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(tourHistory.TourId, Is.EqualTo(tourId));
Assert.That(tourHistory.OldPrice, Is.EqualTo(oldPrice));
Assert.That(tourHistory.ChangeDate, Is.LessThan(DateTime.UtcNow));
Assert.That(tourHistory.ChangeDate, Is.GreaterThan(DateTime.UtcNow.AddMinutes(-1)));
});
}
private static TourHistoryDataModel CreateDataModel(string? tourId, double oldPrice) =>
new(tourId, oldPrice);
}