forked from slavaxom9k/PIBD-23_Fomichev_V.S._MagicCarpet
76 lines
2.6 KiB
C#
76 lines
2.6 KiB
C#
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 TourSuppliesDataModelTests
|
|
{
|
|
[Test]
|
|
public void SuppliesIdIsNullOrEmptyTest()
|
|
{
|
|
var model = CreateDataModel(null, Guid.NewGuid().ToString(), 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
model = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void SuppliesIdIsNotGuidTest()
|
|
{
|
|
var model = CreateDataModel("id", Guid.NewGuid().ToString(), 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TourIdIsNullOrEmptyTest()
|
|
{
|
|
var model = CreateDataModel(Guid.NewGuid().ToString(), null, 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
|
|
model = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void TourIdIsNotGuidTest()
|
|
{
|
|
var model = CreateDataModel(Guid.NewGuid().ToString(), "id", 1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void CountIsLessOrZeroTest()
|
|
{
|
|
var model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
model = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
|
Assert.That(() => model.Validate(), Throws.TypeOf<ValidationException>());
|
|
}
|
|
|
|
[Test]
|
|
public void AllFieldsIsCorrectTest()
|
|
{
|
|
var suppliesId = Guid.NewGuid().ToString();
|
|
var tourId = Guid.NewGuid().ToString();
|
|
var count = 1;
|
|
var model = CreateDataModel(suppliesId, tourId, count);
|
|
Assert.That(() => model.Validate(), Throws.Nothing);
|
|
Assert.Multiple(() =>
|
|
{
|
|
Assert.That(model.SuppliesId, Is.EqualTo(suppliesId));
|
|
Assert.That(model.TourId, Is.EqualTo(tourId));
|
|
Assert.That(model.Count, Is.EqualTo(count));
|
|
});
|
|
}
|
|
|
|
private static TourSuppliesDataModel CreateDataModel(string? suppliesId, string? tourId, int count)
|
|
=> new(suppliesId, tourId, count);
|
|
}
|