public void OverwriteDefaultValueLiteralWithNativeDefaultValue() { // arrange InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor( typeof(Field).GetProperty("Arguments")); // act ((IInputFieldDescriptor)inputFieldDescriptor) .DefaultValue(new StringValueNode("123")) .DefaultValue("string"); // assert Assert.Null(inputFieldDescriptor.DefaultValue); Assert.Equal("string", inputFieldDescriptor.NativeDefaultValue); }
public void OverwriteName2() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor.Name("args"); // assert InputFieldDefinition description = descriptor.CreateDefinition(); Assert.Equal("args", description.Name); }
public void OverwriteName2() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .Name("args"); // assert InputFieldDescription description = descriptor.CreateDescription(); Assert.Equal("args", description.Name); }
public void OverwriteName() { // arrange var descriptor = InputFieldDescriptor.New( Context, "field1234"); // act descriptor.Name("args"); // assert InputFieldDefinition description = descriptor.CreateDefinition(); Assert.Equal("args", description.Name); }
public void SchemaTypesOverwriteDotNetTypes() { // arrange InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor( typeof(Field).GetProperty("Arguments")); // act ((IInputFieldDescriptor)inputFieldDescriptor) .Type <NativeType <IReadOnlyDictionary <string, string> > >() .Type <ListType <StringType> >(); // assert TypeReference typeRef = inputFieldDescriptor.TypeReference; Assert.Equal(typeof(ListType <StringType>), typeRef.NativeType); }
public void SetSchemaType() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .Type(new StringType()); // assert InputFieldDescription description = descriptor.CreateDescription(); TypeReference typeRef = description.TypeReference; Assert.IsType <StringType>(typeRef.SchemaType); }
public void SettingTheNativeDefaultValueToNullCreatesNullLiteral() { // arrange InputFieldDescriptor inputFieldDescriptor = new InputFieldDescriptor( typeof(Field).GetProperty("Arguments")); // act ((IInputFieldDescriptor)inputFieldDescriptor) .DefaultValue(new StringValueNode("123")) .DefaultValue("string") .DefaultValue(null); // assert Assert.IsType <NullValueNode>(inputFieldDescriptor.DefaultValue); Assert.Null(inputFieldDescriptor.NativeDefaultValue); }
public void SetDescription() { // arrange string expectedDescription = Guid.NewGuid().ToString(); var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor.Description(expectedDescription); // assert InputFieldDefinition description = descriptor.CreateDefinition(); Assert.Equal(expectedDescription, description.Description); }
public void SetDefaultValueAndInferType() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .DefaultValue("string"); // assert InputFieldDescription description = descriptor.CreateDescription(); Assert.Equal(typeof(string), description.TypeReference.ClrType); Assert.Equal("string", description.NativeDefaultValue); }
public void SetSchemaType() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor.Type(new StringType()); // assert InputFieldDefinition description = descriptor.CreateDefinition(); ITypeReference typeRef = description.Type; Assert.IsType <StringType>( Assert.IsType <SchemaTypeReference>(typeRef).Type); }
public void SetDefaultValueAndInferType() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor.DefaultValue("string"); // assert InputFieldDefinition description = descriptor.CreateDefinition(); Assert.Equal(typeof(string), Assert.IsType <ClrTypeReference>(description.Type).Type); Assert.Equal("string", description.NativeDefaultValue); }
public void OverwriteDefaultValueLiteralWithNativeDefaultValue() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .DefaultValue(new StringValueNode("123")) .DefaultValue("string"); // asser InputFieldDescription description = descriptor.CreateDescription(); Assert.Null(description.DefaultValue); Assert.Equal("string", description.NativeDefaultValue); }
public void SchemaTypesOverwriteDotNetTypes() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .Type <NativeType <IReadOnlyDictionary <string, string> > >() .Type <ListType <StringType> >(); // assert InputFieldDescription description = descriptor.CreateDescription(); TypeReference typeRef = description.TypeReference; Assert.Equal(typeof(ListType <StringType>), typeRef.ClrType); }
public void SetNonGenericType() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor.Type(typeof(StringType)); // assert InputFieldDefinition description = descriptor.CreateDefinition(); ITypeReference typeRef = description.Type; Assert.Equal( typeof(StringType), Assert.IsType <ClrTypeReference>(typeRef).Type); }
public void SettingTheNativeDefaultValueToNullCreatesNullLiteral() { // arrange var descriptor = new InputFieldDescriptor( typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .DefaultValue(new StringValueNode("123")) .DefaultValue("string") .DefaultValue(null); // assert InputFieldDescription description = descriptor.CreateDescription(); Assert.IsType <NullValueNode>(description.DefaultValue); Assert.Null(description.NativeDefaultValue); }
public void SchemaTypesOverwriteDotNetTypes() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act descriptor .Type <NativeType <IReadOnlyDictionary <string, string> > >() .Type <ListType <StringType> >(); // assert InputFieldDefinition description = descriptor.CreateDefinition(); ITypeReference typeRef = description.Type; Assert.Equal(typeof(ListType <StringType>), Assert.IsType <ClrTypeReference>(typeRef).Type); }
public void OverwriteNativeDefaultValueWithDefaultValueLiteral() { // arrange var descriptor = InputFieldDescriptor.New( Context, typeof(ObjectField).GetProperty("Arguments")); // act ((IInputFieldDescriptor)descriptor) .DefaultValue("string") .DefaultValue(new StringValueNode("123")); // assert InputFieldDefinition description = descriptor.CreateDefinition(); Assert.IsType <StringValueNode>(description.DefaultValue); Assert.Equal("123", ((StringValueNode)description.DefaultValue).Value); Assert.Null(description.NativeDefaultValue); }
protected InputFieldDescriptor Field(string name) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException( "The name cannot be null or empty.", nameof(name)); } if (!ValidationHelper.IsFieldNameValid(name)) { throw new ArgumentException( "The specified name is not a valid GraphQL field name.", nameof(name)); } var field = new InputFieldDescriptor(name); Fields.Add(field); return(field); }
internal InputField(InputFieldDescriptor descriptor) { if (descriptor == null) { throw new ArgumentNullException(nameof(descriptor)); } if (string.IsNullOrEmpty(descriptor.Name)) { throw new ArgumentException( "An input value name must not be null or empty.", nameof(descriptor)); } _typeReference = descriptor.TypeReference; _nativeDefaultValue = descriptor.NativeDefaultValue; SyntaxNode = descriptor.SyntaxNode; Name = descriptor.Name; Description = descriptor.Description; DefaultValue = descriptor.DefaultValue; Property = descriptor.Property; }
public void Type_Syntax_Type_Null() { void Error() => InputFieldDescriptor.New(Context, "foo").Type((string)null); Assert.Throws <ArgumentNullException>(Error); }