private void ProtoTestSingle(IEnumerable <string> testProtoNames, bool ignoreCsProj = false, bool ignoreSnippets = false, bool ignoreUnitTests = false, string grpcServiceConfigPath = null, IEnumerable <string> commonResourcesConfigPaths = null) { // Confirm each generated file is idential to the expected output. // Use `// TEST_START` and `// TEST_END` lines in the expected file to test subsets of output files. // Or include `// TEST_DISABLE` to disable testing of the entire file. var dirName = testProtoNames.First(); var protoPaths = testProtoNames.Select(x => Path.Combine("ProtoTests", dirName, $"{x}.proto")); var files = Run(protoPaths, $"testing.{dirName.ToLowerInvariant()}", grpcServiceConfigPath, commonResourcesConfigPaths); // Check output is present. Assert.NotEmpty(files); // Verify each output file. foreach (var file in files) { if ((ignoreCsProj && file.RelativePath.EndsWith(".csproj")) || (ignoreSnippets && file.RelativePath.Contains($".Snippets{Path.DirectorySeparatorChar}")) || (ignoreUnitTests && file.RelativePath.Contains($".Tests{Path.DirectorySeparatorChar}"))) { continue; } var expectedFilePath = Path.Combine(Invoker.GeneratorTestsDir, "ProtoTests", dirName, file.RelativePath); TextComparer.CompareText(expectedFilePath, file); } }
internal static void TestOutput(string directory, bool ignoreCsProj = false, bool ignoreConfig = false) { var resourceDirectory = Path.Combine(TestDirectory, "GoldenTestData", directory); var json = File.ReadAllText(Path.Combine(resourceDirectory, "discovery.json")); var features = new Features { ReleaseVersion = "1.49.0", CurrentSupportVersion = "1.49.0", Net40SupportVersion = "1.25.0", PclSupportVersion = "1.10.0" }; PackageEnumStorage enumStorage = PackageEnumStorage.FromJson("{}"); var files = CodeGenerator.Generate(json, features, enumStorage).ToList(); // Check output is present. Assert.NotEmpty(files); foreach (var file in files) { if ((ignoreCsProj && file.RelativePath.EndsWith(".csproj")) || (ignoreConfig && file.RelativePath.EndsWith(".config"))) { continue; } var expectedFilePath = Path.Combine(TestDirectory, "GoldenTestData", directory, file.RelativePath); TextComparer.CompareText(expectedFilePath, file); } // TODO: Validate enum storage }
private void ProtoTestSingle(IEnumerable <string> testProtoNames, string sourceDir = null, string outputDir = null, string package = null, bool ignoreCsProj = false, bool ignoreSnippets = false, bool ignoreUnitTests = false, string grpcServiceConfigPath = null, string serviceConfigPath = null, IEnumerable <string> commonResourcesConfigPaths = null, ApiTransports transports = ApiTransports.Grpc, bool ignoreGapicMetadataFile = true, bool ignoreApiMetadataFile = true, bool ignoreServiceExtensionsFile = true) { // Confirm each generated file is identical to the expected output. // Use `// TEST_START` and `// TEST_END` lines in the expected file to test subsets of output files. // Or include `// TEST_DISABLE` to disable testing of the entire file. sourceDir = sourceDir ?? testProtoNames.First(); outputDir = outputDir ?? sourceDir; var protoPaths = testProtoNames.Select(x => Path.Combine("ProtoTests", sourceDir, $"{x}.proto")); package = package ?? $"testing.{sourceDir.ToLowerInvariant()}"; var files = Run(protoPaths, package, grpcServiceConfigPath, serviceConfigPath, commonResourcesConfigPaths, transports); // Check output is present. Assert.NotEmpty(files); // Write all output files to the temporary directory before validating any. // This makes it easier to see the complete set of outputs. foreach (var file in files) { var pathToWriteTo = Path.Combine(Invoker.ActualGeneratedFilesDir, outputDir, file.RelativePath); Directory.CreateDirectory(Path.GetDirectoryName(pathToWriteTo)); File.WriteAllText(pathToWriteTo, file.Content); } // Verify each output file. foreach (var file in files) { if ((ignoreCsProj && file.RelativePath.EndsWith(".csproj")) || (ignoreSnippets && file.RelativePath.Contains($".Snippets{Path.DirectorySeparatorChar}")) || (ignoreSnippets && file.RelativePath.Contains($".GeneratedSnippets{Path.DirectorySeparatorChar}")) || (ignoreUnitTests && file.RelativePath.Contains($".Tests{Path.DirectorySeparatorChar}")) || (ignoreGapicMetadataFile && file.RelativePath.EndsWith("gapic_metadata.json")) || (ignoreApiMetadataFile && file.RelativePath.EndsWith(PackageApiMetadataGenerator.FileName)) || (ignoreServiceExtensionsFile && file.RelativePath.EndsWith(ServiceCollectionExtensionsGenerator.FileName))) { continue; } var expectedFilePath = Path.Combine(Invoker.GeneratorTestsDir, "ProtoTests", outputDir, file.RelativePath); TextComparer.CompareText(expectedFilePath, file); } }
internal static void TestOutput(string directory, bool ignoreCsProj = false, bool ignoreConfig = false) { var resourceDirectory = Path.Combine(TestDirectory, "GoldenTestData", directory); var json = File.ReadAllText(Path.Combine(resourceDirectory, "discovery.json")); var files = CodeGenerator.Generate(json).ToList(); // Check output is present. Assert.NotEmpty(files); foreach (var file in files) { if ((ignoreCsProj && file.RelativePath.EndsWith(".csproj")) || (ignoreConfig && file.RelativePath.EndsWith(".config"))) { continue; } var expectedFilePath = Path.Combine(TestDirectory, "GoldenTestData", directory, file.RelativePath); TextComparer.CompareText(expectedFilePath, file); } }