示例#1
0
        public void GetterWithInvalidSetterDoesNotGenerateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var returnType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = returnType,
                    MarshalType = returnType
                },
            };

            var invalidSetMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, invalidSetMethod }));

            Assert.Empty(propertyBuilder.CreateProperties(new[] { invalidSetMethod, getMethod }));
        }
示例#2
0
        public void GetterWithInvalidSetterDoesNotGenerateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var returnType = TypeRegistry.Int32;

            var getMethod = new CsMethod(null, "GetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType  = returnType,
                    MarshalType = returnType
                },
            };

            var invalidSetMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, invalidSetMethod }));

            Assert.Empty(propertyBuilder.CreateProperties(new[] { invalidSetMethod, getMethod }));
        }
示例#3
0
        public void GetterMethodReturningStatusCodeWithOutParamGeneratesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsStruct
                    {
                        Name = "SharpGen.Runtime.Result"
                    }
                }
            };

            getMethod.Add(new CsParameter
            {
                PublicType = paramType,
                Attribute  = CsParameterAttribute.Out
            });


            var properties = propertyBuilder.CreateProperties(new[] { getMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.True(prop.IsPropertyParam);
            Assert.Equal(paramType, prop.PublicType);
        }
示例#4
0
        public void MethodWithNameStartingWithSetCreatesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = paramType
            });


            var properties = propertyBuilder.CreateProperties(new[] { setMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.Equal(paramType, prop.PublicType);
        }
示例#5
0
        public void MethodWithNameStartingWithSetCreatesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = TypeRegistry.Int32;

            var setMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            setMethod.Add(new CsParameter(null, null)
            {
                PublicType = paramType
            });

            var properties = propertyBuilder.CreateProperties(new[] { setMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.Equal(paramType, prop.PublicType);
        }
示例#6
0
        public void MethodWithNameStartingWithSetAndReturningResultGeneratesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsStruct {
                        Name = "SharpGen.Runtime.Result"
                    }
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = paramType
            });

            var properties = propertyBuilder.CreateProperties(new[] { setMethod });

            Assert.True(properties.ContainsKey("Active"), "Property not created");
            var prop = properties["Active"];

            Assert.Equal(paramType, prop.PublicType);
        }
示例#7
0
        public void DoesNotGeneratePropertyIfGetterAndSetterMismatch()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = TypeRegistry.Int32;

            var getMethod = new CsMethod(null, "GetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType  = paramType,
                    MarshalType = paramType
                },
            };

            var setMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            setMethod.Add(new CsParameter(null, null)
            {
                PublicType = TypeRegistry.Int16
            });

            var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

            Assert.Empty(props);
        }
示例#8
0
        public void GetterMethodReturningStatusCodeWithOutParamGeneratesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = TypeRegistry.Int32;

            var getMethod = new CsMethod(null, "GetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
                }
            };

            getMethod.Add(new CsParameter(null, null)
            {
                PublicType = paramType,
                Attribute  = CsParameterAttribute.Out
            });


            var properties = propertyBuilder.CreateProperties(new[] { getMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.True(prop.IsPropertyParam);
            Assert.Equal(paramType, prop.PublicType);
        }
示例#9
0
        public void DoesNotGeneratePropertyIfGetterAndSetterMismatch()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = paramType,
                    MarshalType = paramType
                },
            };

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = new CsFundamentalType(typeof(short))
            });

            var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

            Assert.Empty(props);
        }
示例#10
0
        public void MethodWithNameStartingWithSetAndReturningResultGeneratesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = TypeRegistry.Int32;

            var setMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
                }
            };

            setMethod.Add(new CsParameter(null, null)
            {
                PublicType = paramType
            });

            var properties = propertyBuilder.CreateProperties(new[] { setMethod });

            Assert.True(properties.ContainsKey("Active"), "Property not created");
            var prop = properties["Active"];

            Assert.Equal(paramType, prop.PublicType);
        }
示例#11
0
        public void DoesNotGeneratePropertyIfOverloaded()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider("SharpGen.Runtime"));

            var paramType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = paramType,
                    MarshalType = paramType
                },
            };

            var getMethodOverload = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = paramType,
                    MarshalType = paramType
                },
            };

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = paramType
            });

            Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, setMethod, getMethodOverload }));
            Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod, getMethodOverload, setMethod }));
        }
示例#12
0
        public void NonPropertyMethodWithNonPropertyNameShouldNotCreateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var setMethod = new CsMethod(null, "MyMethod")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
        }
示例#13
0
        public void InvalidSetterDoesNotCreateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var setMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
        }
示例#14
0
        public void InvalidSetterDoesNotCreateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
        }
示例#15
0
        public void NonPropertyMethodWithNonPropertyNameShouldNotCreateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var setMethod = new CsMethod
            {
                Name        = "MyMethod",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { setMethod }));
        }
示例#16
0
        public void InvalidGetterDoesNotCreateProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider("SharpGen.Runtime"));

            var returnType = new CsFundamentalType(typeof(void));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = returnType,
                    MarshalType = returnType
                },
            };

            Assert.Empty(propertyBuilder.CreateProperties(new[] { getMethod }));
        }
示例#17
0
        public void DoesNotGeneratePropertyIfGetterAndSetterMismatch_ParameterizedGetter()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsStruct
                    {
                        Name = "SharpGen.Runtime.Result"
                    }
                }
            };

            getMethod.Add(new CsParameter
            {
                PublicType = paramType,
                Attribute  = CsParameterAttribute.Out
            });

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = new CsFundamentalType(typeof(short))
            });

            var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

            Assert.Empty(props);
        }
示例#18
0
        public void MethodWithNameStartingWithGetCreatesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var returnType = TypeRegistry.Int32;

            var getMethod = new CsMethod(null, "GetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType  = returnType,
                    MarshalType = returnType
                },
            };

            var properties = propertyBuilder.CreateProperties(new[] { getMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.Equal(returnType, prop.PublicType);
        }
示例#19
0
        public void MethodWithNameStartingWithGetCreatesProperty()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var returnType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = returnType,
                    MarshalType = returnType
                },
            };

            var properties = propertyBuilder.CreateProperties(new[] { getMethod });

            Assert.True(properties.ContainsKey("Active"));
            var prop = properties["Active"];

            Assert.Equal(returnType, prop.PublicType);
        }
示例#20
0
        public void DoesNotGeneratePropertyIfGetterAndSetterMismatch_ParameterizedGetter()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider());

            var paramType = TypeRegistry.Int32;

            var getMethod = new CsMethod(null, "GetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = new CsStruct(null, "SharpGen.Runtime.Result")
                }
            };

            getMethod.Add(new CsParameter(null, null)
            {
                PublicType = paramType,
                Attribute  = CsParameterAttribute.Out
            });

            var setMethod = new CsMethod(null, "SetActive")
            {
                ReturnValue = new CsReturnValue(null)
                {
                    PublicType = TypeRegistry.Void
                }
            };

            setMethod.Add(new CsParameter(null, null)
            {
                PublicType = TypeRegistry.Int16
            });

            var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

            Assert.Empty(props);
        }
示例#21
0
        public void GeneratePropertyIfGetterAndSetterMatch()
        {
            var propertyBuilder = new PropertyBuilder(new GlobalNamespaceProvider("SharpGen.Runtime"));

            var paramType = new CsFundamentalType(typeof(int));

            var getMethod = new CsMethod
            {
                Name        = "GetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType  = paramType,
                    MarshalType = paramType
                },
            };

            var setMethod = new CsMethod
            {
                Name        = "SetActive",
                ReturnValue = new CsReturnValue
                {
                    PublicType = new CsFundamentalType(typeof(void))
                }
            };

            setMethod.Add(new CsParameter
            {
                PublicType = paramType
            });

            var props = propertyBuilder.CreateProperties(new[] { getMethod, setMethod });

            Assert.Single(props);
            Assert.NotNull(props["Active"].Getter);
            Assert.NotNull(props["Active"].Setter);
        }
示例#22
0
    public void MethodWithNameStartingWithIsCreatesProperty()
    {
        var returnType = TypeRegistry.Int32;

        CsMethod isMethod = new(Ioc, null, "IsActive")
        {
            ReturnValue = new CsReturnValue(Ioc, null)
            {
                PublicType  = returnType,
                MarshalType = returnType
            }
        };

        var properties = propertyBuilder.CreateProperties(new[] { isMethod });

        Assert.True(properties.ContainsKey("IsActive"));
        var prop = properties["IsActive"];

        Assert.Equal(returnType, prop.PublicType);
    }