예제 #1
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();
            }
        }
        public void With_Single_Messages_File_Generated_Code_Builds(CodeGenLanguage codeGenLanguage)
        {
            //given
            var context = new ProjectTestContext(BaseName,
                                                 $"{MethodBase.GetCurrentMethod().Name}{codeGenLanguage}");

            try
            {
                context.CreateProject(codeGenLanguage, new[]
                {
                    new Tuple <string, string>("Nethereum.Web3", Constants.NethereumWeb3Version)
                });

                var contractMetaData = TestContracts.StandardContract;
                var contractABI      = new GeneratorModelABIDeserialiser().DeserialiseABI(contractMetaData.ABI);

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

                var generatedFiles = contractProjectGenerator.GenerateAllMessagesFileAndService();
                GeneratedFileWriter.WriteFilesToDisk(generatedFiles);
                context.BuildProject();

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