public void CommandLineInvalidArgs(params string[] args) { AvroGenToolResult result = AvroGenHelper.RunAvroGenTool(args); Assert.That(result.ExitCode, Is.EqualTo(1)); Assert.That(result.StdOut, Is.Not.Empty); Assert.That(result.StdErr, Is.Not.Empty); }
public void CommandLineNoArgs() { AvroGenToolResult result = AvroGenHelper.RunAvroGenTool(Array.Empty <string>()); Assert.That(result.ExitCode, Is.EqualTo(1)); Assert.That(result.StdOut, Is.Not.Empty); Assert.That(result.StdErr, Is.Empty); }
private Assembly TestSchema( string schema, IEnumerable <string> typeNamesToCheck = null, IEnumerable <KeyValuePair <string, string> > namespaceMapping = null, IEnumerable <string> generatedFilesToCheck = null) { // Create temp folder string outputDir = AvroGenHelper.CreateEmptyTemporyFolder(out string uniqueId); try { // Save schema string schemaFileName = Path.Combine(outputDir, $"{uniqueId}.avsc"); System.IO.File.WriteAllText(schemaFileName, schema); // Generate from schema file Assert.That(AvroGenTool.GenSchema(schemaFileName, outputDir, namespaceMapping ?? new Dictionary <string, string>()), Is.EqualTo(0)); // Check if all generated files exist if (generatedFilesToCheck != null) { foreach (string generatedFile in generatedFilesToCheck) { Assert.That(new FileInfo(Path.Combine(outputDir, generatedFile)), Does.Exist); } } // Compile into netstandard library and load assembly Assembly assembly = AvroGenHelper.CompileCSharpFilesIntoLibrary( new DirectoryInfo(outputDir) .EnumerateFiles("*.cs", SearchOption.AllDirectories) .Select(fi => fi.FullName), uniqueId); if (typeNamesToCheck != null) { // Check if the compiled code has the same number of types defined as the check list Assert.That(typeNamesToCheck.Count(), Is.EqualTo(assembly.DefinedTypes.Count())); // Check if types available in compiled assembly foreach (string typeName in typeNamesToCheck) { Type type = assembly.GetType(typeName); Assert.That(type, Is.Not.Null); // Instantiate object obj = Activator.CreateInstance(type); Assert.That(obj, Is.Not.Null); } } return(assembly); } finally { Directory.Delete(outputDir, true); } }
public void CommandLineVersion(params string[] args) { AvroGenToolResult result = AvroGenHelper.RunAvroGenTool(args); Assert.That(result.ExitCode, Is.EqualTo(0)); Assert.That(result.StdOut, Is.Not.Empty); Assert.That(result.StdErr, Is.Empty); // Check if returned version is SemVer 2.0 compliant Assert.That(result.StdOut[0], Does.Match(Utils.VersionTests.SemVerRegex)); // Returned version must be the same as the avrogen tool assembly's version Assert.That(result.StdOut[0], Is.EqualTo(typeof(AvroGenTool).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion)); // Returned version must be the same as the avro library assembly's version Assert.That(result.StdOut[0], Is.EqualTo(typeof(Schema).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>().InformationalVersion)); }