Example #1
0
        public void SerializeSchemaWriter_SchemaIsNull_ArgumentNullException()
        {
            // arrange
            // act
            void Action() => SchemaSerializer.Serialize(null, new StringWriter());

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
Example #2
0
        public void SerializeAsync_SchemaIsNull_ArgumentNullException()
        {
            // arrange
            // act
            async Task Action() => await SchemaSerializer.SerializeAsync(null, new MemoryStream());

            // assert
            Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
Example #3
0
        public void Serialize_SchemaIsNull_ArgumentNullException()
        {
            // arrange
            // act
            void Action() => SchemaSerializer.Serialize(null);

            // assert
            Assert.Throws <ArgumentNullException>(Action);
        }
Example #4
0
        public void SerializeAsync_WriterIsNull_ArgumentNullException()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo: String }")
                             .AddResolver("Query", "foo", "bar")
                             .Create();

            // act
            async Task Action() => await SchemaSerializer.SerializeAsync(schema, null);

            // assert
            Assert.ThrowsAsync <ArgumentNullException>(Action);
        }
Example #5
0
        public void SerializeSchemaWriter_Serialize()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo: String }")
                             .AddResolver("Query", "foo", "bar")
                             .Create();
            var stringBuilder = new StringBuilder();

            // act
            SchemaSerializer.Serialize(schema, new StringWriter(stringBuilder));

            // assert
            stringBuilder.ToString().MatchSnapshot();
        }
        public void SerializeSchemaWriter_WriterIsNull_ArgumentNullException()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString(
                "type Query { foo: String }")
                             .AddResolver("Query", "foo", "bar")
                             .Create();

            // act
            Action action = () => SchemaSerializer.Serialize(schema, null);

            // assert
            Assert.Throws <ArgumentNullException>(action);
        }
Example #7
0
        public async Task SerializeAsync_Serialize()
        {
            // arrange
            ISchema schema = SchemaBuilder.New()
                             .AddDocumentFromString("type Query { foo: String }")
                             .AddResolver("Query", "foo", "bar")
                             .Create();

            using var stream = new MemoryStream();

            // act
            await SchemaSerializer.SerializeAsync(schema, stream);

            // assert
            Encoding.UTF8.GetString(stream.ToArray()).MatchSnapshot();
        }
Example #8
0
        public void SerializeSchemaWithMutationWithoutSubscription()
        {
            // arrange
            string source = FileResource.Open(
                "serialize_schema_with_mutation.graphql");
            ISchema schema = Schema.Create(
                source,
                c =>
            {
                c.Use(next => context => next(context));
            });

            var sb = new StringBuilder();
            var s  = new StringWriter(sb);

            // act
            SchemaSerializer.Serialize(schema, s);

            // assert
            sb.ToString().Snapshot();
        }
Example #9
0
        public void SerializeSchemaWithDirective()
        {
            // arrange
            string  source = FileResource.Open("serialize_schema.graphql");
            ISchema schema = Schema.Create(
                source,
                c =>
            {
                c.Use(next => context => next(context));
                c.RegisterDirective(new DirectiveType(t =>
                                                      t.Name("upper")
                                                      .Location(DirectiveLocation.FieldDefinition)));
            });

            var sb = new StringBuilder();
            var s  = new StringWriter(sb);

            // act
            SchemaSerializer.Serialize(schema, s);

            // assert
            sb.ToString().Snapshot();
        }
Example #10
0
 public string Print() => SchemaSerializer.Serialize(this);
Example #11
0
 public DocumentNode ToDocument(bool includeSpecScalars = false) =>
 SchemaSerializer.SerializeSchema(this, includeSpecScalars);
Example #12
0
 public override string ToString()
 {
     return(SchemaSerializer.Serialize(this));
 }