2025-02-05 22:13:05 +04:00
using BitterlyAndExclamationMarkContracts.DataModels ;
using BitterlyAndExclamationMarkContracts.Exceptions ;
namespace BitterlyAndExclamationMarkTests.DataModelsTests ;
[TestFixture]
internal class BuyerDataModelTests
{
[Test]
public void IdIsNullOrEmptyTest ( )
{
2025-02-11 17:33:57 +04:00
var buyer = CreateDataModel ( null , "Фамилия Имя Отчество" , "+7-777-777-77-77" , 10 ) ;
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
buyer = CreateDataModel ( string . Empty , "Фамилия Имя Отчество" , "+7-777-777-77-77" , 10 ) ; Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
2025-02-05 22:13:05 +04:00
}
[Test]
public void IdIsNotGuidTest ( )
{
2025-02-11 17:33:57 +04:00
var buyer = CreateDataModel ( "id" , "Фамилия Имя Отчество" , "+7-777-777-77-77" , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
}
[Test]
public void FIOIsNullOrEmptyTest ( )
{
2025-02-11 17:33:57 +04:00
var buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , null , "+7-777-777-77-77" , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
2025-02-11 17:33:57 +04:00
buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , string . Empty , "+7-777-777-77-77" , 10 ) ;
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
}
[Test]
public void FIOIsIncorrectTest ( )
{
var buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , "Ф" , "+7-777-777-77-77" , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
}
[Test]
public void PhoneNumberIsNullOrEmptyTest ( )
{
2025-02-11 17:33:57 +04:00
var buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , "Фамилия Имя Отчество" , null , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
2025-02-11 17:33:57 +04:00
buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , "Фамилия Имя Отчество" , string . Empty , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
}
[Test]
public void PhoneNumberIsIncorrectTest ( )
{
2025-02-11 17:33:57 +04:00
var buyer = CreateDataModel ( Guid . NewGuid ( ) . ToString ( ) , "Фамилия Имя Отчество" , "777" , 10 ) ;
2025-02-05 22:13:05 +04:00
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . TypeOf < ValidationException > ( ) ) ;
}
[Test]
public void AllFieldsIsCorrectTest ( )
{
var buyerId = Guid . NewGuid ( ) . ToString ( ) ;
2025-02-11 17:33:57 +04:00
var fio = "Фамилия Имя Отчество" ;
2025-02-05 22:13:05 +04:00
var phoneNumber = "+7-777-777-77-77" ;
var scoreCount = 11 ;
var buyer = CreateDataModel ( buyerId , fio , phoneNumber , scoreCount ) ;
Assert . That ( ( ) = > buyer . Validate ( ) , Throws . Nothing ) ;
Assert . Multiple ( ( ) = >
{
Assert . That ( buyer . Id , Is . EqualTo ( buyerId ) ) ;
Assert . That ( buyer . FIO , Is . EqualTo ( fio ) ) ;
Assert . That ( buyer . PhoneNumber , Is . EqualTo ( phoneNumber ) ) ;
Assert . That ( buyer . ScoreCount , Is . EqualTo ( scoreCount ) ) ;
} ) ;
}
private static BuyerDataModel CreateDataModel ( string? id , string? fio , string? phoneNumber , int scoreCount ) = >
new ( id , fio , phoneNumber , scoreCount ) ;
}