Пример #1
0
 /// <summary>
 /// Either the syntax node is invalid when parsing the literal or the syntax
 /// node value has an invalid format.
 /// </summary>
 public static SerializationException FieldSet_InvalidFormat(
     FieldSetType fieldSetType) =>
 new SerializationException(
     ErrorBuilder.New()
     .SetMessage(ThrowHelper_FieldSet_HasInvalidFormat)
     .SetCode(ErrorCodes.Scalars.InvalidSyntaxFormat)
     .Build(),
     fieldSetType);
Пример #2
0
        public void Ensure_Type_Name_Is_Correct()
        {
            // arrange
            // act
            var type = new FieldSetType();

            // assert
            Assert.Equal(WellKnownTypeNames.FieldSet, type.Name);
        }
Пример #3
0
        public void ParseValue_InvalidValue()
        {
            // arrange
            var type = new FieldSetType();

            // act
            void Action() => type.ParseValue(1);

            // assert
            Assert.Throws <SerializationException>(Action);
        }
Пример #4
0
        public void ParseValue_Null()
        {
            // arrange
            var type = new FieldSetType();

            // act
            IValueNode valueSyntax = type.ParseValue(null);

            // assert
            Assert.IsType <NullValueNode>(valueSyntax);
        }
Пример #5
0
        public void Serialize_Invalid_Format()
        {
            // arrange
            var type = new FieldSetType();

            // act
            void Action() => type.Serialize(1);

            // assert
            Assert.Throws <SerializationException>(Action);
        }
Пример #6
0
        public void TryDeserialize_Null()
        {
            // arrange
            var type = new FieldSetType();

            // act
            var success = type.TryDeserialize(null, out object?selectionSet);

            // assert
            Assert.True(success);
            Assert.Null(selectionSet);
        }
Пример #7
0
        public void Deserialize_Invalid_Format()
        {
            // arrange
            var          type       = new FieldSetType();
            const string serialized = "1";

            // act
            void Action() => type.Deserialize(serialized);

            // assert
            Assert.Throws <SerializationException>(Action);
        }
Пример #8
0
        public void Deserialize()
        {
            // arrange
            var          type       = new FieldSetType();
            const string serialized = "a b c d e(d: $b)";

            // act
            object?selectionSet = type.Deserialize(serialized);

            // assert
            Assert.IsType <SelectionSetNode>(selectionSet);
        }
Пример #9
0
        public void TrySerialize_Invalid_Format()
        {
            // arrange
            var type = new FieldSetType();

            // act
            var success = type.TrySerialize(1, out object?serialized);

            // assert
            Assert.False(success);
            Assert.Null(serialized);
        }
Пример #10
0
 /// <summary>
 /// The runtime type is not supported by the scalars ParseValue method.
 /// </summary>
 public static SerializationException FieldSet_CannotParseValue(
     FieldSetType fieldSetType,
     Type valueType) =>
 new SerializationException(
     ErrorBuilder.New()
     .SetMessage(
         ThrowHelper_FieldSet_CannotParseValue,
         fieldSetType.Name,
         valueType.FullName ?? valueType.Name)
     .SetCode(ErrorCodes.Scalars.InvalidRuntimeType)
     .Build(),
     fieldSetType);
Пример #11
0
        public void TryDeserialize_Invalid_Type()
        {
            // arrange
            var       type       = new FieldSetType();
            const int serialized = 1;

            // act
            var success = type.TryDeserialize(serialized, out object?selectionSet);

            // assert
            Assert.False(success);
            Assert.Null(selectionSet);
        }
Пример #12
0
        public void TryDeserialize()
        {
            // arrange
            var          type       = new FieldSetType();
            const string serialized = "a b c d e(d: $b)";

            // act
            var success = type.TryDeserialize(serialized, out object?selectionSet);

            // assert
            Assert.True(success);
            Assert.IsType <SelectionSetNode>(selectionSet);
        }
Пример #13
0
        public void Serialize()
        {
            // arrange
            var type = new FieldSetType();
            SelectionSetNode selectionSet =
                Utf8GraphQLParser.Syntax.ParseSelectionSet("{ a b c d e(d: $b) }");

            // act
            object?serialized = type.Serialize(selectionSet);

            // assert
            Assert.Equal("a b c d e(d: $b)", serialized);
        }
Пример #14
0
        public void ParseValue()
        {
            // arrange
            var type = new FieldSetType();
            SelectionSetNode selectionSet =
                Utf8GraphQLParser.Syntax.ParseSelectionSet("{ a b c d e(d: $b) }");

            // act
            IValueNode valueSyntax = type.ParseValue(selectionSet);

            // assert
            Assert.Equal(
                "a b c d e(d: $b)",
                Assert.IsType <StringValueNode>(valueSyntax).Value);
        }