mirror of https://github.com/SixLabors/ImageSharp
Browse Source
Former-commit-id: 5d53804087b6c10289b272881b77e4ca45b2e055 Former-commit-id: 0a4c7ab500246b11b97034706e166b380decf3ec Former-commit-id: 453702e4cd1ea1cde1479ef7a7a0a6187d64de90af/merge-core
4 changed files with 331 additions and 0 deletions
@ -0,0 +1,204 @@ |
|||
// <copyright file="GuardTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Tests.Helpers |
|||
{ |
|||
using System; |
|||
using System.Diagnostics.CodeAnalysis; |
|||
|
|||
using Xunit; |
|||
|
|||
/// <summary>
|
|||
/// Tests the <see cref="Guard"/> helper.
|
|||
/// </summary>
|
|||
public class GuardTests |
|||
{ |
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.NotNull"/> method throws when the argument is null.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void NotNullThrowsWhenArgIsNull() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => Guard.NotNull(null, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.NotNull"/> method throws when the argument name is empty.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void NotNullThrowsWhenArgNameEmpty() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => Guard.NotNull(null, string.Empty)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument is empty.
|
|||
/// </summary>
|
|||
[Fact] |
|||
[SuppressMessage("StyleCop.CSharp.ReadabilityRules", "SA1122:UseStringEmptyForEmptyStrings", Justification = "Reviewed. Suppression is OK here.")] |
|||
public void NotEmptyThrowsWhenEmpty() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => Guard.NotNullOrEmpty("", string.Empty)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument is whitespace.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void NotEmptyThrowsWhenWhitespace() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => Guard.NotNullOrEmpty(" ", string.Empty)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.NotEmpty"/> method throws when the argument name is null.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void NotEmptyThrowsWhenParameterNameNull() |
|||
{ |
|||
Assert.Throws<ArgumentNullException>(() => Guard.NotNullOrEmpty(null, null)); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void LessThanThrowsWhenArgIsGreater() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThan(1, 0, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is equal.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void LessThanThrowsWhenArgIsEqual() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThan(1, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method throws when the argument is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void LessThanOrEqualToThrowsWhenArgIsGreater() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeLessThanOrEqualTo(1, 0, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|||
/// is less.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void LessThanOrEqualToDoesNotThrowWhenArgIsLess() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(0, 1, "foo")); |
|||
Assert.Null(ex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|||
/// is equal.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void LessThanOrEqualToDoesNotThrowWhenArgIsEqual() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeLessThanOrEqualTo(1, 1, "foo")); |
|||
Assert.Equal(1, 1); |
|||
Assert.Null(ex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void GreaterThanThrowsWhenArgIsLess() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThan(0, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void GreaterThanThrowsWhenArgIsEqual() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThan(1, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThan"/> method throws when the argument name is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void GreaterThanOrEqualToThrowsWhenArgIsLess() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeGreaterThanOrEqualTo(0, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|||
/// is less.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void GreaterThanOrEqualToDoesNotThrowWhenArgIsGreater() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 0, "foo")); |
|||
Assert.Null(ex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeLessThanOrEqual"/> method does not throw when the argument
|
|||
/// is equal.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void GreaterThanOrEqualToDoesNotThrowWhenArgIsEqual() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeGreaterThanOrEqualTo(1, 1, "foo")); |
|||
Assert.Equal(1, 1); |
|||
Assert.Null(ex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method throws when the argument is less.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void BetweenOrEqualToThrowsWhenArgIsLess() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeBetweenOrEqualTo(-2, -1, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method throws when the argument is greater.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void BetweenOrEqualToThrowsWhenArgIsGreater() |
|||
{ |
|||
Assert.Throws<ArgumentOutOfRangeException>(() => Guard.MustBeBetweenOrEqualTo(2, -1, 1, "foo")); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method does not throw when the argument
|
|||
/// is equal.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void BetweenOrEqualToDoesNotThrowWhenArgIsEqual() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(1, 1, 1, "foo")); |
|||
Assert.Null(ex); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests that the <see cref="M:Guard.MustBeBetweenOrEqualTo"/> method does not throw when the argument
|
|||
/// is equal.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void BetweenOrEqualToDoesNotThrowWhenArgIsBetween() |
|||
{ |
|||
Exception ex = Record.Exception(() => Guard.MustBeBetweenOrEqualTo(0, -1, 1, "foo")); |
|||
Assert.Null(ex); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,11 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace ImageProcessor.Tests.Numerics |
|||
{ |
|||
public class Class |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,66 @@ |
|||
// <copyright file="RectangleTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Tests |
|||
{ |
|||
using Xunit; |
|||
|
|||
/// <summary>
|
|||
/// Tests the <see cref="Rectangle"/> struct.
|
|||
/// </summary>
|
|||
public class RectangleTests |
|||
{ |
|||
/// <summary>
|
|||
/// Tests the equality operators for equality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreEqual() |
|||
{ |
|||
Rectangle first = new Rectangle(1, 1, 100, 100); |
|||
Rectangle second = new Rectangle(1, 1, 100, 100); |
|||
|
|||
Assert.Equal(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests the equality operators for inequality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreNotEqual() |
|||
{ |
|||
Rectangle first = new Rectangle(1, 1, 0, 100); |
|||
Rectangle second = new Rectangle(1, 1, 100, 100); |
|||
|
|||
Assert.NotEqual(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests whether the rectangle constructors correctly assign properties.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void ConstructorAssignsProperties() |
|||
{ |
|||
Rectangle first = new Rectangle(1, 1, 50, 100); |
|||
Assert.Equal(1, first.X); |
|||
Assert.Equal(1, first.Y); |
|||
Assert.Equal(50, first.Width); |
|||
Assert.Equal(100, first.Height); |
|||
Assert.Equal(1, first.Top); |
|||
Assert.Equal(51, first.Right); |
|||
Assert.Equal(101, first.Bottom); |
|||
Assert.Equal(1, first.Left); |
|||
|
|||
Rectangle second = new Rectangle(new Point(1, 1), new Size(50, 100)); |
|||
Assert.Equal(1, second.X); |
|||
Assert.Equal(1, second.Y); |
|||
Assert.Equal(50, second.Width); |
|||
Assert.Equal(100, second.Height); |
|||
Assert.Equal(1, second.Top); |
|||
Assert.Equal(51, second.Right); |
|||
Assert.Equal(101, second.Bottom); |
|||
Assert.Equal(1, second.Left); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,50 @@ |
|||
// <copyright file="SizeTests.cs" company="James Jackson-South">
|
|||
// Copyright (c) James Jackson-South and contributors.
|
|||
// Licensed under the Apache License, Version 2.0.
|
|||
// </copyright>
|
|||
|
|||
namespace ImageProcessorCore.Tests |
|||
{ |
|||
using Xunit; |
|||
|
|||
/// <summary>
|
|||
/// Tests the <see cref="Size"/> struct.
|
|||
/// </summary>
|
|||
public class SizeTests |
|||
{ |
|||
/// <summary>
|
|||
/// Tests the equality operators for equality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreEqual() |
|||
{ |
|||
Size first = new Size(100, 100); |
|||
Size second = new Size(100, 100); |
|||
|
|||
Assert.Equal(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests the equality operators for inequality.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void AreNotEqual() |
|||
{ |
|||
Size first = new Size(0, 100); |
|||
Size second = new Size(100, 100); |
|||
|
|||
Assert.NotEqual(first, second); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Tests whether the size constructor correctly assign properties.
|
|||
/// </summary>
|
|||
[Fact] |
|||
public void ConstructorAssignsProperties() |
|||
{ |
|||
Size first = new Size(4, 5); |
|||
Assert.Equal(4, first.Width); |
|||
Assert.Equal(5, first.Height); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue