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()); tour = CreateDataModel(string.Empty, 10); Assert.That(() => tour.Validate(), Throws.TypeOf()); } [Test] public void ProductIdIsNotGuidTest() { var tour = CreateDataModel("id", 10); Assert.That(() => tour.Validate(), Throws.TypeOf()); } [Test] public void OldPriceIsLessOrZeroTest() { var tour = CreateDataModel(Guid.NewGuid().ToString(), 0); Assert.That(() => tour.Validate(), Throws.TypeOf()); tour = CreateDataModel(Guid.NewGuid().ToString(), -10); Assert.That(() => tour.Validate(), Throws.TypeOf()); } [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); }