|
1 | 1 | using ChilliCream.Testing; |
| 2 | +using Xunit.Sdk; |
2 | 3 | using static StrawberryShake.CodeGeneration.CSharp.GeneratorTestHelper; |
3 | 4 |
|
4 | 5 | namespace StrawberryShake.CodeGeneration.CSharp; |
@@ -95,6 +96,34 @@ public void Custom_Scalar_With_SerializationType_And_RuntimeType() => |
95 | 96 | @serializationType(name: ""global::System.Int32"")", |
96 | 97 | "extend schema @key(fields: \"id\")"); |
97 | 98 |
|
| 99 | + [Fact] |
| 100 | + public void Custom_Scalar_With_ValueType_RuntimeType() => |
| 101 | + AssertResult( |
| 102 | + "query GetId($modelId: ModelIdScalar!) { personId(id: $modelId) }", |
| 103 | + "type Query { personId(id: ModelIdScalar!): ModelIdScalar }", |
| 104 | + "scalar ModelIdScalar", |
| 105 | + @"extend scalar ModelIdScalar |
| 106 | + @runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"" valueType: true)"); |
| 107 | + |
| 108 | + [Fact] |
| 109 | + public void Custom_Scalar_With_ValueType_RuntimeType_Used_As_Nullable_Input() => |
| 110 | + AssertResult( |
| 111 | + "query GetId($modelId: ModelIdScalar) { personId(id: $modelId) }", |
| 112 | + "type Query { personId(id: ModelIdScalar): ModelIdScalar }", |
| 113 | + "scalar ModelIdScalar", |
| 114 | + @"extend scalar ModelIdScalar |
| 115 | + @runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"" valueType: true)"); |
| 116 | + |
| 117 | + [Fact] |
| 118 | + public void Custom_Scalar_With_ValueType_RuntimeType_Fails_If_ValueType_Not_Specified() => |
| 119 | + Assert.Throws<FailException>(() => |
| 120 | + AssertResult( |
| 121 | + "query GetId($modelId: ModelIdScalar!) { personId(id: $modelId) }", |
| 122 | + "type Query { personId(id: ModelIdScalar!): ModelIdScalar }", |
| 123 | + "scalar ModelIdScalar", |
| 124 | + @"extend scalar ModelIdScalar |
| 125 | + @runtimeType(name: ""global::StrawberryShake.CodeGeneration.CSharp.ModelId"")")); |
| 126 | + |
98 | 127 | [Fact] |
99 | 128 | public void Any_Scalar() => |
100 | 129 | AssertResult( |
@@ -187,3 +216,5 @@ public void Uri_Type() => |
187 | 216 | } |
188 | 217 |
|
189 | 218 | public class Custom; |
| 219 | + |
| 220 | +public record struct ModelId(long Id); |
0 commit comments