|
|
|
@ -21,14 +21,21 @@ namespace SixLabors.ImageSharp.Tests |
|
|
|
{ |
|
|
|
private readonly Image<Rgba32> image; |
|
|
|
private readonly FakeImageOperationsProvider provider; |
|
|
|
private readonly IImageProcessor<Rgba32> processor; |
|
|
|
private readonly IImageProcessor<Rgba32> processorImplementation; |
|
|
|
|
|
|
|
private readonly IImageProcessor processorDefinition; |
|
|
|
|
|
|
|
public Configuration Configuration { get; private set; } |
|
|
|
|
|
|
|
public ImageOperationTests() |
|
|
|
{ |
|
|
|
this.provider = new FakeImageOperationsProvider(); |
|
|
|
this.processor = new Mock<IImageProcessor<Rgba32>>().Object; |
|
|
|
this.processorImplementation = new Mock<IImageProcessor<Rgba32>>().Object; |
|
|
|
|
|
|
|
Mock<IImageProcessor> processorMock = new Mock<IImageProcessor>(); |
|
|
|
processorMock.Setup(p => p.CreatePixelSpecificProcessor<Rgba32>()).Returns(this.processorImplementation); |
|
|
|
this.processorDefinition = processorMock.Object; |
|
|
|
|
|
|
|
this.image = new Image<Rgba32>(new Configuration() |
|
|
|
{ |
|
|
|
ImageOperationsProvider = this.provider |
|
|
|
@ -38,61 +45,61 @@ namespace SixLabors.ImageSharp.Tests |
|
|
|
[Fact] |
|
|
|
public void MutateCallsImageOperationsProvider_Func_OriginalImage() |
|
|
|
{ |
|
|
|
this.image.Mutate(x => x.ApplyProcessor(this.processor)); |
|
|
|
this.image.Mutate(x => x.ApplyProcessor(this.processorDefinition)); |
|
|
|
|
|
|
|
Assert.True(this.provider.HasCreated(this.image)); |
|
|
|
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
Assert.Contains(this.processorImplementation, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void MutateCallsImageOperationsProvider_ListOfProcessors_OriginalImage() |
|
|
|
{ |
|
|
|
this.image.Mutate(this.processor); |
|
|
|
this.image.Mutate(this.processorDefinition); |
|
|
|
|
|
|
|
Assert.True(this.provider.HasCreated(this.image)); |
|
|
|
Assert.Contains(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
Assert.Contains(this.processorImplementation, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CloneCallsImageOperationsProvider_Func_WithDuplicateImage() |
|
|
|
{ |
|
|
|
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); |
|
|
|
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processorDefinition)); |
|
|
|
|
|
|
|
Assert.True(this.provider.HasCreated(returned)); |
|
|
|
Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor)); |
|
|
|
Assert.Contains(this.processorImplementation, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CloneCallsImageOperationsProvider_ListOfProcessors_WithDuplicateImage() |
|
|
|
{ |
|
|
|
Image<Rgba32> returned = this.image.Clone(this.processor); |
|
|
|
Image<Rgba32> returned = this.image.Clone(this.processorDefinition); |
|
|
|
|
|
|
|
Assert.True(this.provider.HasCreated(returned)); |
|
|
|
Assert.Contains(this.processor, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor)); |
|
|
|
Assert.Contains(this.processorImplementation, this.provider.AppliedOperations(returned).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CloneCallsImageOperationsProvider_Func_NotOnOrigional() |
|
|
|
{ |
|
|
|
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processor)); |
|
|
|
Image<Rgba32> returned = this.image.Clone(x => x.ApplyProcessor(this.processorDefinition)); |
|
|
|
Assert.False(this.provider.HasCreated(this.image)); |
|
|
|
Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
Assert.DoesNotContain(this.processorImplementation, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CloneCallsImageOperationsProvider_ListOfProcessors_NotOnOrigional() |
|
|
|
{ |
|
|
|
Image<Rgba32> returned = this.image.Clone(this.processor); |
|
|
|
Image<Rgba32> returned = this.image.Clone(this.processorDefinition); |
|
|
|
Assert.False(this.provider.HasCreated(this.image)); |
|
|
|
Assert.DoesNotContain(this.processor, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
Assert.DoesNotContain(this.processorImplementation, this.provider.AppliedOperations(this.image).Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void ApplyProcessors_ListOfProcessors_AppliesAllProcessorsToOperation() |
|
|
|
{ |
|
|
|
var operations = new FakeImageOperationsProvider.FakeImageOperations<Rgba32>(null, false); |
|
|
|
operations.ApplyProcessors(this.processor); |
|
|
|
Assert.Contains(this.processor, operations.Applied.Select(x => x.GenericProcessor)); |
|
|
|
operations.ApplyProcessors(this.processorDefinition); |
|
|
|
Assert.Contains(this.processorImplementation, operations.Applied.Select(x => x.GenericProcessor)); |
|
|
|
} |
|
|
|
|
|
|
|
public void Dispose() => this.image.Dispose(); |
|
|
|
|