MouseHelperTests.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using Microsoft.VisualStudio.TestTools.UnitTesting; 6 using MouseJump.Common.Helpers; 7 using MouseJump.Common.Models.Drawing; 8 9 namespace MouseJump.Common.UnitTests.Helpers; 10 11 [TestClass] 12 public static class MouseHelperTests 13 { 14 [TestClass] 15 public sealed class GetJumpLocationTests 16 { 17 public sealed class TestCase 18 { 19 public TestCase(PointInfo previewLocation, SizeInfo previewSize, RectangleInfo desktopBounds, PointInfo expectedResult) 20 { 21 this.PreviewLocation = previewLocation; 22 this.PreviewSize = previewSize; 23 this.DesktopBounds = desktopBounds; 24 this.ExpectedResult = expectedResult; 25 } 26 27 public PointInfo PreviewLocation { get; } 28 29 public SizeInfo PreviewSize { get; } 30 31 public RectangleInfo DesktopBounds { get; } 32 33 public PointInfo ExpectedResult { get; } 34 } 35 36 public static IEnumerable<object[]> GetTestCases() 37 { 38 // screen corners and midpoint with a zero origin 39 yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(0, 0, 1600, 1200), new(0, 0)) }; 40 yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(0, 0, 1600, 1200), new(1600, 0)) }; 41 yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(0, 0, 1600, 1200), new(0, 1200)) }; 42 yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(0, 0, 1600, 1200), new(1600, 1200)) }; 43 yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(0, 0, 1600, 1200), new(800, 600)) }; 44 45 // screen corners and midpoint with a positive origin 46 yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(1000, 1000, 1600, 1200), new(1000, 1000)) }; 47 yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(1000, 1000, 1600, 1200), new(2600, 1000)) }; 48 yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(1000, 1000, 1600, 1200), new(1000, 2200)) }; 49 yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(1000, 1000, 1600, 1200), new(2600, 2200)) }; 50 yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(1000, 1000, 1600, 1200), new(1800, 1600)) }; 51 52 // screen corners and midpoint with a negative origin 53 yield return new object[] { new TestCase(new(0, 0), new(160, 120), new(-1000, -1000, 1600, 1200), new(-1000, -1000)) }; 54 yield return new object[] { new TestCase(new(160, 0), new(160, 120), new(-1000, -1000, 1600, 1200), new(600, -1000)) }; 55 yield return new object[] { new TestCase(new(0, 120), new(160, 120), new(-1000, -1000, 1600, 1200), new(-1000, 200)) }; 56 yield return new object[] { new TestCase(new(160, 120), new(160, 120), new(-1000, -1000, 1600, 1200), new(600, 200)) }; 57 yield return new object[] { new TestCase(new(80, 60), new(160, 120), new(-1000, -1000, 1600, 1200), new(-200, -400)) }; 58 } 59 60 [TestMethod] 61 [DynamicData(nameof(GetTestCases), DynamicDataSourceType.Method)] 62 public void RunTestCases(TestCase data) 63 { 64 var actual = MouseHelper.GetJumpLocation( 65 data.PreviewLocation, 66 data.PreviewSize, 67 data.DesktopBounds); 68 var expected = data.ExpectedResult; 69 Assert.AreEqual(expected.X, actual.X); 70 Assert.AreEqual(expected.Y, actual.Y); 71 } 72 } 73 }