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); }
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")); }
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"); }
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); }
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); }
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); }
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", "")); }