Ejemplo n.º 1
0
        public void GeneratesConfigurationFromTruffleJsonFiles()
        {
            //given
            var factory = new GeneratorConfigurationFactory();
            var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name);

            try
            {
                context.CreateEmptyProject();

                var truffleJsonDirectory = Path.Combine(context.TargetProjectFolder, "build", "contracts");

                var truffleFiles = new[]
                {
                    new TruffleFileWrapper(truffleJsonDirectory, "MetaCoin.json"),
                    new TruffleFileWrapper(truffleJsonDirectory, "EIP20.json")
                };

                foreach (var truffleFile in truffleFiles)
                {
                    context.WriteFileToProject(truffleFile.Path, truffleFile.Content);
                }

                //when
                var config = factory.FromTruffle(
                    directory: truffleJsonDirectory,
                    outputFolder: context.TargetProjectFolder,
                    baseNamespace: "DefaultNamespace",
                    language: CodeGenLanguage.CSharp).ToList();

                //then
                Assert.Equal(truffleFiles.Length, config.Count);

                foreach (var truffleFile in truffleFiles)
                {
                    var actualConfig = config.First(c => c.ContractName == truffleFile.ContractName);
                    Assert.NotNull(actualConfig);
                    Assert.Equal(CodeGenLanguage.CSharp, actualConfig.CodeGenLanguage);

                    //Assert.Equal(
                    //    JsonConvert.SerializeObject(truffleFile.ContractAbi),
                    //    JsonConvert.SerializeObject(actualConfig.ContractABI));

                    Assert.Equal(truffleFile.TruffleContract.Bytecode, actualConfig.ByteCode);
                    Assert.Equal(context.TargetProjectFolder, actualConfig.BaseOutputPath);

                    Assert.Equal("DefaultNamespace", actualConfig.BaseNamespace);
                    Assert.Equal($"{truffleFile.ContractName}.ContractDefinition", actualConfig.CQSNamespace);
                    Assert.Equal($"{truffleFile.ContractName}.ContractDefinition", actualConfig.DTONamespace);
                    Assert.Equal($"{truffleFile.ContractName}", actualConfig.ServiceNamespace);
                }
            }
            finally
            {
                context.CleanUp();
            }
        }
Ejemplo n.º 2
0
        public void GeneratedProjectBuildsSuccessfully(CodeGenLanguage codeGenLanguage)
        {
            var context = new ProjectTestContext(GetType().Name,
                                                 $"{MethodBase.GetCurrentMethod().Name}{codeGenLanguage}");

            try
            {
                //given
                context.TargetFramework = "netstandard2.0";
                context.CreateEmptyProject();
                var fullProjectFilePath = Path.Combine(context.TargetProjectFolder,
                                                       context.ProjectName + CodeGenLanguageExt.ProjectFileExtensions[codeGenLanguage]);

                var generator = new NetStandardLibraryGenerator(fullProjectFilePath, codeGenLanguage)
                {
                    NethereumWeb3Version = Constants.NethereumWeb3Version
                };

                //when
                //code gen proj file
                var projectFile = generator.GenerateFileContent(context.TargetProjectFolder);
                GeneratedFileWriter.WriteFileToDisk(projectFile);

                //add in some code gen class files
                var contractMetaData = TestContracts.StandardContract;
                var contractABI      = new GeneratorModelABIDeserialiser().DeserialiseABI(contractMetaData.ABI);

                var contractProjectGenerator = new ContractProjectGenerator(
                    contractABI,
                    "StandardContract",
                    contractMetaData.ByteCode,
                    context.ProjectName,
                    "StandardContract.Service",
                    "StandardContract.CQS",
                    "StandardContract.DTO",
                    context.TargetProjectFolder,
                    Path.DirectorySeparatorChar.ToString(),
                    codeGenLanguage)
                {
                    AddRootNamespaceOnVbProjectsToImportStatements = false
                };

                var generatedFiles = contractProjectGenerator.GenerateAll();
                GeneratedFileWriter.WriteFilesToDisk(generatedFiles);

                context.BuildProject();

                //then
                Assert.True(context.BuildHasSucceeded());
            }
            finally
            {
                context.CleanUp();
            }
        }