Browse Source

changed test to ensure proper encoders/decoders are set

af/merge-core
Vicente Penades 8 years ago
parent
commit
dad8b1bed5
  1. 222
      tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

222
tests/ImageSharp.Tests/Formats/ImageFormatManagerTests.cs

@ -1,117 +1,129 @@
// Copyright (c) Six Labors and contributors. // Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0. // Licensed under the Apache License, Version 2.0.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using SixLabors.ImageSharp.Formats; using SixLabors.ImageSharp.Formats;
using SixLabors.ImageSharp.IO; using SixLabors.ImageSharp.IO;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using Moq; using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.Formats.Bmp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Formats.Gif;
using Moq;
using Xunit; using Xunit;
namespace SixLabors.ImageSharp.Tests namespace SixLabors.ImageSharp.Tests
{ {
public class ImageFormatManagerTests public class ImageFormatManagerTests
{ {
public ImageFormatManager FormatsManagerEmpty { get; private set; } public ImageFormatManager FormatsManagerEmpty { get; private set; }
public ImageFormatManager DefaultFormatsManager { get; private set; } public ImageFormatManager DefaultFormatsManager { get; private set; }
public ImageFormatManagerTests() public ImageFormatManagerTests()
{ {
this.DefaultFormatsManager = Configuration.Default.ImageFormatsManager; this.DefaultFormatsManager = Configuration.Default.ImageFormatsManager;
this.FormatsManagerEmpty = new ImageFormatManager(); this.FormatsManagerEmpty = new ImageFormatManager();
} }
[Fact] [Fact]
public void IfAutoloadWellKnownFormatsIsTrueAllFormatsAreLoaded() public void IfAutoloadWellKnownFormatsIsTrueAllFormatsAreLoaded()
{ {
Assert.Equal(4, this.DefaultFormatsManager.ImageEncoders.Count()); Assert.Equal(1, this.DefaultFormatsManager.ImageEncoders.Select(item => item.Value).OfType<PngEncoder>().Count());
Assert.Equal(4, this.DefaultFormatsManager.ImageDecoders.Count()); Assert.Equal(1, this.DefaultFormatsManager.ImageEncoders.Select(item => item.Value).OfType<BmpEncoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageEncoders.Select(item => item.Value).OfType<JpegEncoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageEncoders.Select(item => item.Value).OfType<GifEncoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageDecoders.Select(item => item.Value).OfType<PngDecoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageDecoders.Select(item => item.Value).OfType<BmpDecoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageDecoders.Select(item => item.Value).OfType<JpegDecoder>().Count());
Assert.Equal(1, this.DefaultFormatsManager.ImageDecoders.Select(item => item.Value).OfType<BmpDecoder>().Count());
}
[Fact]
public void AddImageFormatDetectorNullthrows()
{
Assert.Throws<ArgumentNullException>(() =>
{
this.DefaultFormatsManager.AddImageFormatDetector(null);
});
} }
[Fact] [Fact]
public void AddImageFormatDetectorNullthrows() public void RegisterNullMimeTypeEncoder()
{ {
Assert.Throws<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
this.DefaultFormatsManager.AddImageFormatDetector(null); this.DefaultFormatsManager.SetEncoder(null, new Mock<IImageEncoder>().Object);
}); });
} Assert.Throws<ArgumentNullException>(() =>
[Fact]
public void RegisterNullMimeTypeEncoder()
{
Assert.Throws<ArgumentNullException>(() =>
{ {
this.DefaultFormatsManager.SetEncoder(null, new Mock<IImageEncoder>().Object); this.DefaultFormatsManager.SetEncoder(ImageFormats.Bmp, null);
}); });
Assert.Throws<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
this.DefaultFormatsManager.SetEncoder(ImageFormats.Bmp, null); this.DefaultFormatsManager.SetEncoder(null, null);
}); });
Assert.Throws<ArgumentNullException>(() => }
{
this.DefaultFormatsManager.SetEncoder(null, null); [Fact]
}); public void RegisterNullSetDecoder()
} {
Assert.Throws<ArgumentNullException>(() =>
[Fact] {
public void RegisterNullSetDecoder() this.DefaultFormatsManager.SetDecoder(null, new Mock<IImageDecoder>().Object);
{ });
Assert.Throws<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
this.DefaultFormatsManager.SetDecoder(null, new Mock<IImageDecoder>().Object); this.DefaultFormatsManager.SetDecoder(ImageFormats.Bmp, null);
}); });
Assert.Throws<ArgumentNullException>(() => Assert.Throws<ArgumentNullException>(() =>
{ {
this.DefaultFormatsManager.SetDecoder(ImageFormats.Bmp, null); this.DefaultFormatsManager.SetDecoder(null, null);
}); });
Assert.Throws<ArgumentNullException>(() => }
{
this.DefaultFormatsManager.SetDecoder(null, null); [Fact]
}); public void RegisterMimeTypeEncoderReplacesLast()
} {
IImageEncoder encoder1 = new Mock<IImageEncoder>().Object;
[Fact] this.FormatsManagerEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder1);
public void RegisterMimeTypeEncoderReplacesLast() IImageEncoder found = this.FormatsManagerEmpty.FindEncoder(TestFormat.GlobalTestFormat);
{ Assert.Equal(encoder1, found);
IImageEncoder encoder1 = new Mock<IImageEncoder>().Object;
this.FormatsManagerEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder1); IImageEncoder encoder2 = new Mock<IImageEncoder>().Object;
IImageEncoder found = this.FormatsManagerEmpty.FindEncoder(TestFormat.GlobalTestFormat); this.FormatsManagerEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder2);
Assert.Equal(encoder1, found); IImageEncoder found2 = this.FormatsManagerEmpty.FindEncoder(TestFormat.GlobalTestFormat);
Assert.Equal(encoder2, found2);
IImageEncoder encoder2 = new Mock<IImageEncoder>().Object; Assert.NotEqual(found, found2);
this.FormatsManagerEmpty.SetEncoder(TestFormat.GlobalTestFormat, encoder2); }
IImageEncoder found2 = this.FormatsManagerEmpty.FindEncoder(TestFormat.GlobalTestFormat);
Assert.Equal(encoder2, found2); [Fact]
Assert.NotEqual(found, found2); public void RegisterMimeTypeDecoderReplacesLast()
} {
IImageDecoder decoder1 = new Mock<IImageDecoder>().Object;
[Fact] this.FormatsManagerEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder1);
public void RegisterMimeTypeDecoderReplacesLast() IImageDecoder found = this.FormatsManagerEmpty.FindDecoder(TestFormat.GlobalTestFormat);
{ Assert.Equal(decoder1, found);
IImageDecoder decoder1 = new Mock<IImageDecoder>().Object;
this.FormatsManagerEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder1); IImageDecoder decoder2 = new Mock<IImageDecoder>().Object;
IImageDecoder found = this.FormatsManagerEmpty.FindDecoder(TestFormat.GlobalTestFormat); this.FormatsManagerEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder2);
Assert.Equal(decoder1, found); IImageDecoder found2 = this.FormatsManagerEmpty.FindDecoder(TestFormat.GlobalTestFormat);
Assert.Equal(decoder2, found2);
IImageDecoder decoder2 = new Mock<IImageDecoder>().Object; Assert.NotEqual(found, found2);
this.FormatsManagerEmpty.SetDecoder(TestFormat.GlobalTestFormat, decoder2); }
IImageDecoder found2 = this.FormatsManagerEmpty.FindDecoder(TestFormat.GlobalTestFormat);
Assert.Equal(decoder2, found2); [Fact]
Assert.NotEqual(found, found2); public void AddFormatCallsConfig()
} {
var provider = new Mock<IConfigurationModule>();
[Fact] var config = new Configuration();
public void AddFormatCallsConfig() config.Configure(provider.Object);
{
var provider = new Mock<IConfigurationModule>(); provider.Verify(x => x.Configure(config));
var config = new Configuration();
config.Configure(provider.Object);
provider.Verify(x => x.Configure(config));
} }
} }
} }

Loading…
Cancel
Save