|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using NUnit.Framework; |
| 4 | + |
| 5 | +using Xamarin.MacDev; |
| 6 | +using Xamarin.MacDev.Tasks; |
| 7 | + |
| 8 | +namespace Xamarin.MacDev.Tasks { |
| 9 | + [TestFixture] |
| 10 | + public class GetPropertyListValueTaskTests : TestBase { |
| 11 | + |
| 12 | + void TestExecuteTask (string property, string expected) |
| 13 | + { |
| 14 | + var path = Path.Combine (Path.GetDirectoryName (GetType ().Assembly.Location)!, "Resources", "PropertyList.plist"); |
| 15 | + var task = CreateTask<GetPropertyListValue> (); |
| 16 | + task.PropertyListFile = path; |
| 17 | + task.Property = property; |
| 18 | + |
| 19 | + if (expected is null) { |
| 20 | + Assert.IsFalse (task.Execute (), "Task was expected to fail."); |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + Assert.IsTrue (task.Execute (), "Task was expected to execute successfully."); |
| 25 | + |
| 26 | + Assert.AreEqual (expected, task.Value, "Task produced the incorrect plist output."); |
| 27 | + } |
| 28 | + |
| 29 | + [Test] |
| 30 | + public void TestWithColonPrefix () |
| 31 | + { |
| 32 | + const string property = "KeyString"; |
| 33 | + const string expected = "MarLoe"; |
| 34 | + |
| 35 | + TestExecuteTask (":" + property, expected); |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + [Test] |
| 40 | + public void TestWithoutColonPrefix () |
| 41 | + { |
| 42 | + const string property = "KeyString"; |
| 43 | + const string expected = "MarLoe"; |
| 44 | + |
| 45 | + TestExecuteTask (property, expected); |
| 46 | + } |
| 47 | + |
| 48 | + [Test] |
| 49 | + public void TestReturnArrayNotSupported () |
| 50 | + { |
| 51 | + const string property = "KeyArray"; |
| 52 | + |
| 53 | + TestExecuteTask (property, null); |
| 54 | + } |
| 55 | + |
| 56 | + [Test] |
| 57 | + public void TestReturnDictionaryNotSupported () |
| 58 | + { |
| 59 | + const string property = "KeyDictionary"; |
| 60 | + |
| 61 | + TestExecuteTask (property, null); |
| 62 | + } |
| 63 | + |
| 64 | + [Test] |
| 65 | + public void TestReturnDataNotSupported () |
| 66 | + { |
| 67 | + const string property = "KeyData"; |
| 68 | + |
| 69 | + TestExecuteTask (property, null); |
| 70 | + } |
| 71 | + |
| 72 | + [Test] |
| 73 | + public void TestKeyNotFound () |
| 74 | + { |
| 75 | + const string property = "ThisKeyDoesNotExist"; |
| 76 | + |
| 77 | + TestExecuteTask (property, null); |
| 78 | + } |
| 79 | + |
| 80 | + [Test] |
| 81 | + public void TestGetStringProperty () |
| 82 | + { |
| 83 | + const string property = "KeyString"; |
| 84 | + const string expected = "MarLoe"; |
| 85 | + |
| 86 | + TestExecuteTask (property, expected); |
| 87 | + } |
| 88 | + |
| 89 | + [Test] |
| 90 | + public void TestGetIntegerProperty () |
| 91 | + { |
| 92 | + const string property = "KeyNumberInt"; |
| 93 | + const string expected = "1013"; |
| 94 | + |
| 95 | + TestExecuteTask (property, expected); |
| 96 | + } |
| 97 | + |
| 98 | + [Test] |
| 99 | + public void TestGetDoubleProperty () |
| 100 | + { |
| 101 | + const string property = "KeyNumberDouble"; |
| 102 | + const string expected = "10.13"; |
| 103 | + |
| 104 | + TestExecuteTask (property, expected); |
| 105 | + } |
| 106 | + |
| 107 | + [Test] |
| 108 | + public void TestGetBooleanTrueProperty () |
| 109 | + { |
| 110 | + const string property = "KeyBooleanTrue"; |
| 111 | + const string expected = "True"; |
| 112 | + |
| 113 | + TestExecuteTask (property, expected); |
| 114 | + } |
| 115 | + |
| 116 | + [Test] |
| 117 | + public void TestGetBooleanFalseProperty () |
| 118 | + { |
| 119 | + const string property = "KeyBooleanFalse"; |
| 120 | + const string expected = "False"; |
| 121 | + |
| 122 | + TestExecuteTask (property, expected); |
| 123 | + } |
| 124 | + |
| 125 | + [Test] |
| 126 | + public void TestGetDateProperty () |
| 127 | + { |
| 128 | + const string property = "KeyDate"; |
| 129 | + const string expected = "11/19/1974 10:20:30 AM"; |
| 130 | + |
| 131 | + TestExecuteTask (property, expected); |
| 132 | + } |
| 133 | + |
| 134 | + [Test] |
| 135 | + public void TestGetArrayIndexOutOfBounds () |
| 136 | + { |
| 137 | + var property = $"KeyArray:99"; |
| 138 | + |
| 139 | + TestExecuteTask (property, null); |
| 140 | + } |
| 141 | + |
| 142 | + [Test] |
| 143 | + [TestCase (0)] |
| 144 | + [TestCase (1)] |
| 145 | + [TestCase (2)] |
| 146 | + public void TestGetArrayIndexProperty (int index) |
| 147 | + { |
| 148 | + var property = $"KeyArray:{index}"; |
| 149 | + var expected = $"Array Item {index}"; |
| 150 | + |
| 151 | + TestExecuteTask (property, expected); |
| 152 | + } |
| 153 | + |
| 154 | + [Test] |
| 155 | + [TestCase (0)] |
| 156 | + [TestCase (1)] |
| 157 | + [TestCase (2)] |
| 158 | + public void TestGetArrayArrayIndexProperty (int index) |
| 159 | + { |
| 160 | + var property = $"KeyArray:3:{index}"; |
| 161 | + var expected = $"Array Array Item 3.{index}"; |
| 162 | + |
| 163 | + TestExecuteTask (property, expected); |
| 164 | + } |
| 165 | + |
| 166 | + [Test] |
| 167 | + [TestCase (0)] |
| 168 | + [TestCase (1)] |
| 169 | + [TestCase (2)] |
| 170 | + public void TestGetArrayDictionaryKeyProperty (int index) |
| 171 | + { |
| 172 | + var property = $"KeyArray:4:Item{index}"; |
| 173 | + var expected = $"Array Dictionary Item 4.{index}"; |
| 174 | + |
| 175 | + TestExecuteTask (property, expected); |
| 176 | + } |
| 177 | + |
| 178 | + [Test] |
| 179 | + public void TestGetDictionaryKeyNotFound () |
| 180 | + { |
| 181 | + var property = $"KeyDictionary:ItemKeyNotFound"; |
| 182 | + |
| 183 | + TestExecuteTask (property, null); |
| 184 | + } |
| 185 | + |
| 186 | + [Test] |
| 187 | + [TestCase (0)] |
| 188 | + [TestCase (1)] |
| 189 | + [TestCase (2)] |
| 190 | + public void TestGetDictionaryKeyProperty (int index) |
| 191 | + { |
| 192 | + var property = $"KeyDictionary:Item{index}"; |
| 193 | + var expected = $"Dictionary Item {index}"; |
| 194 | + |
| 195 | + TestExecuteTask (property, expected); |
| 196 | + } |
| 197 | + |
| 198 | + [Test] |
| 199 | + [TestCase (0)] |
| 200 | + [TestCase (1)] |
| 201 | + [TestCase (2)] |
| 202 | + public void TestGetDictionaryDictionaryKeyProperty (int index) |
| 203 | + { |
| 204 | + var property = $"KeyDictionary:Item3:Item{index}"; |
| 205 | + var expected = $"Dictionary Dictionary Item 3.{index}"; |
| 206 | + |
| 207 | + TestExecuteTask (property, expected); |
| 208 | + } |
| 209 | + |
| 210 | + [Test] |
| 211 | + [TestCase (0)] |
| 212 | + [TestCase (1)] |
| 213 | + [TestCase (2)] |
| 214 | + public void TestGetDictionaryArrayKeyProperty (int index) |
| 215 | + { |
| 216 | + var property = $"KeyDictionary:Item4:{index}"; |
| 217 | + var expected = $"Dictionary Array Item 4.{index}"; |
| 218 | + |
| 219 | + TestExecuteTask (property, expected); |
| 220 | + } |
| 221 | + |
| 222 | + } |
| 223 | +} |
0 commit comments