@ -21,6 +21,8 @@ namespace SixLabors.ImageSharp.Tests.Processing
private readonly Mock < IImageProcessor > processorDefinition ;
private readonly Mock < IImageProcessor > processorDefinition ;
private readonly Mock < CloningImageProcessor > cloningProcessorDefinition ;
private readonly Mock < IImageProcessor < Rgba32 > > regularProcessorImpl ;
private readonly Mock < IImageProcessor < Rgba32 > > regularProcessorImpl ;
private readonly Mock < ICloningImageProcessor < Rgba32 > > cloningProcessorImpl ;
private readonly Mock < ICloningImageProcessor < Rgba32 > > cloningProcessorImpl ;
@ -30,18 +32,20 @@ namespace SixLabors.ImageSharp.Tests.Processing
public ImageProcessingContextTests ( )
public ImageProcessingContextTests ( )
{
{
this . processorDefinition = new Mock < IImageProcessor > ( ) ;
this . processorDefinition = new Mock < IImageProcessor > ( ) ;
this . cloningProcessorDefinition = new Mock < CloningImageProcessor > ( ) ;
this . regularProcessorImpl = new Mock < IImageProcessor < Rgba32 > > ( ) ;
this . regularProcessorImpl = new Mock < IImageProcessor < Rgba32 > > ( ) ;
this . cloningProcessorImpl = new Mock < ICloningImageProcessor < Rgba32 > > ( ) ;
this . cloningProcessorImpl = new Mock < ICloningImageProcessor < Rgba32 > > ( ) ;
}
}
// bool throwException, bool useBounds
// bool throwException, bool useBounds
public static readonly TheoryData < bool , bool > ProcessorTestData = new TheoryData < bool , bool > ( )
public static readonly TheoryData < bool , bool > ProcessorTestData = new TheoryData < bool , bool > ( )
{
{
{ false , false } ,
{ false , false } ,
{ false , true } ,
{ false , true } ,
{ true , false } ,
{ true , false } ,
{ true , true }
{ true , true }
} ;
} ;
[Theory]
[Theory]
[MemberData(nameof(ProcessorTestData))]
[MemberData(nameof(ProcessorTestData))]
public void Mutate_RegularProcessor ( bool throwException , bool useBounds )
public void Mutate_RegularProcessor ( bool throwException , bool useBounds )
@ -57,7 +61,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
this . MutateApply ( useBounds ) ;
this . MutateApply ( useBounds ) ;
}
}
this . regularProcessorImpl . Verify ( p = > p . Apply ( ) , Times . Once ( ) ) ;
this . regularProcessorImpl . Verify ( p = > p . Execute ( ) , Times . Once ( ) ) ;
this . regularProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
this . regularProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
}
}
@ -69,16 +73,15 @@ namespace SixLabors.ImageSharp.Tests.Processing
if ( throwException )
if ( throwException )
{
{
Assert . Throws < ImageProcessingException > ( ( ) = > this . CloneApply ( useBounds ) ) ;
Assert . Throws < ImageProcessingException > ( ( ) = > this . CloneRegular Apply ( useBounds ) ) ;
}
}
else
else
{
{
this . CloneApply ( useBounds ) ;
this . CloneRegular Apply ( useBounds ) ;
}
}
// TODO: This should be Times.Once(). See comments in DefaultImageProcessingContext<T>.ApplyProcessor()
this . regularProcessorImpl . Verify ( p = > p . Execute ( ) , Times . Once ) ;
this . regularProcessorImpl . Verify ( p = > p . Apply ( ) , Times . AtLeast ( 1 ) ) ;
this . regularProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ) ;
this . regularProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . AtLeast ( 1 ) ) ;
}
}
[Theory]
[Theory]
@ -96,7 +99,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
this . MutateApply ( useBounds ) ;
this . MutateApply ( useBounds ) ;
}
}
this . cloningProcessorImpl . Verify ( p = > p . Apply ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . Execute ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
}
}
@ -108,14 +111,14 @@ namespace SixLabors.ImageSharp.Tests.Processing
if ( throwException )
if ( throwException )
{
{
Assert . Throws < ImageProcessingException > ( ( ) = > this . CloneApply ( useBounds ) ) ;
Assert . Throws < ImageProcessingException > ( ( ) = > this . CloneClone Apply ( useBounds ) ) ;
}
}
else
else
{
{
this . CloneApply ( useBounds ) ;
this . CloneClone Apply ( useBounds ) ;
}
}
this . cloningProcessorImpl . Verify ( p = > p . CloneAndApply ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . CloneAndExecute ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
this . cloningProcessorImpl . Verify ( p = > p . Dispose ( ) , Times . Once ( ) ) ;
}
}
@ -131,7 +134,7 @@ namespace SixLabors.ImageSharp.Tests.Processing
}
}
}
}
private void CloneApply ( bool useBounds )
private void CloneRegular Apply ( bool useBounds )
{
{
if ( useBounds )
if ( useBounds )
{
{
@ -143,11 +146,23 @@ namespace SixLabors.ImageSharp.Tests.Processing
}
}
}
}
private void CloneCloneApply ( bool useBounds )
{
if ( useBounds )
{
this . image . Clone ( c = > c . ApplyProcessor ( this . cloningProcessorDefinition . Object , Bounds ) ) . Dispose ( ) ;
}
else
{
this . image . Clone ( c = > c . ApplyProcessor ( this . cloningProcessorDefinition . Object ) ) . Dispose ( ) ;
}
}
private void SetupRegularProcessor ( bool throwsException )
private void SetupRegularProcessor ( bool throwsException )
{
{
if ( throwsException )
if ( throwsException )
{
{
this . regularProcessorImpl . Setup ( p = > p . Apply ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
this . regularProcessorImpl . Setup ( p = > p . Execute ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
}
}
this . processorDefinition
this . processorDefinition
@ -159,13 +174,17 @@ namespace SixLabors.ImageSharp.Tests.Processing
{
{
if ( throwsException )
if ( throwsException )
{
{
this . cloningProcessorImpl . Setup ( p = > p . Apply ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
this . cloningProcessorImpl . Setup ( p = > p . Execute ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
this . cloningProcessorImpl . Setup ( p = > p . CloneAndApply ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
this . cloningProcessorImpl . Setup ( p = > p . CloneAndExecute ( ) ) . Throws ( new ImageProcessingException ( "Test" ) ) ;
}
}
this . processorDefinition
this . processorDefinition
. Setup ( p = > p . CreatePixelSpecificProcessor ( It . IsAny < Image < Rgba32 > > ( ) , It . IsAny < Rectangle > ( ) ) )
. Setup ( p = > p . CreatePixelSpecificProcessor ( It . IsAny < Image < Rgba32 > > ( ) , It . IsAny < Rectangle > ( ) ) )
. Returns ( this . cloningProcessorImpl . Object ) ;
. Returns ( this . cloningProcessorImpl . Object ) ;
this . cloningProcessorDefinition
. Setup ( p = > p . CreatePixelSpecificProcessor ( It . IsAny < Image < Rgba32 > > ( ) , It . IsAny < Rectangle > ( ) ) )
. Returns ( this . cloningProcessorImpl . Object ) ;
}
}
}
}
}
}