@@ -16,8 +16,10 @@ namespace TwoFromTheCasketTest.BuisnessLogicContractTests;
[TestFixture]
internal class SalaryBusinessLogicContractTests
{
private SalaryBusinessLogicContract _salaryBusinessLogicContract ;
private Mock < ISalaryStorageContract > _salaryStorageContract ;
private Mock < IOrderStorageContract > _orderStorageContract ;
private Mock < IPostStorageContract > _postStorageContract ;
private Mock < IMasterStorageContract > _masterStorageContract ;
@@ -25,196 +27,406 @@ internal class SalaryBusinessLogicContractTests
public void OneTimeSetUp ( )
{
_salaryStorageContract = new Mock < ISalaryStorageContract > ( ) ;
_orderStorageContract = new Mock < IOrderStorageContract > ( ) ;
_postStorageContract = new Mock < IPostStorageContract > ( ) ;
_masterStorageContract = new Mock < IMasterStorageContract > ( ) ;
_salaryBusinessLogicContract = new SalaryBusinessLogicContract (
_salary StorageContract. Object ,
_postStorageContract . Object ,
_masterStorageContract . Object ,
new Mock < ILogger > ( ) . Object
) ;
_salaryBusinessLogicContract = new SalaryBusinessLogicContract ( _salaryStorageContract . Object ,
_postStorageContract . Object , _masterStorageContract . Object ,
new Mock < ILogger > ( ) . Object , _order StorageContract. Object ) ;
}
[SetUp]
public void SetUp ( )
{
_salaryStorageContract . Reset ( ) ;
_orderStorageContract . Reset ( ) ;
_postStorageContract . Reset ( ) ;
_masterStorageContract . Reset ( ) ;
}
[Test]
public void GetAllSalariesByPeriod _ReturnListOfRecords_Test ( )
public void GetAllSalaries_ReturnListOfRecords_Test ( )
{
// Arrange
//Arrange
var startDate = DateTime . UtcNow ;
var endDate = DateTime . UtcNow . AddDays ( 1 ) ;
var listOriginal = new List < SalaryDataModel >
var listOriginal = new List < SalaryDataModel > ( )
{
new SalaryDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow , 1000 , 20 0) ,
new SalaryDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( 1 ) , 1500 , 30 0) ,
new SalaryDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( - 1 ) , 120 0, 25 0)
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow , 10 , 1 0) ,
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( 1 ) , 14 , 1 0) ,
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( - 1 ) , 3 0, 1 0) ,
} ;
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ) . Returns ( listOriginal ) ;
// Act
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) )
. Returns ( listOriginal ) ;
//Act
var list = _salaryBusinessLogicContract . GetAllSalariesByPeriod ( startDate , endDate ) ;
// Assert
//Assert
Assert . That ( list , Is . Not . Null ) ;
Assert . That ( list , Is . EquivalentTo ( listOriginal ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Once ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( startDate , endDate , null ) , Times . Once ) ;
}
[Test]
public void GetAllSalariesByPeriod _ReturnEmptyList_Test ( )
public void GetAllSalaries_ReturnEmptyList_Test ( )
{
// Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ) . Returns ( new List < SalaryDataModel > ( ) ) ;
// Act
//Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) )
. Returns ( [ ] ) ;
//Act
var list = _salaryBusinessLogicContract . GetAllSalariesByPeriod ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) ) ;
// Assert
//Assert
Assert . That ( list , Is . Not . Null ) ;
Assert . That ( list . Count, Is . EqualTo ( 0 ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Once ) ;
Assert . That ( list , Has .Count . EqualTo ( 0 ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void GetAllSalariesByPeriod_StorageThrowError _ThrowException_Test ( )
public void GetAllSalaries_IncorrectDates _ThrowException_Test ( )
{
// Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ) . Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
//Arrange
var dateTime = DateTime . UtcNow ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriod ( dateTime , dateTime ) ,
Throws . TypeOf < IncorrectDatesException > ( ) ) ;
Assert . That ( ( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriod ( dateTime , dateTime . AddSeconds ( - 1 ) ) ,
Throws . TypeOf < IncorrectDatesException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Never ) ;
}
// Act & Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriod ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) ) ,
[Test]
public void GetAllSalaries_ReturnNull_ThrowException_Test ( )
{
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriod ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) ) ,
Throws . TypeOf < NullListException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void GetAllSalaries_StorageThrowError_ThrowException_Test ( )
{
//Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) )
. Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriod ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) ) ,
Throws . TypeOf < StorageException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Once ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void GetAllSalariesByPeriodBy Master_ReturnListOfRecords_Test ( )
public void GetAllSalariesByMaster_ReturnListOfRecords_Test ( )
{
// Arrange
//Arrange
var startDate = DateTime . UtcNow ;
var endDate = DateTime . UtcNow . AddDays ( 1 ) ;
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
var listOriginal = new List < SalaryDataModel >
var listOriginal = new List < SalaryDataModel > ( )
{
new SalaryDataModel ( masterId , DateTime . UtcNow , 1000 , 20 0) ,
new SalaryDataModel ( masterId , DateTime . UtcNow . AddDays ( 1 ) , 1500 , 30 0)
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow , 10 , 1 0) ,
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( 1 ) , 14 , 1 0) ,
new ( Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddDays ( - 1 ) , 30 , 10 ) ,
} ;
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ) . Returns ( listOriginal ) ;
// Act
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) )
. Returns ( listOriginal ) ;
//Act
var list = _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( startDate , endDate , masterId ) ;
// Assert
//Assert
Assert . That ( list , Is . Not . Null ) ;
Assert . That ( list , Is . EquivalentTo ( listOriginal ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Once ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( startDate , endDate , masterId ) , Times . Once ) ;
}
[Test]
public void GetAllSalariesByPeriodBy Master_ReturnEmptyList_Test ( )
public void GetAllSalariesByMaster_ReturnEmptyList_Test ( )
{
// Arrange
var masterId = Guid . NewGuid ( ) . ToS tring( ) ;
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , masterId ) ) . Returns ( new List < SalaryDataModel > ( ) ) ;
// Act
var list = _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) , masterId ) ;
// Assert
//Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < s tring> () ) )
. Returns ( [ ] ) ;
//Act
var list = _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , Guid . NewGuid ( ) . ToString ( ) ) ;
//Assert
Assert . That ( list , Is . Not . Null ) ;
Assert . That ( list . Count, Is . EqualTo ( 0 ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , masterId ) , Times . Once ) ;
Assert . That ( list , Has .Count . EqualTo ( 0 ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void GetAllSalariesByPeriodByMaster_MasterIdIsNull _ThrowException_Test ( )
public void GetAllSalariesByMaster_IncorrectDates _ThrowException_Test ( )
{
// Act & Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) , null ) ,
Throws . TypeOf < ArgumentNullException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Never ) ;
//Arrange
var dateTime = DateTime . UtcNow ;
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( dateTime , dateTime ,
Guid . NewGuid ( ) . ToString ( ) ) , Throws . TypeOf < IncorrectDatesException > ( ) ) ;
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( dateTime , dateTime . AddSeconds ( - 1 ) ,
Guid . NewGuid ( ) . ToString ( ) ) , Throws . TypeOf < IncorrectDatesException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Never ) ;
}
[Test]
public void GetAllSalariesByPeriodBy Master_MasterIdIsEmpty_ThrowException_Test ( )
public void GetAllSalariesByMaster_MasterIdIsNUllOr Empty_ThrowException_Test ( )
{
// Act & Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow , DateTime . UtcNow . AddDays ( 1 ) , string . Empty ) ,
Throws . TypeOf < ArgumentNullException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) , Times . Never ) ;
//Act& Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , null ) , Throws . TypeOf < ArgumentNullException > ( ) ) ;
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , string . Empty ) , Throws . TypeOf < ArgumentNullException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Never ) ;
}
[Test]
public void CalculateSalaryByMonth_CalculateSalary _Test( )
public void GetAllSalariesByMaster_MasterIdIsNotGuid_ThrowException _Test( )
{
// Arrange
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , "masterId" ) , Throws . TypeOf < ValidationException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Never ) ;
}
[Test]
public void GetAllSalariesByMaster_ReturnNull_ThrowException_Test ( )
{
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , Guid . NewGuid ( ) . ToString ( ) ) , Throws . TypeOf < NullListException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void GetAllSalariesByMaster_StorageThrowError_ThrowException_Test ( )
{
//Arrange
_salaryStorageContract . Setup ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) )
. Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
//Act&Assert
Assert . That (
( ) = > _salaryBusinessLogicContract . GetAllSalariesByPeriodByMaster ( DateTime . UtcNow ,
DateTime . UtcNow . AddDays ( 1 ) , Guid . NewGuid ( ) . ToString ( ) ) , Throws . TypeOf < StorageException > ( ) ) ;
_salaryStorageContract . Verify ( x = > x . GetList ( It . IsAny < DateTime > ( ) , It . IsAny < DateTime > ( ) , It . IsAny < string > ( ) ) ,
Times . Once ) ;
}
[Test]
public void CalculateSalaryByMounth_CalculateSalary_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
var expectedSalary = 2000 .0 ;
var expectedPrize = 5 00.0;
var master = new MasterDataModel (
id : masterId ,
fio : "Иванов Иван Иванович" ,
postId : Guid . NewGui d( ) . ToS tring( ) ,
birthDate : DateTi me. Now . AddYears ( - 30 ) ,
employmentDate : DateTime . Now . AddYears ( - 5 ) ,
isDeleted : false
) ;
// Устанавливаем mock-поведение для метода GetList
_masterStorageContract . Setup ( x = > x . GetList ( true , It . IsAny < string > ( ) , null , null , null , null ) )
. Returns ( new List < MasterDataModel > { master } ) ;
// Act
var orderSum = 200.0 ;
var postSalary = 20 00.0;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_postStorageContract . Setup ( x = > x . GetElementByI d( It . IsAny < s tring> () ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "na me" , PostType . Plasterer , postSalary ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
var sum = 0.0 ;
var expectedSum = postSalary + 500 ;
_salaryStorageContract . Setup ( x = > x . AddElement ( It . IsAny < SalaryDataModel > ( ) ) )
. Callback ( ( SalaryDataModel x ) = > { sum = x . Salary ; } ) ;
//Act
_salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ;
// Assert
_salaryStorageContract . Verify ( x = > x . AddElement ( It . Is < SalaryDataModel > ( s = >
s . MasterId = = masterId & &
s . Salary = = expectedSalary & &
s . Prize = = expectedPrize ) ) , Times . Once ) ;
//Assert
Assert. That ( sum , Is . EqualTo ( expectedSum ) ) ;
}
[Test]
public void CalculateSalaryByMonth_MasterStorageThrowError_ThrowException _Test ( )
public void CalculateSalaryByMou nth_WithSeveralMasters _Test ( )
{
// Arrange
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) ) . Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
//Arrange
var master1Id = Guid . NewGuid ( ) . ToString ( ) ;
var master2Id = Guid . NewGuid ( ) . ToString ( ) ;
var master3Id = Guid . NewGuid ( ) . ToString ( ) ;
var list = new List < MasterDataModel > ( )
{
new MasterDataModel ( master1Id , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false ) ,
new MasterDataModel ( master2Id , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false ) ,
new MasterDataModel ( master3Id , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
} ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial ) ,
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial ) ,
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial ) ,
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial ) ,
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , 2000 ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( list ) ;
//Act
_salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ;
//Assert
_salaryStorageContract . Verify ( x = > x . AddElement ( It . IsAny < SalaryDataModel > ( ) ) , Times . Exactly ( list . Count ) ) ;
}
// Act & Assert
[Test]
public void CalculateSalaryByMounth_WithoitOrdersByMaster_Test ( )
{
//Arrange
var postSalary = 2000.0 ;
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [ ] ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , postSalary ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
var sum = 0.0 ;
var expectedSum = postSalary + 500 ;
_salaryStorageContract . Setup ( x = > x . AddElement ( It . IsAny < SalaryDataModel > ( ) ) )
. Callback ( ( SalaryDataModel x ) = > { sum = x . Salary ; } ) ;
//Act
_salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ;
//Assert
Assert . That ( sum , Is . EqualTo ( expectedSum ) ) ;
}
[Test]
public void CalculateSalaryByMounth_OrderStorageReturnNull_ThrowException_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , 2000 ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < NullListException > ( ) ) ;
}
[Test]
public void CalculateSalaryByMounth_PostStorageReturnNull_ThrowException_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < NullListException > ( ) ) ;
}
[Test]
public void CalculateSalaryByMounth_MasterStorageReturnNull_ThrowException_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , 2000 ) ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < NullListException > ( ) ) ;
}
[Test]
public void CalculateSalaryByMounth_OrderStorageThrowException_ThrowException_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , 2000 ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < StorageException > ( ) ) ;
_postStorageContract . Verify ( x = > x . GetElementById ( It . IsAny < string > ( ) ) , Times . Once ) ;
}
[Test]
public void CalculateSalaryByMonth_MasterDataInvalid_ThrowValidation Exception_Test ( )
public void CalculateSalaryByMou nth_PostStorageThrowException_Throw Exception_Test ( )
{
// Arrange
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
var master = new MasterDataModel (
id : masterId ,
fio : "Invalid FIO" , // Некорректное ФИО
postId : Guid . NewGuid ( ) . ToString ( ) ,
birthDate : DateTime . Now . AddYears ( - 30 ) ,
employmentDate : DateTime . Now . AddYears ( - 5 ) ,
isDeleted : false
);
_masterStorageContract . Setup ( x = > x . GetElementById ( masterId ) ) . Returns ( master ) ;
// Act & Assert
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Returns ( [
new MasterDataModel ( masterId , "А А А " , Guid . NewGuid ( ) . ToString ( ) , DateTime . UtcNow . AddYears ( - 19 ) , DateTime . UtcNow ,
false )
] ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < Validation Exception> ( ) ) ;
_masterStorageContract . Verify ( x = > x . GetElementById ( masterId ) , Times . Once ) ;
Throws . TypeOf < Storage Exception> ( ) ) ;
}
[Test]
public void CalculateSalaryByMounth_MasterStorageThrowException_ThrowException_Test ( )
{
//Arrange
var masterId = Guid . NewGuid ( ) . ToString ( ) ;
_orderStorageContract . Setup ( x = > x . GetList ( ) )
. Returns ( [
new OrderDataModel ( Guid . NewGuid ( ) . ToString ( ) , DateTime . Now , StatusType . Ready , RoomType . Industrial )
] ) ;
_postStorageContract . Setup ( x = > x . GetElementById ( It . IsAny < string > ( ) ) )
. Returns ( new PostDataModel ( Guid . NewGuid ( ) . ToString ( ) , "name" , PostType . Plasterer , 2000 ) ) ;
_masterStorageContract . Setup ( x = > x . GetList ( It . IsAny < bool > ( ) , It . IsAny < string? > ( ) , It . IsAny < DateTime ? > ( ) ,
It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) , It . IsAny < DateTime ? > ( ) ) )
. Throws ( new StorageException ( new InvalidOperationException ( ) ) ) ;
//Act&Assert
Assert . That ( ( ) = > _salaryBusinessLogicContract . CalculateSalaryByMonth ( DateTime . UtcNow ) ,
Throws . TypeOf < StorageException > ( ) ) ;
}
}