コード例 #1
0
ファイル: ThrowHelper.cs プロジェクト: zaneclaes/hotchocolate
 /// <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
ファイル: ThrowHelper.cs プロジェクト: zaneclaes/hotchocolate
 /// <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);
        }