75 lines
2.7 KiB
C#
Raw Normal View History

2025-02-09 15:17:40 +04:00
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 ClientDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest()
{
var client = CreateDataModel(null, "fio", "number", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
client = CreateDataModel(string.Empty, "fio", "number", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void IdIsNotGuidTest()
{
var client = CreateDataModel("id", "fio", "number", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void FIOIsNullOrEmptyTest()
{
var client = CreateDataModel(Guid.NewGuid().ToString(), null, "number", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
client = CreateDataModel(Guid.NewGuid().ToString(), string.Empty, "number", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsNullOrEmptyTest()
{
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", null, 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
client = CreateDataModel(Guid.NewGuid().ToString(), "fio", string.Empty, 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void PhoneNumberIsIncorrectTest()
{
var client = CreateDataModel(Guid.NewGuid().ToString(), "fio", "777", 10);
Assert.That(() => client.Validate(), Throws.TypeOf<ValidationException>());
}
[Test]
public void AllFieldsIsCorrectTest()
{
var clientId = Guid.NewGuid().ToString();
var fio = "Fio";
var phoneNumber = "+7-777-777-77-77";
var discountSize = 11;
var buyer = CreateDataModel(clientId, fio, phoneNumber, discountSize);
Assert.That(() => buyer.Validate(), Throws.Nothing);
Assert.Multiple(() =>
{
Assert.That(buyer.Id, Is.EqualTo(clientId));
Assert.That(buyer.FIO, Is.EqualTo(fio));
Assert.That(buyer.PhoneNumber, Is.EqualTo(phoneNumber));
Assert.That(buyer.DiscountSize, Is.EqualTo(discountSize));
});
}
private static ClientDataModel CreateDataModel(string? id, string? fio, string? phoneNumber, double discountSize) =>
new(id, fio, phoneNumber, discountSize);
}