Browse Source

[SL.Core] Added stylecop to the test project.

pull/1087/head
Dirk Lemstra 9 years ago
parent
commit
5ac709d889
  1. 24
      tests/SixLabors.Core.Tests/Primitives/PointFTests.cs
  2. 23
      tests/SixLabors.Core.Tests/Primitives/PointTests.cs
  3. 41
      tests/SixLabors.Core.Tests/Primitives/RectangleFTests.cs
  4. 33
      tests/SixLabors.Core.Tests/Primitives/RectangleTests.cs
  5. 22
      tests/SixLabors.Core.Tests/Primitives/SizeFTests.cs
  6. 22
      tests/SixLabors.Core.Tests/Primitives/SizeTests.cs
  7. 10
      tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj
  8. 10
      tests/SixLabors.ruleset

24
tests/SixLabors.Core.Tests/Primitives/PointFTests.cs

@ -1,22 +1,20 @@
// <copyright file="PointFTests.cs" company="Six Labors"> // 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.
// </copyright>
using System;
using System.Globalization;
using System.Numerics;
using System.Reflection;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System;
using System.Globalization;
using System.Numerics;
using System.Reflection;
using Xunit;
public class PointFTests public class PointFTests
{ {
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(PointF.Empty, new PointF()); Assert.Equal(PointF.Empty, default(PointF));
} }
[Theory] [Theory]
@ -37,7 +35,7 @@ namespace SixLabors.Primitives.Tests
public void IsEmptyDefaultsTest() public void IsEmptyDefaultsTest()
{ {
Assert.True(PointF.Empty.IsEmpty); Assert.True(PointF.Empty.IsEmpty);
Assert.True(new PointF().IsEmpty); Assert.True(default(PointF).IsEmpty);
Assert.True(new PointF(0, 0).IsEmpty); Assert.True(new PointF(0, 0).IsEmpty);
} }
@ -151,7 +149,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTest_NotPointF() public void EqualityTest_NotPointF()
{ {
var point = new PointF(0, 0); var point = new PointF(0, 0);
Assert.False(point.Equals(null)); Assert.False(point.Equals(null));
@ -167,7 +165,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var point = new PointF(10, 10); var point = new PointF(10, 10);
Assert.Equal(point.GetHashCode(), new PointF(10, 10).GetHashCode()); Assert.Equal(point.GetHashCode(), new PointF(10, 10).GetHashCode());

23
tests/SixLabors.Core.Tests/Primitives/PointTests.cs

@ -1,21 +1,18 @@
// <copyright file="PointTests.cs" company="Six Labors"> // 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.
// </copyright>
using System.Globalization;
using System.Numerics;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System.Globalization;
using System.Numerics;
using Xunit;
public class PointTests public class PointTests
{ {
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(Point.Empty, new Point()); Assert.Equal(Point.Empty, default(Point));
} }
[Theory] [Theory]
@ -47,7 +44,7 @@ namespace SixLabors.Primitives.Tests
public void IsEmptyDefaultsTest() public void IsEmptyDefaultsTest()
{ {
Assert.True(Point.Empty.IsEmpty); Assert.True(Point.Empty.IsEmpty);
Assert.True(new Point().IsEmpty); Assert.True(default(Point).IsEmpty);
Assert.True(new Point(0, 0).IsEmpty); Assert.True(new Point(0, 0).IsEmpty);
} }
@ -186,7 +183,7 @@ namespace SixLabors.Primitives.Tests
public void EqualityTest(int x, int y) public void EqualityTest(int x, int y)
{ {
var p1 = new Point(x, y); var p1 = new Point(x, y);
var p2 = new Point(x / 2 - 1, y / 2 - 1); var p2 = new Point((x / 2) - 1, (y / 2) - 1);
var p3 = new Point(x, y); var p3 = new Point(x, y);
Assert.True(p1 == p3); Assert.True(p1 == p3);
@ -205,7 +202,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTest_NotPoint() public void EqualityTest_NotPoint()
{ {
var point = new Point(0, 0); var point = new Point(0, 0);
Assert.False(point.Equals(null)); Assert.False(point.Equals(null));
@ -214,7 +211,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var point = new Point(10, 10); var point = new Point(10, 10);
Assert.Equal(point.GetHashCode(), new Point(10, 10).GetHashCode()); Assert.Equal(point.GetHashCode(), new Point(10, 10).GetHashCode());

41
tests/SixLabors.Core.Tests/Primitives/RectangleFTests.cs

@ -1,16 +1,13 @@
// <copyright file="RectangleFTests.cs" company="Six Labors"> // 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.
// </copyright>
using System;
using System.Globalization;
using System.Reflection;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System;
using System.Globalization;
using System.Reflection;
using Xunit;
/// <summary> /// <summary>
/// Tests the <see cref="RectangleF"/> struct. /// Tests the <see cref="RectangleF"/> struct.
/// </summary> /// </summary>
@ -19,7 +16,7 @@ namespace SixLabors.Primitives.Tests
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(RectangleF.Empty, new RectangleF()); Assert.Equal(RectangleF.Empty, default(RectangleF));
} }
[Theory] [Theory]
@ -77,7 +74,7 @@ namespace SixLabors.Primitives.Tests
public void IsEmptyTest() public void IsEmptyTest()
{ {
Assert.True(RectangleF.Empty.IsEmpty); Assert.True(RectangleF.Empty.IsEmpty);
Assert.True(new RectangleF().IsEmpty); Assert.True(default(RectangleF).IsEmpty);
Assert.True(new RectangleF(1, -2, -10, 10).IsEmpty); Assert.True(new RectangleF(1, -2, -10, 10).IsEmpty);
Assert.True(new RectangleF(1, -2, 10, -10).IsEmpty); Assert.True(new RectangleF(1, -2, 10, -10).IsEmpty);
Assert.True(new RectangleF(1, -2, 0, 0).IsEmpty); Assert.True(new RectangleF(1, -2, 0, 0).IsEmpty);
@ -88,7 +85,7 @@ namespace SixLabors.Primitives.Tests
[Theory] [Theory]
[InlineData(0, 0)] [InlineData(0, 0)]
[InlineData(float.MaxValue, float.MinValue)] [InlineData(float.MaxValue, float.MinValue)]
public static void LocationSetTest(float x, float y) public void LocationSetTest(float x, float y)
{ {
var point = new PointF(x, y); var point = new PointF(x, y);
var rect = new RectangleF(10, 10, 10, 10) { Location = point }; var rect = new RectangleF(10, 10, 10, 10) { Location = point };
@ -100,7 +97,7 @@ namespace SixLabors.Primitives.Tests
[Theory] [Theory]
[InlineData(0, 0)] [InlineData(0, 0)]
[InlineData(float.MaxValue, float.MinValue)] [InlineData(float.MaxValue, float.MinValue)]
public static void SizeSetTest(float x, float y) public void SizeSetTest(float x, float y)
{ {
var size = new SizeF(x, y); var size = new SizeF(x, y);
var rect = new RectangleF(10, 10, 10, 10) { Size = size }; var rect = new RectangleF(10, 10, 10, 10) { Size = size };
@ -125,7 +122,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTestNotRectangleF() public void EqualityTestNotRectangleF()
{ {
var rectangle = new RectangleF(0, 0, 0, 0); var rectangle = new RectangleF(0, 0, 0, 0);
Assert.False(rectangle.Equals(null)); Assert.False(rectangle.Equals(null));
@ -141,7 +138,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var rect1 = new RectangleF(10, 10, 10, 10); var rect1 = new RectangleF(10, 10, 10, 10);
var rect2 = new RectangleF(10, 10, 10, 10); var rect2 = new RectangleF(10, 10, 10, 10);
@ -158,12 +155,12 @@ namespace SixLabors.Primitives.Tests
public void ContainsTest(float x, float y, float width, float height) public void ContainsTest(float x, float y, float width, float height)
{ {
var rect = new RectangleF(x, y, width, height); var rect = new RectangleF(x, y, width, height);
float X = (x + width) / 2; float x1 = (x + width) / 2;
float Y = (y + height) / 2; float y1 = (y + height) / 2;
var p = new PointF(X, Y); var p = new PointF(x1, y1);
var r = new RectangleF(X, Y, width / 2, height / 2); var r = new RectangleF(x1, y1, width / 2, height / 2);
Assert.False(rect.Contains(X, Y)); Assert.False(rect.Contains(x1, y1));
Assert.False(rect.Contains(p)); Assert.False(rect.Contains(p));
Assert.False(rect.Contains(r)); Assert.False(rect.Contains(r));
} }
@ -175,7 +172,7 @@ namespace SixLabors.Primitives.Tests
public void InflateTest(float x, float y, float width, float height) public void InflateTest(float x, float y, float width, float height)
{ {
var rect = new RectangleF(x, y, width, height); var rect = new RectangleF(x, y, width, height);
var inflatedRect = new RectangleF(x - width, y - height, width + 2 * width, height + 2 * height); var inflatedRect = new RectangleF(x - width, y - height, width + (2 * width), height + (2 * height));
rect.Inflate(width, height); rect.Inflate(width, height);
Assert.Equal(inflatedRect, rect); Assert.Equal(inflatedRect, rect);
@ -201,7 +198,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void IntersectIntersectingRectsTest() public void IntersectIntersectingRectsTest()
{ {
var rect1 = new RectangleF(0, 0, 5, 5); var rect1 = new RectangleF(0, 0, 5, 5);
var rect2 = new RectangleF(1, 1, 3, 3); var rect2 = new RectangleF(1, 1, 3, 3);

33
tests/SixLabors.Core.Tests/Primitives/RectangleTests.cs

@ -1,15 +1,12 @@
// <copyright file="RectangleTests.cs" company="Six Labors"> // 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.
// </copyright>
using System;
using System.Globalization;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System;
using System.Globalization;
using Xunit;
/// <summary> /// <summary>
/// Tests the <see cref="Rectangle"/> struct. /// Tests the <see cref="Rectangle"/> struct.
/// </summary> /// </summary>
@ -18,7 +15,7 @@ namespace SixLabors.Primitives.Tests
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(Rectangle.Empty, new Rectangle()); Assert.Equal(Rectangle.Empty, default(Rectangle));
} }
[Theory] [Theory]
@ -51,8 +48,8 @@ namespace SixLabors.Primitives.Tests
public void EmptyTest() public void EmptyTest()
{ {
Assert.True(Rectangle.Empty.IsEmpty); Assert.True(Rectangle.Empty.IsEmpty);
Assert.True(default(Rectangle).IsEmpty);
Assert.True(new Rectangle(0, 0, 0, 0).IsEmpty); Assert.True(new Rectangle(0, 0, 0, 0).IsEmpty);
Assert.True(new Rectangle().IsEmpty);
} }
[Theory] [Theory]
@ -107,7 +104,7 @@ namespace SixLabors.Primitives.Tests
[Theory] [Theory]
[InlineData(0, 0)] [InlineData(0, 0)]
[InlineData(int.MaxValue, int.MinValue)] [InlineData(int.MaxValue, int.MinValue)]
public static void LocationSetTest(int x, int y) public void LocationSetTest(int x, int y)
{ {
var point = new Point(x, y); var point = new Point(x, y);
var rect = new Rectangle(10, 10, 10, 10) { Location = point }; var rect = new Rectangle(10, 10, 10, 10) { Location = point };
@ -119,7 +116,7 @@ namespace SixLabors.Primitives.Tests
[Theory] [Theory]
[InlineData(0, 0)] [InlineData(0, 0)]
[InlineData(int.MaxValue, int.MinValue)] [InlineData(int.MaxValue, int.MinValue)]
public static void SizeSetTest(int x, int y) public void SizeSetTest(int x, int y)
{ {
var size = new Size(x, y); var size = new Size(x, y);
var rect = new Rectangle(10, 10, 10, 10) { Size = size }; var rect = new Rectangle(10, 10, 10, 10) { Size = size };
@ -145,7 +142,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTestNotRectangle() public void EqualityTestNotRectangle()
{ {
var rectangle = new Rectangle(0, 0, 0, 0); var rectangle = new Rectangle(0, 0, 0, 0);
Assert.False(rectangle.Equals(null)); Assert.False(rectangle.Equals(null));
@ -154,7 +151,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var rect1 = new Rectangle(10, 10, 10, 10); var rect1 = new Rectangle(10, 10, 10, 10);
var rect2 = new Rectangle(10, 10, 10, 10); var rect2 = new Rectangle(10, 10, 10, 10);
@ -193,7 +190,7 @@ namespace SixLabors.Primitives.Tests
[InlineData(0, int.MinValue, int.MaxValue, 0)] [InlineData(0, int.MinValue, int.MaxValue, 0)]
public void ContainsTest(int x, int y, int width, int height) public void ContainsTest(int x, int y, int width, int height)
{ {
var rect = new Rectangle(unchecked(2 * x - width), unchecked(2 * y - height), width, height); var rect = new Rectangle(unchecked((2 * x) - width), unchecked((2 * y) - height), width, height);
var p = new Point(x, y); var p = new Point(x, y);
var r = new Rectangle(x, y, width / 2, height / 2); var r = new Rectangle(x, y, width / 2, height / 2);
@ -211,7 +208,7 @@ namespace SixLabors.Primitives.Tests
Rectangle inflatedRect, rect = new Rectangle(x, y, width, height); Rectangle inflatedRect, rect = new Rectangle(x, y, width, height);
unchecked unchecked
{ {
inflatedRect = new Rectangle(x - width, y - height, width + 2 * width, height + 2 * height); inflatedRect = new Rectangle(x - width, y - height, width + (2 * width), height + (2 * height));
} }
Assert.Equal(inflatedRect, Rectangle.Inflate(rect, width, height)); Assert.Equal(inflatedRect, Rectangle.Inflate(rect, width, height));
@ -222,7 +219,7 @@ namespace SixLabors.Primitives.Tests
var s = new Size(x, y); var s = new Size(x, y);
unchecked unchecked
{ {
inflatedRect = new Rectangle(rect.X - x, rect.Y - y, rect.Width + 2 * x, rect.Height + 2 * y); inflatedRect = new Rectangle(rect.X - x, rect.Y - y, rect.Width + (2 * x), rect.Height + (2 * y));
} }
rect.Inflate(s); rect.Inflate(s);
@ -243,7 +240,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void IntersectIntersectingRectsTest() public void IntersectIntersectingRectsTest()
{ {
var rect1 = new Rectangle(0, 0, 5, 5); var rect1 = new Rectangle(0, 0, 5, 5);
var rect2 = new Rectangle(1, 1, 3, 3); var rect2 = new Rectangle(1, 1, 3, 3);

22
tests/SixLabors.Core.Tests/Primitives/SizeFTests.cs

@ -1,21 +1,19 @@
// <copyright file="SizeTests.cs" company="Six Labors"> // 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.
// </copyright>
using System;
using System.Globalization;
using System.Reflection;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System;
using System.Globalization;
using System.Reflection;
using Xunit;
public class SizeFTests public class SizeFTests
{ {
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(SizeF.Empty, new SizeF()); Assert.Equal(SizeF.Empty, default(SizeF));
} }
[Theory] [Theory]
@ -47,7 +45,7 @@ namespace SixLabors.Primitives.Tests
public void IsEmptyDefaultsTest() public void IsEmptyDefaultsTest()
{ {
Assert.True(SizeF.Empty.IsEmpty); Assert.True(SizeF.Empty.IsEmpty);
Assert.True(new SizeF().IsEmpty); Assert.True(default(SizeF).IsEmpty);
Assert.True(new SizeF(0, 0).IsEmpty); Assert.True(new SizeF(0, 0).IsEmpty);
} }
@ -106,7 +104,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTest_NotSizeF() public void EqualityTest_NotSizeF()
{ {
var size = new SizeF(0, 0); var size = new SizeF(0, 0);
Assert.False(size.Equals(null)); Assert.False(size.Equals(null));
@ -122,7 +120,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var size = new SizeF(10, 10); var size = new SizeF(10, 10);
Assert.Equal(size.GetHashCode(), new SizeF(10, 10).GetHashCode()); Assert.Equal(size.GetHashCode(), new SizeF(10, 10).GetHashCode());

22
tests/SixLabors.Core.Tests/Primitives/SizeTests.cs

@ -1,14 +1,12 @@
// <copyright file="SizeTests.cs" company="Six Labors"> // 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.
// </copyright>
using System;
using System.Globalization;
using Xunit;
namespace SixLabors.Primitives.Tests namespace SixLabors.Primitives.Tests
{ {
using System;
using System.Globalization;
using Xunit;
/// <summary> /// <summary>
/// Tests the <see cref="Size"/> struct. /// Tests the <see cref="Size"/> struct.
/// </summary> /// </summary>
@ -17,7 +15,7 @@ namespace SixLabors.Primitives.Tests
[Fact] [Fact]
public void DefaultConstructorTest() public void DefaultConstructorTest()
{ {
Assert.Equal(Size.Empty, new Size()); Assert.Equal(Size.Empty, default(Size));
} }
[Theory] [Theory]
@ -43,7 +41,7 @@ namespace SixLabors.Primitives.Tests
public void IsEmptyDefaultsTest() public void IsEmptyDefaultsTest()
{ {
Assert.True(Size.Empty.IsEmpty); Assert.True(Size.Empty.IsEmpty);
Assert.True(new Size().IsEmpty); Assert.True(default(Size).IsEmpty);
Assert.True(new Size(0, 0).IsEmpty); Assert.True(new Size(0, 0).IsEmpty);
} }
@ -162,7 +160,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void EqualityTest_NotSize() public void EqualityTest_NotSize()
{ {
var size = new Size(0, 0); var size = new Size(0, 0);
Assert.False(size.Equals(null)); Assert.False(size.Equals(null));
@ -171,7 +169,7 @@ namespace SixLabors.Primitives.Tests
} }
[Fact] [Fact]
public static void GetHashCodeTest() public void GetHashCodeTest()
{ {
var size = new Size(10, 10); var size = new Size(10, 10);
Assert.Equal(size.GetHashCode(), new Size(10, 10).GetHashCode()); Assert.Equal(size.GetHashCode(), new Size(10, 10).GetHashCode());
@ -238,7 +236,6 @@ namespace SixLabors.Primitives.Tests
Assert.Equal(mulExpected, multiplier * sz1); Assert.Equal(mulExpected, multiplier * sz1);
} }
[Theory] [Theory]
[InlineData(1000, 0.0f)] [InlineData(1000, 0.0f)]
[InlineData(1000, 1.0f)] [InlineData(1000, 1.0f)]
@ -285,7 +282,6 @@ namespace SixLabors.Primitives.Tests
Assert.Equal(mulExpected, multiplier * sz1); Assert.Equal(mulExpected, multiplier * sz1);
} }
[Fact] [Fact]
public void DivideByZeroChecks() public void DivideByZeroChecks()
{ {

10
tests/SixLabors.Core.Tests/SixLabors.Core.Tests.csproj

@ -16,7 +16,17 @@
<RootNamespace>SixLabors.Tests</RootNamespace> <RootNamespace>SixLabors.Tests</RootNamespace>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<CodeAnalysisRuleSet>..\SixLabors.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<AdditionalFiles Include="..\..\stylecop.json" />
<Content Include="..\..\stylecop.json" Link="stylecop.json" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta004" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" /> <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" /> <PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
<PackageReference Include="xunit" Version="2.2.0" /> <PackageReference Include="xunit" Version="2.2.0" />

10
tests/SixLabors.ruleset

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<RuleSet Name="Shaper2D" ToolsVersion="14.0">
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA1413" Action="None" />
<!-- Test only ignores -->
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1117" Action="None" />
<Rule Id="SA1600" Action="None" />
</Rules>
</RuleSet>
Loading…
Cancel
Save