private IDictionary <string, OpenApiSchema> CreateDefinitions() { // Creates schema for each of the methods in the contract. var schemaFactory = new ContractSchemaFactory(); return(schemaFactory.Map(this.assembly)); }
public void Only_Map_Deployed_Type_Success() { var compilationResult = ContractCompiler.Compile(Code); var assembly = Assembly.Load(compilationResult.Compilation); var mapper = new ContractSchemaFactory(); IDictionary <string, OpenApiSchema> mapped = mapper.Map(new ContractAssembly(assembly)); Assert.Equal(11, mapped.Count); Assert.False(mapped.ContainsKey("SomeMethod")); }
public void Map_Parameter_Type_Success() { var compilationResult = ContractCompiler.Compile(Code); var assembly = Assembly.Load(compilationResult.Compilation); var mapper = new ContractSchemaFactory(); MethodInfo methodInfo = assembly.ExportedTypes.First(t => t.Name == "PrimitiveParams").GetMethod("AcceptsAllParams"); var schema = mapper.Map(methodInfo); var properties = schema.Properties; Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(bool)]().Type, properties["b"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(byte)]().Type, properties["bb"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(byte[])]().Type, properties["ba"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(char)]().Type, properties["c"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(string)]().Type, properties["s"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(uint)]().Type, properties["ui"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(ulong)]().Type, properties["ul"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(int)]().Type, properties["i"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(long)]().Type, properties["l"].Type); Assert.Equal(ContractSchemaFactory.PrimitiveTypeMap[typeof(string)]().Type, properties["a"].Type); }
public void Only_Map_Deployed_Type_Single_Contract_Success() { string code = @" using Stratis.SmartContracts; public class PrimitiveParams : SmartContract { public PrimitiveParams(ISmartContractState state): base(state) {} public void SomeMethod(string i) {} } "; var compilationResult = ContractCompiler.Compile(code); var assembly = Assembly.Load(compilationResult.Compilation); var contractAssembly = new ContractAssembly(assembly); var mapper = new ContractSchemaFactory(); IDictionary <string, OpenApiSchema> mapped = mapper.Map(contractAssembly); Assert.Equal(1, mapped.Count); Assert.True(mapped.ContainsKey("SomeMethod")); }
public void Map_Type_Success() { var compilationResult = ContractCompiler.Compile(Code); var assembly = Assembly.Load(compilationResult.Compilation); var mapper = new ContractSchemaFactory(); // Maps the methods in a type to schemas. IDictionary <string, OpenApiSchema> mapped = mapper.Map(new ContractAssembly(assembly).GetPublicMethods()); Assert.Equal("AcceptsBool", mapped["AcceptsBool"].Title); Assert.Equal("AcceptsByte", mapped["AcceptsByte"].Title); Assert.Equal("AcceptsByteArray", mapped["AcceptsByteArray"].Title); Assert.Equal("AcceptsChar", mapped["AcceptsChar"].Title); Assert.Equal("AcceptsString", mapped["AcceptsString"].Title); Assert.Equal("AcceptsUint", mapped["AcceptsUint"].Title); Assert.Equal("AcceptsUlong", mapped["AcceptsUlong"].Title); Assert.Equal("AcceptsInt", mapped["AcceptsInt"].Title); Assert.Equal("AcceptsLong", mapped["AcceptsLong"].Title); Assert.Equal("AcceptsAddress", mapped["AcceptsAddress"].Title); Assert.Equal(11, mapped.Count); }