예제 #1
0
        private IDictionary <string, OpenApiSchema> CreateDefinitions()
        {
            // Creates schema for each of the methods in the contract.
            var schemaFactory = new ContractSchemaFactory();

            return(schemaFactory.Map(this.assembly));
        }
예제 #2
0
        public void AddSchema_2()
        {
            // arrange
            ISchema customerSchema = CustomerSchemaFactory.Create();

            ISchema contractSchema = ContractSchemaFactory.Create();

            var builder = new MockStitchingBuilder();

            // act
            builder.AddSchema("customer", customerSchema)
            .AddSchema("contract", contractSchema);

            // assert
            var services = new EmptyServiceProvider();
            var merger   = new SchemaMerger();

            foreach (KeyValuePair <NameString, ExecutorFactory> item in
                     builder.Executors)
            {
                ISchema schema = item.Value.Invoke(services).Schema;
                merger.AddSchema(item.Key,
                                 SchemaSerializer.SerializeSchema(schema));
            }

            SchemaSyntaxSerializer.Serialize(merger.Merge()).MatchSnapshot();
        }
예제 #3
0
        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"));
        }
예제 #4
0
        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);
        }
예제 #5
0
        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"));
        }
예제 #6
0
        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);
        }