Beispiel #1
0
        public void TestNormalFunctionWrap()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestNormalFunctionWrap))
            {
                Class = { Name = "TestNormalFunctionWrap" }
            };

            policy.Factory(context);

            Assert.AreEqual(3, context.Class.Members.Count);
            Assert.AreEqual("VoidReturn", context.Class.Members[0].Name);
            Assert.AreEqual("IntReturn", context.Class.Members[1].Name);
            Assert.AreEqual("IntReturnAndHasParams", context.Class.Members[2].Name);

            Assert.AreEqual(
                @"public static void VoidReturn() {
    Instance.VoidReturn();
}", Util.GenerateFromMember(context.Class.Members[0]));

            Assert.AreEqual(
                @"public static int IntReturn() {
    return Instance.IntReturn();
}", Util.GenerateFromMember(context.Class.Members[1]));

            Assert.AreEqual(
                @"public static int IntReturnAndHasParams(string name) {
    return Instance.IntReturnAndHasParams(name);
}", Util.GenerateFromMember(context.Class.Members[2]));
        }
Beispiel #2
0
        public void OverrideMethod()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(IOverrideMethod))
            {
                Class = { Name = "OverrideMethod" }
            };

            policy.Factory(context);

            Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class OverrideMethod {
    
    public static event System.Action TestFunction {
        add {  
            Instance.TestFunction += value;
        }
        remove {
            Instance.TestFunction -= value;
        }
    }
    
    public static float TestFunction2 {
        get {
            return Instance.TestFunction2;
        }
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #3
0
        public void TestHasDefaultValueFunction()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestHasDefaultValueFunction))
            {
                Class = { Name = "TestHasDefaultValueFunction" }
            };

            policy.Factory(context);
            // Console.WriteLine(Util.GenerateFromType(context.Class));
            Assert.AreEqual(
                @"public class TestHasDefaultValueFunction {
    
    public static void HasIntDefaultValue(int num = 100) {
        Instance.HasIntDefaultValue(num);
    }
    
    public static void HasFloatDefaultValue(float num = 100.123f, float num2 = 200f) {
        Instance.HasFloatDefaultValue(num, num2);
    }
    
    public static void HasBooleanDefaultValue(bool v1 = true, bool v2 = false) {
        Instance.HasBooleanDefaultValue(v1, v2);
    }
    
    public static void HasDoubleDefaultValue(double num = 123.123456789d, double num2 = 123d, double num3 = 123.123458862305d) {
        Instance.HasDoubleDefaultValue(num, num2, num3);
    }
    
    public static void HasUintDefaultValue(uint num = 122) {
        Instance.HasUintDefaultValue(num);
    }
    
    public static void HasStringDefaultValue(string str = ""helloworld"") {
        Instance.HasStringDefaultValue(str);
    }
    
    public static void HasStringNullDefaultValue(string str = null) {
        Instance.HasStringNullDefaultValue(str);
    }
    
    public static void HasClassDefaultValue(CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestHasDefaultValueFunction cls = null) {
        Instance.HasClassDefaultValue(cls);
    }
    
    public static void TestGenericTypeDefaultValue(System.Collections.Generic.Dictionary<string, CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestHasDefaultValueFunction> generic = null) {
        Instance.TestGenericTypeDefaultValue(generic);
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #4
0
        public void TestOverloadMethod()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestOverloadMethod))
            {
                Class = { Name = "TestOverloadMethod" }
            };

            policy.Factory(context);
            // Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class TestOverloadMethod {
    
    public static event System.Action TestFunctionRef {
        add {  
            Instance.TestFunctionRef += value;
        }
        remove {
            Instance.TestFunctionRef -= value;
        }
    }
    
    public static void TestFunction() {
        Instance.TestFunction();
    }
    
    public static void TestFunction2(int a = 100) {
        Instance.TestFunction2(a);
    }
    
    public static void TestFunction(int a) {
        Instance.TestFunction(a);
    }
    
    public static void TestFunction2(double a = 100d) {
        Instance.TestFunction2(a);
    }
    
    public static void TestFunction2(double a, int b = 100) {
        Instance.TestFunction2(a, b);
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #5
0
        public void MethodDirectionCallTwoSense()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(IMethodDirectionCallTwoSense))
            {
                Class = { Name = "MethodDirectionCallTwoSense" }
            };

            try
            {
                policy.Factory(context);
            }
            catch (GenerateException)
            {
                return;
            }

            Assert.Fail();
        }
Beispiel #6
0
        public void TestHasGenericInterface()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestHasGenericInterface))
            {
                Class = { Name = "TestHasGenericInterface" }
            };

            policy.Factory(context);
            //Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class TestHasGenericInterface {
    
    public static CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestHasGenericInterface Say(CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestHasGenericInterface value, CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestHasGenericInterface def = null) {
        return Instance.Say(value, def);
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #7
0
        public void TestThisProperty()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestThisProperty))
            {
                Class = { Name = "TestThisProperty" }
            };

            policy.Factory(context);

            // Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class TestThisProperty {
    
    public static void TestFunction() {
        Instance.TestFunction();
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #8
0
        public void TestEvent()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestEvent))
            {
                Class = { Name = "TestEvent" }
            };

            policy.Factory(context);
            Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class TestEvent {
    
    public static event System.Action ActionEventTest {
        add {  
            Instance.ActionEventTest += value;
        }
        remove {
            Instance.ActionEventTest -= value;
        }
    }
    public static event System.Action<CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestEvent> ActionGenericEventTest {
        add {  
            Instance.ActionGenericEventTest += value;
        }
        remove {
            Instance.ActionGenericEventTest -= value;
        }
    }
    public static event System.Func<int, System.Collections.Generic.Dictionary<string, CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestEvent>> FuncEventTest {
        add {  
            Instance.FuncEventTest += value;
        }
        remove {
            Instance.FuncEventTest -= value;
        }
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #9
0
        public void MixedOverride()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(IMixedOverride))
            {
                Class = { Name = "MixedOverride" }
            };

            policy.Factory(context);

            Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(@"public class MixedOverride {
    
    public static event System.Action<CatLib.Generater.Editor.Policy.StaticWrap.MemberStaticWrapPolicy> TestFunction2 {
        add {  
            Instance.TestFunction2 += value;
        }
        remove {
            Instance.TestFunction2 -= value;
        }
    }
    
    public static System.Action TestFunction3 {
        get {
            return Instance.TestFunction3;
        }
        set {
            Instance.TestFunction3 = value;
        }
    }
    
    public static float TestFunction(int a = 100) {
        return Instance.TestFunction(a);
    }
}", Util.GenerateFromType(context.Class));
        }
Beispiel #10
0
        public void TestAttributeSelector()
        {
            var policy  = new MemberStaticWrapPolicy();
            var context = new FacadeContext(null, typeof(ITestAttributeSelector))
            {
                Class = { Name = "TestAttributeSelector" }
            };

            policy.Factory(context);
            // Console.WriteLine(Util.GenerateFromType(context.Class));

            Assert.AreEqual(
                @"public class TestAttributeSelector {
    
    public static string StringData {
        get {
            return Instance.StringData;
        }
        set {
            Instance.StringData = value;
        }
    }
    
    public static string StringDataOnlyGet {
        get {
            return Instance.StringDataOnlyGet;
        }
    }
    
    public static string StringDataOnlySet {
        set {
            Instance.StringDataOnlySet = value;
        }
    }
    
    public static System.Collections.Generic.List<string> ListData {
        get {
            return Instance.ListData;
        }
        set {
            Instance.ListData = value;
        }
    }
    
    public static CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestAttributeSelector ClassData {
        set {
            Instance.ClassData = value;
        }
    }
    
    public static System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestAttributeSelector>> ComplexGenericTypeOnlyGet {
        get {
            return Instance.ComplexGenericTypeOnlyGet;
        }
    }
    
    public static System.Collections.Generic.Dictionary<string, System.Collections.Generic.List<CatLib.Generater.Editor.Tests.Policy.MemberStaticWrapPolicyTests.ITestAttributeSelector>> ComplexGenericTypeOnlySet {
        set {
            Instance.ComplexGenericTypeOnlySet = value;
        }
    }
}", Util.GenerateFromType(context.Class));
        }