using MagicCarpetContracts.DataModels; using MagicCarpetContracts.Enums; using MagicCarpetContracts.Exceptions; using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MagicCarpetTests.DataModelTests; internal class TourDataModelTests { [Test] public void IdIsNullOrEmptyTest() { var cocktail = CreateDataModel(null, "name", "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); cocktail = CreateDataModel(string.Empty, "name", "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } [Test] public void IdIsNotGuidTest() { var cocktail = CreateDataModel("id", "name", "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } [Test] public void TourNameIsNullOrEmptyTest() { var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } public void TourCountryIsNullOrEmptyTest() { var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } [Test] public void PriceIsLessOrZeroTest() { var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } [Test] public void TourTypeIsNoneTest() { var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach, CreateSuppliesDataModel(), CreateAgencyDataModel()); Assert.That(() => cocktail.Validate(), Throws.TypeOf()); } [Test] public void SuppliesIsEmptyOrNullTest() { var model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, TourType.Beach, [], CreateAgencyDataModel()); Assert.That(() => model.Validate(), Throws.TypeOf()); model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, TourType.Beach, null, CreateAgencyDataModel()); Assert.That(() => model.Validate(), Throws.TypeOf()); } [Test] public void AgencyIsEmptyOrNullTest() { var model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), []); Assert.That(() => model.Validate(), Throws.TypeOf()); model = CreateDataModel(Guid.NewGuid().ToString(), "name", "country", 10.5, TourType.Beach, CreateSuppliesDataModel(), null); Assert.That(() => model.Validate(), Throws.TypeOf()); } [Test] public void AllFieldsIsCorrectTest() { var tourId = Guid.NewGuid().ToString(); var tourName = "name"; var tourCountry = "country"; var price = 10.5; var tourType = TourType.Ski; var supplies = CreateSuppliesDataModel(); var agency = CreateAgencyDataModel(); var tour = CreateDataModel(tourId, tourName, tourCountry, price, tourType, supplies, agency); Assert.That(() => tour.Validate(), Throws.Nothing); Assert.Multiple(() => { Assert.That(tour.Id, Is.EqualTo(tourId)); Assert.That(tour.TourName, Is.EqualTo(tourName)); Assert.That(tour.TourCountry, Is.EqualTo(tourCountry)); Assert.That(tour.Price, Is.EqualTo(price)); Assert.That(tour.Type, Is.EqualTo(tourType)); Assert.That(tour.Supplies, Is.EqualTo(supplies)); Assert.That(tour.Agency, Is.EqualTo(agency)); }); } private static TourDataModel CreateDataModel(string? id, string? tourName, string? countryName, double price, TourType tourType, List supplies, List agency) => new(id, tourName, countryName,price, tourType, supplies, agency); private static List CreateSuppliesDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; private static List CreateAgencyDataModel() => [new(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 1)]; }