Skip to content

Commit

Permalink
Resolved all PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Alvarenga1 committed Feb 28, 2024
1 parent 81b8b44 commit 3fb82b5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 34 deletions.
16 changes: 10 additions & 6 deletions src/Blazor.Diagrams.Core/Models/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,16 @@ public override void SetPosition(double x, double y)
public void SetSize(double width, double height)
{
var newSize = new Size(width, height);
if (newSize.Equals(_size) == true || Size == null)
if (newSize.Equals(_size) == true)
return;
var oldSize = new Size(Size.Width, Size.Height);

Size? oldSize = Size != null ? new Size(Size.Width, Size.Height) : null;

Size = newSize;
UpdatePortPositions(oldSize, newSize);
if (oldSize != null)
{
UpdatePortPositions(oldSize, newSize);
}
Refresh();
RefreshLinks();
SizeChanging?.Invoke(this);
Expand Down Expand Up @@ -176,12 +180,12 @@ private void UpdatePortPositions(double deltaX, double deltaY)
/// </summary>
private void UpdatePortPositions(Size oldSize, Size newSize)
{
var deltaX = newSize.Width - oldSize.Width;
var deltaY = newSize.Height - oldSize.Height;
var deltaWidth = newSize.Width - oldSize.Width;
var deltaHeight = newSize.Height - oldSize.Height;

foreach (var port in _ports)
{
port.SetPortPositionOnNodeSizeChanged(deltaX, deltaY);
port.SetPortPositionOnNodeSizeChanged(deltaWidth, deltaHeight);
port.RefreshLinks();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="bunit" Version="1.4.15" />
<PackageReference Include="FluentAssertions" Version="5.10.3" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="xunit" Version="2.4.1" />
Expand All @@ -26,7 +25,6 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Blazor.Diagrams.Core\Blazor.Diagrams.Core.csproj" />
<ProjectReference Include="..\..\src\Blazor.Diagrams\Blazor.Diagrams.csproj" />
</ItemGroup>

</Project>
1 change: 0 additions & 1 deletion tests/Blazor.Diagrams.Core.Tests/Models/NodeModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Moq;
using Xunit;


namespace Blazor.Diagrams.Core.Tests.Models
{
public class NodeModelTest
Expand Down
50 changes: 25 additions & 25 deletions tests/Blazor.Diagrams.Core.Tests/Models/PortModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Blazor.Diagrams.Core.Tests.Models
public class PortModelTest
{
[Theory]
[InlineData(PortAlignment.Top)]
[InlineData(PortAlignment.TopLeft)]
[InlineData(PortAlignment.TopRight)]
[InlineData(PortAlignment.Bottom)]
[InlineData(PortAlignment.BottomLeft)]
[InlineData(PortAlignment.BottomRight)]
[InlineData(PortAlignment.Left)]
[InlineData(PortAlignment.Right)]
public void SetPortPositionOnNodeSizeChangedCalculatesCorrectPosition(PortAlignment alignment)
[InlineData(PortAlignment.Top, 50, 0)]
[InlineData(PortAlignment.TopLeft, 0, 0)]
[InlineData(PortAlignment.TopRight, 100, 0)]
[InlineData(PortAlignment.Bottom, 50, 100)]
[InlineData(PortAlignment.BottomLeft, 0, 100)]
[InlineData(PortAlignment.BottomRight, 100, 100)]
[InlineData(PortAlignment.Left, 0, 50)]
[InlineData(PortAlignment.Right, 100, 50)]
public void SetPortPositionOnNodeSizeChangedCalculatesCorrectPosition(PortAlignment alignment, double expectedXPosition, double expectedYPosition)
{
// Arrange
var node = new NodeModel();
Expand All @@ -29,36 +29,36 @@ public void SetPortPositionOnNodeSizeChangedCalculatesCorrectPosition(PortAlignm
switch (alignment)
{
case PortAlignment.Top:
Assert.Equal(50, port.Position.X);
Assert.Equal(0, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.TopRight:
Assert.Equal(100, port.Position.X);
Assert.Equal(0, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.TopLeft:
Assert.Equal(0, port.Position.X);
Assert.Equal(0, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.Right:
Assert.Equal(100, port.Position.X);
Assert.Equal(50, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.Left:
Assert.Equal(0, port.Position.X);
Assert.Equal(50, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.Bottom:
Assert.Equal(50, port.Position.X);
Assert.Equal(100, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.BottomRight:
Assert.Equal(100, port.Position.X);
Assert.Equal(100, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
case PortAlignment.BottomLeft:
Assert.Equal(0, port.Position.X);
Assert.Equal(100, port.Position.Y);
Assert.Equal(expectedXPosition, port.Position.X);
Assert.Equal(expectedYPosition, port.Position.Y);
break;
}
}
Expand Down

0 comments on commit 3fb82b5

Please sign in to comment.