2025-02-13 13:58:15 +04:00

75 lines
2.6 KiB
C#

using AndDietCokeContracts.DataModels;
using AndDietCokeContracts.Exceptions;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AndDietCokeTests.DataModelsTests;
[TestFixture]
internal class OrderDataModelTests
{
[Test]
public void OrderIdIsNullOrEmptyTest()
{
var orderDish = CreateDataModel(null, Guid.NewGuid().ToString(), 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
orderDish = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void OrderIdIsNotGuidTest()
{
var orderDish = CreateDataModel("saleId", Guid.NewGuid().ToString(), 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DishIdIsNullOrEmptyTest()
{
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), null, 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
orderDish = CreateDataModel(string.Empty, Guid.NewGuid().ToString(), 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void DishIdIsNotGuidTest()
{
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), "dishId", 10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void CountIsLessOrZeroTest()
{
var orderDish = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), 0);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
orderDish = CreateDataModel(Guid.NewGuid().ToString(), Guid.NewGuid().ToString(), -10);
Assert.That(() => orderDish.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var orderId = Guid.NewGuid().ToString();
var dishId = Guid.NewGuid().ToString();
var count = 10;
var orderDish = CreateDataModel(orderId, dishId, count);
Assert.That(() => orderDish.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(orderDish.OrderId, Is.EqualTo(orderId));
Assert.That(orderDish.DishId, Is.EqualTo(dishId));
Assert.That(orderDish.Count, Is.EqualTo(count));
});
}
private static OrderDishDataModel CreateDataModel(string? orderId, string? dishId, int count) => new(orderId, dishId, count);
}