Skip to content

Commit

Permalink
use member data for tests to see if DAT test discovery will work
Browse files Browse the repository at this point in the history
  • Loading branch information
Heathermcx committed Jan 9, 2024
1 parent 6c27363 commit 35fc6fd
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 46 deletions.
43 changes: 27 additions & 16 deletions tests/Blazor.Diagrams.Core.Tests/Anchors/SinglePortAnchorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Blazor.Diagrams.Core.Models;
using FluentAssertions;
using Moq;
using System.Collections.Generic;
using Xunit;

namespace Blazor.Diagrams.Core.Tests.Anchors;
Expand Down Expand Up @@ -76,15 +77,20 @@ public void GetPosition_ShouldReturnMiddlePosition_WhenMiddleIfNoMarker()
position.Y.Should().Be(mp.Y);
}

public static IEnumerable<object[]> GetPosition_ShouldReturnAlignmentBasedPosition_WhenUseShapeAndAlignmentIsFalse_TestData()
{
yield return new object[] { PortAlignment.Top, 110, 50 };
yield return new object[] { PortAlignment.TopRight, 120, 50 };
yield return new object[] { PortAlignment.Right, 120, 55 };
yield return new object[] { PortAlignment.BottomRight, 120, 60 };
yield return new object[] { PortAlignment.Bottom, 110, 60 };
yield return new object[] { PortAlignment.BottomLeft, 100, 60 };
yield return new object[] { PortAlignment.Left, 100, 55 };
yield return new object[] { PortAlignment.TopLeft, 100, 50 };
}

[Theory(DisplayName = "GetPosition_ShouldReturnAlignmentBasedPosition_WhenUseShapeAndAlignmentIsFalse")]
[InlineData(PortAlignment.Top, 110, 50)]
[InlineData(PortAlignment.TopRight, 120, 50)]
[InlineData(PortAlignment.Right, 120, 55)]
[InlineData(PortAlignment.BottomRight, 120, 60)]
[InlineData(PortAlignment.Bottom, 110, 60)]
[InlineData(PortAlignment.BottomLeft, 100, 60)]
[InlineData(PortAlignment.Left, 100, 55)]
[InlineData(PortAlignment.TopLeft, 100, 50)]
[MemberData(nameof(GetPosition_ShouldReturnAlignmentBasedPosition_WhenUseShapeAndAlignmentIsFalse_TestData))]
public void GetPosition_ShouldReturnAlignmentBasedPosition_WhenUseShapeAndAlignmentIsFalse(PortAlignment alignment, double x, double y)
{
// Arrange
Expand All @@ -110,15 +116,20 @@ public void GetPosition_ShouldReturnAlignmentBasedPosition_WhenUseShapeAndAlignm
position.Y.Should().Be(y);
}

public static IEnumerable<object[]> GetPosition_ShouldUsePointAtAngle_WhenUseShapeAndAlignmentIsTrue_TestData()
{
yield return new object[] { PortAlignment.Top, 270 };
yield return new object[] { PortAlignment.TopRight, 315 };
yield return new object[] { PortAlignment.Right, 0 };
yield return new object[] { PortAlignment.BottomRight, 45 };
yield return new object[] { PortAlignment.Bottom, 90 };
yield return new object[] { PortAlignment.BottomLeft, 135 };
yield return new object[] { PortAlignment.Left, 180 };
yield return new object[] { PortAlignment.TopLeft, 225 };
}

[Theory(DisplayName = "GetPosition_ShouldUsePointAtAngle_WhenUseShapeAndAlignmentIsTrue")]
[InlineData(PortAlignment.Top, 270)]
[InlineData(PortAlignment.TopRight, 315)]
[InlineData(PortAlignment.Right, 0)]
[InlineData(PortAlignment.BottomRight, 45)]
[InlineData(PortAlignment.Bottom, 90)]
[InlineData(PortAlignment.BottomLeft, 135)]
[InlineData(PortAlignment.Left, 180)]
[InlineData(PortAlignment.TopLeft, 225)]
[MemberData(nameof(GetPosition_ShouldUsePointAtAngle_WhenUseShapeAndAlignmentIsTrue_TestData))]
public void GetPosition_ShouldUsePointAtAngle_WhenUseShapeAndAlignmentIsTrue(PortAlignment alignment, double angle)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Blazor.Diagrams.Core.Options;
using FluentAssertions;
using Moq;
using System.Collections.Generic;
using Xunit;

namespace Blazor.Diagrams.Core.Tests.Behaviors;
Expand All @@ -29,11 +30,16 @@ public void Behavior_ShouldCallSetPosition()
nodeMock.Verify(n => n.SetPosition(50, 50), Times.Once);
}

public static IEnumerable<object[]> Behavior_SnapToGrid_ShouldCallSetPosition_TestData()
{
yield return new object[] { false, 0, 0, 45, 45 };
yield return new object[] { true, 0, 0, 35, 35 };
yield return new object[] { false, 3, 3, 45, 45 };
yield return new object[] { true, 3, 3, 50, 50 };
}

[Theory(DisplayName = "Behavior_SnapToGrid_ShouldCallSetPosition")]
[InlineData(false, 0, 0, 45, 45)]
[InlineData(true, 0, 0, 35, 35)]
[InlineData(false, 3, 3, 45, 45)]
[InlineData(true, 3, 3, 50, 50)]
[MemberData(nameof(Behavior_SnapToGrid_ShouldCallSetPosition_TestData))]
public void Behavior_SnapToGrid_ShouldCallSetPosition(bool gridSnapToCenter, double initialX, double initialY, double deltaX, double deltaY)
{
// Arrange
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using Blazor.Diagrams.Core.Behaviors;
using Blazor.Diagrams.Core.Events;
using Blazor.Diagrams.Core.Models;
using FluentAssertions;
using System.Collections.Generic;
using System.Threading.Tasks;
using Xunit;

namespace Blazor.Diagrams.Core.Tests.Behaviors;

public class KeyboardShortcutsBehaviorTests
{
public static IEnumerable<object[]> Behavior_ShouldExecuteAction_WhenCombinationIsPressed_TestData()
{
yield return new object[] { "A", true, true, true };
yield return new object[] { "B", true, false, false};
yield return new object[] { "C", true, true, false};
yield return new object[] { "D", true, false, true};
yield return new object[] { "E", false, false, true};
yield return new object[] { "F", false, true, true};
yield return new object[] { "G", false, false, false};
}

[Theory(DisplayName = "Behavior_ShouldExecuteAction_WhenCombinationIsPressed")]
[InlineData("A", true, true, true)]
[InlineData("B", true, false, false)]
[InlineData("C", true, true, false)]
[InlineData("D", true, false, true)]
[InlineData("E", false, false, true)]
[InlineData("F", false, true, true)]
[InlineData("G", false, false, false)]
[MemberData(nameof(Behavior_ShouldExecuteAction_WhenCombinationIsPressed_TestData))]
public void Behavior_ShouldExecuteAction_WhenCombinationIsPressed(string key, bool ctrl, bool shift, bool alt)
{
// Arrange
Expand Down
25 changes: 17 additions & 8 deletions tests/Blazor.Diagrams.Core.Tests/DiagramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Blazor.Diagrams.Core.Models;
using FluentAssertions;
using System;
using System.Collections.Generic;
using Xunit;

namespace Blazor.Diagrams.Core.Tests;
Expand Down Expand Up @@ -93,30 +94,38 @@ public void ZoomToFit_ShouldTriggerAppropriateEvents()
panChanges.Should().Be(1);
}

public static IEnumerable<object[]> Zoom_ShoulClampToMinimumValue_TestData()
{
yield return new object[] { 0.001 };
yield return new object[] { 0.1 };
}

[Theory(DisplayName = "Zoom_ShoulClampToMinimumValue")]
[InlineData(0.001)]
[InlineData(0.1)]
[MemberData(nameof(Zoom_ShoulClampToMinimumValue_TestData))]
public void Zoom_ShoulClampToMinimumValue(double zoomValue)
{
var diagram = new TestDiagram();
diagram.SetZoom(zoomValue);
Assert.Equal(diagram.Zoom, diagram.Options.Zoom.Minimum);
}

public static IEnumerable<object[]> ThrowExceptionWhenLessThan0_TestData()
{
yield return new object[] { 0 };
yield return new object[] { -0.1 };
yield return new object[] { -0.00001 };
}

[Theory(DisplayName = "Zoom_ThrowExceptionWhenLessThan0")]
[InlineData(0)]
[InlineData(-0.1)]
[InlineData(-0.00001)]
[MemberData(nameof (ThrowExceptionWhenLessThan0_TestData))]
public void Zoom_ThrowExceptionWhenLessThan0(double zoomValue)
{
var diagram = new TestDiagram();
Assert.Throws<ArgumentException>(() => diagram.SetZoom(zoomValue));
}

[Theory(DisplayName = "ZoomOptions_ThrowExceptionWhenLessThan0")]
[InlineData(0)]
[InlineData(-0.1)]
[InlineData(-0.00001)]
[MemberData(nameof(ThrowExceptionWhenLessThan0_TestData))]
public void ZoomOptions_ThrowExceptionWhenLessThan0(double zoomValue)
{
var diagram = new TestDiagram();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
using Xunit;
using Blazor.Diagrams.Core.Extensions;
using Blazor.Diagrams.Core.Models;
using System.Collections.Generic;

namespace Blazor.Diagrams.Core.Tests.Extensions;

public class DoubleExtensionsTests
{
public static IEnumerable<object[]> AlmostEqualTo_TestData()
{
yield return new object[] { 5, 10, 0.1, false };
yield return new object[] { 1.1, 1.2, 0.01, false };
yield return new object[] { 10, 10, 0.0001, true };
yield return new object[] { 10.35, 10.35, 0.0001, true };
yield return new object[] { 1.659, 1.660, 0.0001, false };
yield return new object[] { 1.65999, 1.65998, 0.0001, true };
yield return new object[] { 1.65999, 1.6599998, 0.0001, true };
}

[Theory(DisplayName = "AlmostEqualTo")]
[InlineData(5, 10, 0.1, false)]
[InlineData(1.1, 1.2, 0.01, false)]
[InlineData(10, 10, 0.0001, true)]
[InlineData(10.35, 10.35, 0.0001, true)]
[InlineData(1.659, 1.660, 0.0001, false)]
[InlineData(1.65999, 1.65998, 0.0001, true)]
[InlineData(1.65999, 1.6599998, 0.0001, true)]
[MemberData(nameof(AlmostEqualTo_TestData))]
public void AlmostEqualTo(double num1, double num2, double tolerance, bool expected)
{
Assert.Equal(expected, num1.AlmostEqualTo(num2, tolerance));
Expand Down
15 changes: 11 additions & 4 deletions tests/Blazor.Diagrams.Core.Tests/Geometry/PointTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Core.Models;
using FluentAssertions;
using System.Collections.Generic;
using Xunit;

namespace Blazor.Diagrams.Core.Tests.Geometry;

public class PointTests
{
public static IEnumerable<object[]> DistanceTo_TestData()
{
yield return new object[] { 0, 0, 0, 0, 0 };
yield return new object[] { -7, -4, 17, 6.5, 26.196374 };
yield return new object[] { 5, 10, 33, 98, 92.347171 };
yield return new object[] { 5.5, 2.7, 6.5, 47.2, 44.511235 };
}

[Theory(DisplayName = "DistanceTo")]
[InlineData(0, 0, 0, 0, 0)]
[InlineData(-7, -4, 17, 6.5, 26.196374)]
[InlineData(5, 10, 33, 98, 92.347171)]
[InlineData(5.5, 2.7, 6.5, 47.2, 44.511235)]
[MemberData(nameof(DistanceTo_TestData))]
public void DistanceTo(double x1, double y1, double x2, double y2, double expected)
{
var pt1 = new Point(x1, y1);
Expand Down

0 comments on commit 35fc6fd

Please sign in to comment.