76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using TwoFromTheCasketContratcs.DataModels;
|
|||
|
using TwoFromTheCasketContratcs.Exceptions;
|
|||
|
|
|||
|
namespace TwoFromTheCasketTest.DataModelsTest;
|
|||
|
|
|||
|
[TestFixture]
|
|||
|
public class SaleServiceDataModelTests
|
|||
|
{
|
|||
|
[Test]
|
|||
|
public void SaleIdIsNullOrEmptyTest()
|
|||
|
{
|
|||
|
var saleService = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 5);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void SaleIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var saleService = CreateDataModel("invalid-guid", Guid.NewGuid().ToString(), 5);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void ServiceIdIsNullOrEmptyTest()
|
|||
|
{
|
|||
|
var saleService = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, 5);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void ServiceIdIsNotGuidTest()
|
|||
|
{
|
|||
|
var saleService = CreateDataModel(Guid.NewGuid().ToString(), "invalid-guid", 5);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void CountIsLessOrEqualToZeroTest()
|
|||
|
{
|
|||
|
var saleService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
|
|||
|
saleService = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -1);
|
|||
|
Assert.That(() => saleService.Validate(), Throws.TypeOf<ValidationException>());
|
|||
|
}
|
|||
|
|
|||
|
[Test]
|
|||
|
public void AllFieldsAreCorrectTest()
|
|||
|
{
|
|||
|
var saleId = Guid.NewGuid().ToString();
|
|||
|
var serviceId = Guid.NewGuid().ToString();
|
|||
|
var count = 5;
|
|||
|
|
|||
|
var saleService = CreateDataModel(saleId, serviceId, count);
|
|||
|
|
|||
|
Assert.That(() => saleService.Validate(), Throws.Nothing);
|
|||
|
|
|||
|
Assert.Multiple(() =>
|
|||
|
{
|
|||
|
Assert.That(saleService.SaleId, Is.EqualTo(saleId));
|
|||
|
Assert.That(saleService.ServiceId, Is.EqualTo(serviceId));
|
|||
|
Assert.That(saleService.Count, Is.EqualTo(count));
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
private static SaleServiceDataModel CreateDataModel(string saleId, string serviceId, int count)
|
|||
|
{
|
|||
|
return new SaleServiceDataModel(saleId, serviceId, count);
|
|||
|
}
|
|||
|
}
|