forked from Blazor-Diagrams/Blazor.Diagrams
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DiagramTests.cs
95 lines (82 loc) · 2.78 KB
/
DiagramTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Blazor.Diagrams.Core.Geometry;
using Blazor.Diagrams.Core.Models;
using FluentAssertions;
using Xunit;
namespace Blazor.Diagrams.Core.Tests
{
public class DiagramTests
{
[Fact]
public void GetScreenPoint_ShouldReturnCorrectPoint()
{
// Arrange
var diagram = new Diagram();
// Act
diagram.SetZoom(1.234);
diagram.UpdatePan(50, 50);
diagram.SetContainer(new Rectangle(30, 65, 1000, 793));
var pt = diagram.GetScreenPoint(100, 200);
// Assert
pt.X.Should().Be(203.4); // 2*X + panX + left
pt.Y.Should().Be(361.8); // 2*Y + panY + top
}
[Fact]
public void ZoomToFit_ShouldUseSelectedNodesIfAny()
{
// Arrange
var diagram = new Diagram();
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768)));
diagram.Nodes.Add(new NodeModel(new Point(50, 50))
{
Size = new Size(100, 80)
});
diagram.SelectModel(diagram.Nodes[0], true);
// Act
diagram.ZoomToFit(10);
// Assert
diagram.Zoom.Should().BeApproximately(7.68, 0.001);
diagram.Pan.X.Should().Be(-307.2);
diagram.Pan.Y.Should().Be(-307.2);
}
[Fact]
public void ZoomToFit_ShouldUseNodesWhenNoneSelected()
{
// Arrange
var diagram = new Diagram();
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768)));
diagram.Nodes.Add(new NodeModel(new Point(50, 50))
{
Size = new Size(100, 80)
});
// Act
diagram.ZoomToFit(10);
// Assert
diagram.Zoom.Should().BeApproximately(7.68, 0.001);
diagram.Pan.X.Should().Be(-307.2);
diagram.Pan.Y.Should().Be(-307.2);
}
[Fact]
public void ZoomToFit_ShouldTriggerAppropriateEvents()
{
// Arrange
var diagram = new Diagram();
diagram.SetContainer(new Rectangle(new Point(0, 0), new Size(1080, 768)));
diagram.Nodes.Add(new NodeModel(new Point(50, 50))
{
Size = new Size(100, 80)
});
var refreshes = 0;
var zoomChanges = 0;
var panChanges = 0;
// Act
diagram.Changed += () => refreshes++;
diagram.ZoomChanged += () => zoomChanges++;
diagram.PanChanged += () => panChanges++;
diagram.ZoomToFit(10);
// Assert
refreshes.Should().Be(1);
zoomChanges.Should().Be(1);
panChanges.Should().Be(1);
}
}
}