示例#1
0
        public async Task ExecuteToFileTest()
        {
            var fileName = ".\\test-project.mdj";
            var project  = await DVDpro.StarUML.FileFormat.Project.LoadAsync(fileName);

            var tmpFile = System.IO.Path.GetTempFileName();

            try
            {
                var generator = new InterfaceGenerator();
                using (var outStream = new CSharpWriter(tmpFile))
                {
                    foreach (var model in project.GetChildrenByType <DVDpro.StarUML.FileFormat.Nodes.UmlModelNode>())
                    {
                        var node = model.GetChildrenByType <DVDpro.StarUML.FileFormat.Nodes.UmlInterfaceNode>().First(r => r.Name == "Interface1");
                        generator.Generate(outStream, node);
                    }
                }
                var output = await System.IO.File.ReadAllTextAsync(tmpFile);

                Assert.Equal("public interface Interface1 : Interface1Base\r\n{\r\n    int InterfaceAttribute { get; }\r\n}\r\n", output);
            }
            finally
            {
                System.IO.File.Delete(tmpFile);
            }
        }
        private void CheckTypeScriptInterfaceFile(string interfaceFileSubPath)
        {
            var contractFile = new FileInfo(GetTypeScriptContractFullPath(interfaceFileSubPath));

            contractFile.Exists.Should().BeTrue(
                $"The Typescript contract file {interfaceFileSubPath} does not exist. Please run the `src/interface-generator` tool with option --out-file {contractFile.FullName}.");

            var actual   = File.ReadAllText(contractFile.FullName);
            var expected = InterfaceGenerator.Generate();

            var compareResult = new DefaultStringComparer(true).Compare(actual, expected);

            compareResult
            .Error
            .Should()
            .BeNullOrEmpty(
                because:
                $@"{contractFile.Name} should match the checked-in version.

If the contract change is deliberate, then the TypeScript contracts file '{interfaceFileSubPath}' needs to be regenerated.

Please run the following:

dotnet run -p src/interface-generator --  --out-file {contractFile.FullName}

");
        }
示例#3
0
        public static void PrintInterface(Interface iface, string root, List <string> imports)
        {
            string packageDirectory = Path.Combine(root, JavaConventionHelper.packageConvention(iface.Namespace.Name));

            Directory.CreateDirectory(packageDirectory);
            using (StreamWriter writer = new StreamWriter(Path.Combine(packageDirectory, iface.Name + ".java")))
            {
                InterfaceGenerator javaGen = new InterfaceGenerator();
                writer.WriteLine(javaGen.Generate(iface, imports));
            }
        }
        private void CheckTypeScriptInterfaceFile(string interfaceFileSubPath)
        {
            var contractFile = new FileInfo(GetTypeScriptContractFullPath(interfaceFileSubPath));

            contractFile.Exists.Should().BeTrue($"The Typescript contract file {interfaceFileSubPath} does not exist. Please run the `src/interface-generator` tool with option --out-file {contractFile.FullName}.");

            var actual   = File.ReadAllText(contractFile.FullName);
            var expected = InterfaceGenerator.Generate();

            actual.Should()
            .Be(expected, $"The contents of the TypeScript contracts file '{interfaceFileSubPath}' needs to be updated.  Please re-run the `src/interface-generator` tool with option --out-file {contractFile.FullName}.");
        }
示例#5
0
    public static void Generate(TypeMap typeMap, string fname, string name)
    {
        StreamReader  sr  = new StreamReader(fname);
        XmlSerializer sz  = new XmlSerializer(typeof(xcb));
        xcb           xcb = (xcb)sz.Deserialize(sr);

        string extName = xcb.extensionxname ?? "";

        TypesGenerator tg = new TypesGenerator(typeMap);

        tg.Generate(xcb, name, extName);

        InterfaceGenerator ig = new InterfaceGenerator(typeMap);

        ig.Generate(xcb, name);

        ClassGenerator cg = new ClassGenerator(typeMap);

        cg.Generate(xcb, name, extName);
    }