|
| 1 | +namespace Schema.NET.Test.TestData; |
| 2 | + |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Diagnostics.CodeAnalysis; |
| 6 | +using Xunit; |
| 7 | + |
| 8 | +[SuppressMessage("Style", "IDE0004:Remove Unnecessary Cast")] |
| 9 | +public class Values2ConstructorScenarios : TheoryData<Values2TestScenario> |
| 10 | +{ |
| 11 | + public Values2ConstructorScenarios() |
| 12 | + { |
| 13 | + this.Add(new Values2TestScenario( |
| 14 | + "OneOrMany<T1> with empty values", |
| 15 | + () => new Values<int, string>(new OneOrMany<int>()), |
| 16 | + [], |
| 17 | + false, |
| 18 | + false, |
| 19 | + 0, |
| 20 | + 0)); |
| 21 | + |
| 22 | + this.Add(new Values2TestScenario( |
| 23 | + "OneOrMany<T1> with single value", |
| 24 | + () => new Values<int, string>(new OneOrMany<int>(42)), |
| 25 | + [42], |
| 26 | + true, |
| 27 | + false, |
| 28 | + 1, |
| 29 | + 0)); |
| 30 | + |
| 31 | + this.Add(new Values2TestScenario( |
| 32 | + "OneOrMany<T1> with multiple values", |
| 33 | + () => new Values<int, string>(new OneOrMany<int>(1, 2, 3)), |
| 34 | + [1, 2, 3], |
| 35 | + true, |
| 36 | + false, |
| 37 | + 3, |
| 38 | + 0)); |
| 39 | + |
| 40 | + this.Add(new Values2TestScenario( |
| 41 | + "OneOrMany<T2> with empty values", |
| 42 | + () => new Values<int, string>(new OneOrMany<string>()), |
| 43 | + [], |
| 44 | + false, |
| 45 | + false, |
| 46 | + 0, |
| 47 | + 0)); |
| 48 | + |
| 49 | + this.Add(new Values2TestScenario( |
| 50 | + "OneOrMany<T2> with single value", |
| 51 | + () => new Values<int, string>(new OneOrMany<string>("hello")), |
| 52 | + ["hello"], |
| 53 | + false, |
| 54 | + true, |
| 55 | + 0, |
| 56 | + 1)); |
| 57 | + |
| 58 | + this.Add(new Values2TestScenario( |
| 59 | + "OneOrMany<T2> with multiple values", |
| 60 | + () => new Values<int, string>(new OneOrMany<string>("a", "b", "c")), |
| 61 | + ["a", "b", "c"], |
| 62 | + false, |
| 63 | + true, |
| 64 | + 0, |
| 65 | + 3)); |
| 66 | + |
| 67 | + this.Add(new Values2TestScenario( |
| 68 | + "IEnumerable<object> with empty collection", |
| 69 | + () => new Values<int, string>(new List<object?>()), |
| 70 | + [], |
| 71 | + false, |
| 72 | + false, |
| 73 | + 0, |
| 74 | + 0)); |
| 75 | + |
| 76 | + this.Add(new Values2TestScenario( |
| 77 | + "IEnumerable<object> with only T1 item", |
| 78 | + () => new Values<int, string>((IEnumerable<object?>)[10]), |
| 79 | + [10], |
| 80 | + true, |
| 81 | + false, |
| 82 | + 1, |
| 83 | + 0)); |
| 84 | + |
| 85 | + this.Add(new Values2TestScenario( |
| 86 | + "IEnumerable<object> with only T2 item", |
| 87 | + () => new Values<int, string>((IEnumerable<object?>)["x"]), |
| 88 | + ["x"], |
| 89 | + false, |
| 90 | + true, |
| 91 | + 0, |
| 92 | + 1)); |
| 93 | + |
| 94 | + this.Add(new Values2TestScenario( |
| 95 | + "IEnumerable<object> with mixed T1 and T2 items", |
| 96 | + () => new Values<int, string>((IEnumerable<object?>)[5, "test"]), |
| 97 | + [5, "test"], |
| 98 | + true, |
| 99 | + true, |
| 100 | + 1, |
| 101 | + 1)); |
| 102 | + |
| 103 | + this.Add(new Values2TestScenario( |
| 104 | + "IEnumerable<object> string values null and whitespace are removed", |
| 105 | + () => new Values<int, string>((IEnumerable<object?>)[string.Empty, null!, "\u2028 \u2029 \u0009 \u000A \u000B \u000C \u000D \u0085"]), |
| 106 | + [], |
| 107 | + false, |
| 108 | + false, |
| 109 | + 0, |
| 110 | + 0)); |
| 111 | + |
| 112 | + this.Add(new Values2TestScenario( |
| 113 | + "ReadOnlySpan<object> with no arguments (empty)", |
| 114 | + () => new Values<int, string>(ReadOnlySpan<object>.Empty), |
| 115 | + [], |
| 116 | + false, |
| 117 | + false, |
| 118 | + 0, |
| 119 | + 0)); |
| 120 | + |
| 121 | + this.Add(new Values2TestScenario( |
| 122 | + "ReadOnlySpan<object> with T1 item", |
| 123 | + () => new Values<int, string>((ReadOnlySpan<object>)[999]), |
| 124 | + [999], |
| 125 | + true, |
| 126 | + false, |
| 127 | + 1, |
| 128 | + 0)); |
| 129 | + |
| 130 | + this.Add(new Values2TestScenario( |
| 131 | + "ReadOnlySpan<object> with T2 item", |
| 132 | + () => new Values<int, string>((ReadOnlySpan<object>)["single"]), |
| 133 | + ["single"], |
| 134 | + false, |
| 135 | + true, |
| 136 | + 0, |
| 137 | + 1)); |
| 138 | + |
| 139 | + this.Add(new Values2TestScenario( |
| 140 | + "ReadOnlySpan<object> with mixed T1 and T2 items", |
| 141 | + () => new Values<int, string>((ReadOnlySpan<object>)[123, "mixed"]), |
| 142 | + [123, "mixed"], |
| 143 | + true, |
| 144 | + true, |
| 145 | + 1, |
| 146 | + 1)); |
| 147 | + |
| 148 | + this.Add(new Values2TestScenario( |
| 149 | + "ReadOnlySpan<object> string values null and whitespace are removed", |
| 150 | + () => new Values<int, string>((ReadOnlySpan<object>)[string.Empty, null!, "\u2028 \u2029 \u0009 \u000A \u000B \u000C \u000D \u0085"]), |
| 151 | + [], |
| 152 | + false, |
| 153 | + false, |
| 154 | + 0, |
| 155 | + 0)); |
| 156 | + |
| 157 | + this.Add(new Values2TestScenario( |
| 158 | + "Collection expression with no arguments (empty)", |
| 159 | + () => [], |
| 160 | + [], |
| 161 | + false, |
| 162 | + false, |
| 163 | + 0, |
| 164 | + 0)); |
| 165 | + |
| 166 | + this.Add(new Values2TestScenario( |
| 167 | + "Collection expression with T1 item", |
| 168 | + () => [42], |
| 169 | + [42], |
| 170 | + true, |
| 171 | + false, |
| 172 | + 1, |
| 173 | + 0)); |
| 174 | + |
| 175 | + this.Add(new Values2TestScenario( |
| 176 | + "Collection expression with T2 item", |
| 177 | + () => ["hello"], |
| 178 | + ["hello"], |
| 179 | + false, |
| 180 | + true, |
| 181 | + 0, |
| 182 | + 1)); |
| 183 | + |
| 184 | + this.Add(new Values2TestScenario( |
| 185 | + "Collection expression with mixed items (T1, T2)", |
| 186 | + () => [99, "single"], |
| 187 | + [99, "single"], |
| 188 | + true, |
| 189 | + true, |
| 190 | + 1, |
| 191 | + 1)); |
| 192 | + } |
| 193 | +} |
| 194 | + |
| 195 | +public record Values2TestScenario( |
| 196 | + string Name, |
| 197 | + Func<Values<int, string>> ConstructorCall, |
| 198 | + IReadOnlyCollection<object> ExpectedValues, |
| 199 | + bool ExpectedHasValue1, |
| 200 | + bool ExpectedHasValue2, |
| 201 | + int ExpectedCountValue1, |
| 202 | + int ExpectedCountValue2) |
| 203 | +{ |
| 204 | + public override string ToString() => this.Name; |
| 205 | +} |
0 commit comments