GridLayoutModelTests.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 FancyZonesEditor.Models; 6 7 namespace UnitTestsFancyZonesEditor; 8 9 [TestClass] 10 public class GridLayoutModelTests 11 { 12 [TestMethod] 13 public void EmptyGridLayoutModelIsNotValid() 14 { 15 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 16 Assert.IsFalse(gridLayoutModel.IsModelValid()); 17 } 18 19 [TestMethod] 20 public void GridLayoutModelWithInvalidRowAndColumnCountsIsNotValid() 21 { 22 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 23 gridLayoutModel.Rows = 0; 24 gridLayoutModel.Columns = 0; 25 Assert.IsFalse(gridLayoutModel.IsModelValid()); 26 } 27 28 [TestMethod] 29 public void GridLayoutModelWithInvalidRowPercentsIsNotValid() 30 { 31 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 32 gridLayoutModel.Rows = 1; 33 gridLayoutModel.Columns = 1; 34 gridLayoutModel.RowPercents = new List<int> { 0 }; // Invalid percentage 35 Assert.IsFalse(gridLayoutModel.IsModelValid()); 36 } 37 38 [TestMethod] 39 public void GridLayoutModelWithInvalidColumnPercentsIsNotValid() 40 { 41 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 42 gridLayoutModel.Rows = 1; 43 gridLayoutModel.Columns = 1; 44 gridLayoutModel.ColumnPercents = new List<int> { 0 }; // Invalid percentage 45 Assert.IsFalse(gridLayoutModel.IsModelValid()); 46 } 47 48 [TestMethod] 49 public void GridLayoutModelWithInvalidCellChildMapLengthIsNotValid() 50 { 51 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 52 gridLayoutModel.Rows = 2; 53 gridLayoutModel.Columns = 2; 54 gridLayoutModel.CellChildMap = new int[2, 1]; // Invalid length 55 Assert.IsFalse(gridLayoutModel.IsModelValid()); 56 } 57 58 [TestMethod] 59 public void GridLayoutModelWithInvalidZoneCountIsNotValid() 60 { 61 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 62 gridLayoutModel.Rows = 2; 63 gridLayoutModel.Columns = 2; 64 gridLayoutModel.CellChildMap = new int[,] 65 { 66 { 1, 2 }, 67 { 3, 4 }, 68 }; // Invalid zone count 69 Assert.IsFalse(gridLayoutModel.IsModelValid()); 70 } 71 72 [TestMethod] 73 public void GridLayoutModelWithValidPropertiesIsValid() 74 { 75 GridLayoutModel gridLayoutModel = new GridLayoutModel(); 76 77 // Set valid row and column counts 78 gridLayoutModel.Rows = 2; 79 gridLayoutModel.Columns = 2; 80 81 // Set valid percentages for rows and columns 82 // Should add up to 10000 83 gridLayoutModel.RowPercents = new List<int> { 5000, 5000 }; 84 gridLayoutModel.ColumnPercents = new List<int> { 5000, 5000 }; 85 86 // Set a valid CellChildMap 87 gridLayoutModel.CellChildMap = new int[,] 88 { 89 { 0, 1 }, 90 { 2, 3 }, 91 }; // corresponds to 4 zones 92 93 Assert.IsTrue(gridLayoutModel.IsModelValid(), "GridLayoutModel with valid properties should be valid."); 94 } 95 }