public void GivenProjectFileOrFolderPath_ItFindsAllAbiFilesInProjectFolder(PathType pathType) { //given var factory = new GeneratorConfigurationFactory(); var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name + "_" + pathType.ToString()); try { context.CreateProject(); context.WriteFileToProject("StandardContract.abi", TestContracts.StandardContract.ABI); context.WriteFileToProject("StandardContract.bin", TestContracts.StandardContract.ByteCode); //when var path = pathType == PathType.FolderAndFile ? context.ProjectFilePath : context.TargetProjectFolder; var config = factory.FromProject(path, context.OutputAssemblyName); //then var abiConfig = config.ElementAt(0); Assert.NotNull(abiConfig); Assert.Equal(CodeGenLanguage.CSharp, abiConfig.CodeGenLanguage); Assert.Equal("StandardContract", abiConfig.ContractName); Assert.Equal(JsonConvert.SerializeObject(TestContracts.StandardContract.GetContractAbi()), JsonConvert.SerializeObject(abiConfig.ContractABI)); Assert.Equal(TestContracts.StandardContract.ByteCode, abiConfig.ByteCode); Assert.Equal(context.TargetProjectFolder, abiConfig.BaseOutputPath); Assert.Equal(Path.GetFileNameWithoutExtension(context.OutputAssemblyName), abiConfig.BaseNamespace); Assert.Equal("StandardContract.CQS", abiConfig.CQSNamespace); Assert.Equal("StandardContract.DTO", abiConfig.DTONamespace); Assert.Equal("StandardContract.Service", abiConfig.ServiceNamespace); } finally { context.CleanUp(); } }
public void WhenContractNameIsNotSpecifiedUsesAbiFileName() { //given var factory = new GeneratorConfigurationFactory(); var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name); try { context.CreateProject(); context.WriteFileToProject("StandardContract.abi", TestContracts.StandardContract.ABI); context.WriteFileToProject("StandardContract.bin", TestContracts.StandardContract.ByteCode); //when var config = factory.FromAbi( null, //contract name "StandardContract.abi", "StandardContract.bin", Path.GetFileNameWithoutExtension(context.OutputAssemblyName), context.TargetProjectFolder).ToList(); //then Assert.Equal(1, config.Count); var abiConfig = config.First(); Assert.Equal("StandardContract", abiConfig.ContractName); } finally { context.CleanUp(); } }
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(); } }
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 GivenRelativeAbiFilePathInProject() { //given var factory = new GeneratorConfigurationFactory(); var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name); try { context.CreateProject(); context.WriteFileToProject("solidity\\StandardContract.abi", TestContracts.StandardContract.ABI); context.WriteFileToProject("solidity\\StandardContract.bin", TestContracts.StandardContract.ByteCode); var generatorConfig = new ABICollectionConfiguration { ABIConfigurations = new List <ABIConfiguration> { new ABIConfiguration { ContractName = "StandardContractA", ABIFile = "solidity\\StandardContract.abi", BaseOutputPath = context.TargetProjectFolder } } }; generatorConfig.SaveToJson(context.TargetProjectFolder); //when var config = factory.FromProject(context.TargetProjectFolder, context.OutputAssemblyName).ToList(); //then Assert.Equal(1, config.Count); var abiConfig = config.ElementAt(0); Assert.NotNull(abiConfig); Assert.Equal(CodeGenLanguage.CSharp, abiConfig.CodeGenLanguage); Assert.Equal("StandardContractA", abiConfig.ContractName); Assert.Equal(JsonConvert.SerializeObject(TestContracts.StandardContract.GetContractAbi()), JsonConvert.SerializeObject(abiConfig.ContractABI)); Assert.Equal(TestContracts.StandardContract.ByteCode, abiConfig.ByteCode); Assert.Equal(context.TargetProjectFolder, abiConfig.BaseOutputPath); Assert.Equal(Path.GetFileNameWithoutExtension(context.OutputAssemblyName), abiConfig.BaseNamespace); Assert.Equal("StandardContractA.CQS", abiConfig.CQSNamespace); Assert.Equal("StandardContractA.DTO", abiConfig.DTONamespace); Assert.Equal("StandardContractA.Service", abiConfig.ServiceNamespace); } finally { context.CleanUp(); } }
public void ReadsProjectInformationFromProjectFolderPath() { var context = new ProjectTestContext(this.GetType().Name, "Test05"); try { context.CreateProject(); var folderInfo = new DotNetProjectFolderInfo(context.TargetProjectFolder); AssertDefaultProjectValues(context, folderInfo); } finally { context.CleanUp(); } }
public void CanReadRootNamespaceFromProjectFile() { var context = new ProjectTestContext(this.GetType().Name, "Test01"); try { context.CreateProject(); context.SetRootNamespaceInProject("Test"); var folderInfo = new DotNetProjectFolderInfo(context.TargetProjectFolder); Assert.Equal("Test", folderInfo.RootNamespace); } 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(); } }
public void RootNamespaceTakesPreferenceToAssemblyName() { var context = new ProjectTestContext(this.GetType().Name, "Test03"); try { context.CreateProject(); context.SetRootNamespaceInProject("TestNamespace"); context.SetAssemblyNameInProject("TestAssembly"); var folderInfo = new DotNetProjectFolderInfo(context.TargetProjectFolder); Assert.Equal("TestNamespace", folderInfo.RootNamespace); } finally { context.CleanUp(); } }
public void GivenRelativeAbiPathInProjectParent() { //given var factory = new GeneratorConfigurationFactory(); var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name); try { context.CreateProject(); context.WriteFileToProject("..\\StandardContract.abi", TestContracts.StandardContract.ABI); var generatorConfig = new ABICollectionConfiguration { ABIConfigurations = new List <ABIConfiguration> { new ABIConfiguration { ContractName = "StandardContractA", ABIFile = "..\\StandardContract.abi", BaseOutputPath = context.TargetProjectFolder } } }; generatorConfig.SaveToJson(context.TargetProjectFolder); //when var config = factory.FromProject(context.TargetProjectFolder, context.OutputAssemblyName).ToList(); //then Assert.Equal(1, config.Count); var abiConfig = config.First(); Assert.NotNull(abiConfig); Assert.Equal(CodeGenLanguage.CSharp, abiConfig.CodeGenLanguage); Assert.Equal("StandardContractA", abiConfig.ContractName); Assert.Equal(JsonConvert.SerializeObject(TestContracts.StandardContract.GetContractAbi()), JsonConvert.SerializeObject(abiConfig.ContractABI)); } finally { context.CleanUp(); } }
public void GeneratesConfigurationFromAbiFilesInProject() { //given var factory = new GeneratorConfigurationFactory(); var context = new ProjectTestContext(this.GetType().Name, MethodBase.GetCurrentMethod().Name); try { context.CreateProject(); context.WriteFileToProject("StandardContract.abi", TestContracts.StandardContract.ABI); context.WriteFileToProject("StandardContract.bin", TestContracts.StandardContract.ByteCode); //when var config = factory.FromAbi( "StandardContract", "StandardContract.abi", "StandardContract.bin", Path.GetFileNameWithoutExtension(context.OutputAssemblyName), context.TargetProjectFolder).ToList(); //then Assert.Equal(1, config.Count); var abiConfig = config.ElementAt(0); Assert.NotNull(abiConfig); Assert.Equal(CodeGenLanguage.CSharp, abiConfig.CodeGenLanguage); Assert.Equal("StandardContract", abiConfig.ContractName); //Assert.Equal(JsonConvert.SerializeObject(TestContracts.StandardContract.GetContractAbi()), JsonConvert.SerializeObject(abiConfig.ContractABI)); Assert.Equal(TestContracts.StandardContract.ByteCode, abiConfig.ByteCode); Assert.Equal(context.TargetProjectFolder, abiConfig.BaseOutputPath); Assert.Equal(Path.GetFileNameWithoutExtension(context.OutputAssemblyName), abiConfig.BaseNamespace); Assert.Equal("StandardContract.ContractDefinition", abiConfig.CQSNamespace); Assert.Equal("StandardContract.ContractDefinition", abiConfig.DTONamespace); Assert.Equal("StandardContract", abiConfig.ServiceNamespace); } finally { context.CleanUp(); } }