mirror of https://github.com/SixLabors/ImageSharp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
151 lines
5.0 KiB
151 lines
5.0 KiB
// <copyright file="BootstrapperTests.cs" company="James Jackson-South">
|
|
// Copyright (c) James Jackson-South and contributors.
|
|
// Licensed under the Apache License, Version 2.0.
|
|
// </copyright>
|
|
|
|
namespace ImageSharp.Tests
|
|
{
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using ImageSharp.Formats;
|
|
using Xunit;
|
|
using System.Linq;
|
|
|
|
public class BootstrapperTests
|
|
{
|
|
private class TestFormat : IImageFormat
|
|
{
|
|
private IImageDecoder decoder;
|
|
private IImageEncoder encoder;
|
|
private string mimeType;
|
|
private string extension;
|
|
private IEnumerable<string> supportedExtensions;
|
|
|
|
public TestFormat()
|
|
{
|
|
this.decoder = new JpegDecoder();
|
|
this.encoder = new JpegEncoder();
|
|
this.extension = "jpg";
|
|
this.mimeType = "image/test";
|
|
this.supportedExtensions = new string[] { "jpg" };
|
|
}
|
|
|
|
public IImageDecoder Decoder { get { return this.decoder; } set { this.decoder = value; } }
|
|
|
|
public IImageEncoder Encoder { get { return this.encoder; } set { this.encoder = value; } }
|
|
|
|
public string MimeType { get { return this.mimeType; } set { this.mimeType = value; } }
|
|
|
|
public string Extension { get { return this.extension; } set { this.extension = value; } }
|
|
|
|
public IEnumerable<string> SupportedExtensions { get { return this.supportedExtensions; } set { this.supportedExtensions = value; } }
|
|
|
|
public int HeaderSize { get { throw new NotImplementedException(); } }
|
|
|
|
public bool IsSupportedFileFormat(byte[] header) { throw new NotImplementedException(); }
|
|
}
|
|
|
|
[Fact]
|
|
public void AddImageFormatGuardNull()
|
|
{
|
|
ArgumentException exception;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(null);
|
|
});
|
|
|
|
var format = new TestFormat();
|
|
format.Decoder = null;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("decoder", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.Encoder = null;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("encoder", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.MimeType = null;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("mime type", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.MimeType = "";
|
|
|
|
exception = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("mime type", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.Extension = null;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("extension", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.Extension = "";
|
|
|
|
exception = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("extension", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.SupportedExtensions = null;
|
|
|
|
exception = Assert.Throws<ArgumentNullException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("supported extensions", exception.Message);
|
|
|
|
format = new TestFormat();
|
|
format.SupportedExtensions = Enumerable.Empty<string>();
|
|
|
|
exception = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("supported extensions", exception.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddImageFormatChecks()
|
|
{
|
|
TestFormat format = new TestFormat();
|
|
|
|
format.Extension = "test";
|
|
var exception = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("should contain", exception.Message);
|
|
|
|
format.SupportedExtensions = new string[] { "test", "" };
|
|
exception = Assert.Throws<ArgumentException>(() =>
|
|
{
|
|
Bootstrapper.Default.AddImageFormat(format);
|
|
});
|
|
Assert.Contains("empty values", exception.Message);
|
|
}
|
|
}
|
|
}
|
|
|