Ejemplo n.º 1
0
        public async Task ShouldRecieveErrorAboutTwoClassesWithSameName()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/ClientOnlyDirectives/QueryDuplicatedType.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();

            var error = Assert.Single(generator.Document.Errors);
        }
Ejemplo n.º 2
0
        public async Task TypeNamesShouldBeUnique()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/Issue_8/Quote.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();

            var model = generator.Model;

            var resultType = Assert.Single(model.Types.Where(x => x.Name == "QuoteResult"));
        }
Ejemplo n.º 3
0
        public async Task TypeDirectiveCanChangeExportedTypeName()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/ClientOnlyDirectives/Query.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();

            Assert.Empty(generator.Document.Errors);

            Assert.Single(generator.Model.Types.Select(x => x.Name), "TestResultABCD");
        }
Ejemplo n.º 4
0
        public async Task ShouldExportNullableField_Gitub()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/Issue_9/QueryGithub.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();
            generator.Render();

            var code = generator.GeneratedCode;

            Assert.Contains("int? DatabaseId { get; ", code);
            Assert.Contains("DateTime CreatedAt { get; ", code);
        }
Ejemplo n.º 5
0
        public async Task NullableFielsShouldGenerateNullableMetadata_Gitub()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/Issue_9/QueryGithub.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();

            var model = generator.Model;

            var droidType = Assert.Single(model.Types.Where(x => x.Name == "RepositoryResult"));

            var databaseIdField = Assert.Single(droidType.Fields.Where(x => x.Name == "databaseId"));
            var createdAtField  = Assert.Single(droidType.Fields.Where(x => x.Name == "createdAt"));

            Assert.True(databaseIdField.Type.CanValueBeNull);
            Assert.False(createdAtField.Type.CanValueBeNull);
        }
Ejemplo n.º 6
0
        public async Task NullableFielsShouldGenerateNullableMetadata()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/Issue_9/Query.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();

            var model = generator.Model;

            var droidType = Assert.Single(model.Types.Where(x => x.Name == "DroidResult"));

            var nullableField    = Assert.Single(droidType.Fields.Where(x => x.Name == "nullable"));
            var nonnullableField = Assert.Single(droidType.Fields.Where(x => x.Name == "nonnullable"));

            Assert.False(nonnullableField.Type.CanValueBeNull);
            Assert.True(nullableField.Type.CanValueBeNull);
        }
Ejemplo n.º 7
0
        public async Task ClientOnlyDirectivesShouldBeTrimedFromQueries()
        {
            var settings = settingsLoader.GenerateSettings(new CodeGeneratorSettingsLoaderDefaults(), new[] { "./Files/ClientOnlyDirectives/Query.gql" });

            CodeGenerator generator = new CodeGenerator(logger, settings.Single());

            await generator.LoadSource();

            generator.Parse();
            generator.Render();

            Assert.Empty(generator.Document.Errors);

            var code = generator.GeneratedCode;

            Assert.Contains(@"query q {
  test(id: """"safsa""""){
    nullable
    nonnullable
  }
}".Trim().Replace("\r", ""), code.Replace("\r", ""));
        }