2025-02-12 22:16:56 +04:00

55 lines
2.1 KiB
C#

using System;
using CandyHouseBase.DataModels;
using CandyHouseBase.Exceptions;
using NUnit.Framework;
namespace CandyHouseTests.DataModelsTests
{
[TestFixture]
public class CustomerDataModelTests
{
[Test]
public void Customer_ShouldThrowException_WhenIdIsInvalid()
{
var customerDataModel1 = new CustomerDataModel("", "John Doe", "+79998887766", "john@example.com");
var customerDataModel2 =
new CustomerDataModel("invalid-guid", "John Doe", "+79998887766", "john@example.com");
Assert.Throws<ValidationException>(customerDataModel1.Validate);
Assert.Throws<ValidationException>(customerDataModel2.Validate);
}
[Test]
public void Customer_ShouldThrowException_WhenFIO_IsEmpty()
{
var customerDataModel1 =
new CustomerDataModel(Guid.NewGuid().ToString(), "", "+79998887766", "john@example.com");
Assert.Throws<ValidationException>(customerDataModel1.Validate);
}
[Test]
public void Customer_ShouldThrowException_WhenPhone_IsInvalid()
{
var customerDataModel1 =
new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "123456", "john@example.com");
Assert.Throws<ValidationException>(customerDataModel1.Validate);
}
[Test]
public void Customer_ShouldThrowException_WhenEmail_IsInvalid()
{
var customerDataModel1 =
new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "+79998887766", "invalid-email");
Assert.Throws<ValidationException>(customerDataModel1.Validate);
}
[Test]
public void Customer_ShouldCreateSuccessfully_WithValidData()
{
var customer = new CustomerDataModel(Guid.NewGuid().ToString(), "John Doe", "+79998887766",
"john@example.com");
Assert.That(customer.FIO, Is.EqualTo("John Doe"));
Assert.That(customer.Phone, Is.EqualTo("+79998887766"));
Assert.That(customer.Email, Is.EqualTo("john@example.com"));
}
}
}