85 lines
3.4 KiB
C#

using MagicCarpetContracts.DataModels;
using MagicCarpetContracts.Enums;
using MagicCarpetContracts.Exceptions;
using System;
using System.Collections.Generic;
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);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(string.Empty, "name", "country", 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var cocktail = CreateDataModel("id", "name", "country", 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TourNameIsNullOrEmptyTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, "country", 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "country", 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
public void TourCountryIsNullOrEmptyTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", null, 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), "name", string.Empty, 10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PriceIsLessOrZeroTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
cocktail = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, string.Empty, -10.5, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void TourTypeIsNoneTest()
{
var cocktail = CreateDataModel(Guid.NewGuid().ToString(), null, null, 0, TourType.Beach);
Assert.That(() => cocktail.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var tourId = Guid.NewGuid().ToString();
var tourName = "name";
var tourCountry = "country";
var price = 10.5;
var tourType = TourType.Ski;
var tour = CreateDataModel(tourId, tourName, tourCountry, price, tourType);
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));
});
}
private static TourDataModel CreateDataModel(string? id, string? tourName, string? countryName,double price, TourType tourType) =>
new(id, tourName, countryName,price, tourType);
}