示例#1
0
        public void Should_PassParameters_When_ManyArguments()
        {
            var argCount = 0;

            var arg = new TestArg(parameters =>
            {
                Assert.Equal(3, parameters.Count);
                Assert.Equal("x", parameters["param"]);
                Assert.Equal("x2", parameters["param2"]);
                Assert.Equal("x3", parameters["param3"]);
                argCount++;
            })
            {
                Name = "arg", Value = "value", AllowedParameters = new[] { "param", "param2", "param3" }
            };

            var arg2Count = 0;

            var arg2 = new TestArg(parameters =>
            {
                Assert.Equal(1, parameters.Count);
                Assert.Equal("val", parameters["par"]);
                arg2Count++;
            })
            {
                Name = "arg2", Value = "value2", AllowedParameters = new[] { "par" }
            };

            var result = MessageFormatter.Format("test {arg|param=x|param2=x2|param3=x3} {arg2|par=val}", new IMessageArg[] { arg, arg2 });

            Assert.Equal("test value value2", result);
            Assert.Equal(1, argCount);
            Assert.Equal(1, arg2Count);
        }
示例#2
0
        public void Should_Stringify_When_OnlyUsedArguments()
        {
            var argCount = 0;

            var arg = new TestArg(parameters =>
            {
                Assert.Null(parameters);
                argCount++;
            })
            {
                Name = "arg", Value = "value"
            };

            var arg2Count = 0;
            var arg2      = new TestArg(parameters => { arg2Count++; })
            {
                Name = "arg2", Value = "value2"
            };

            var result = MessageFormatter.Format("test {arg} {arg2} {arg3}", new IMessageArg[] { arg, arg2 });

            Assert.Equal("test value value2 {arg3}", result);
            Assert.Equal(1, argCount);
            Assert.Equal(1, arg2Count);
        }
        public void BaseMemberAccess_ExtensionBindTestMethod_BaseClass()
        {
            var arg = new TestArg() as BaseTestArg;

            engine.AddRestrictedHostObject("arg", arg);
            Assert.AreEqual(testObject.BaseExtensionBindTestMethod(arg), engine.Evaluate("testObject.BaseExtensionBindTestMethod(arg)"));
        }
示例#4
0
        public void InterfaceMemberAccess_BindTestMethod_Interface()
        {
            var arg = new TestArg() as ITestArg;

            engine.AddRestrictedHostObject("arg", arg);
            Assert.AreEqual(testObject.InterfaceBindTestMethod(arg), engine.Evaluate("testObject.InterfaceBindTestMethod(arg)"));
        }
示例#5
0
            public void Should_FormatMessage_SinglePlaceholder()
            {
                var parametersChecked = 0;

                var testArg = new TestArg(parameters =>
                {
                    parameters.Should().BeNull();
                    parametersChecked++;
                });

                testArg.AllowedParameters = Array.Empty <string>();

                testArg.Name  = "test";
                testArg.Value = "testValue";

                var formattedMessage = ArgHelper.FormatMessage(
                    "test {test}",
                    new[]
                {
                    new ArgPlaceholder()
                    {
                        Name        = "test",
                        Placeholder = "{test}",
                        Parameters  = null
                    },
                },
                    new IArg[]
                {
                    testArg
                });

                formattedMessage.Should().Be("test testValue");

                parametersChecked.Should().Be(1);
            }
示例#6
0
        public void StaticMemberAccess_BindTestMethod_Interface()
        {
            var arg = new TestArg() as ITestArg;

            engine.AddRestrictedHostObject("arg", arg);
            Assert.AreEqual(StaticTestClass.StaticBindTestMethod(arg), engine.Evaluate("StaticTestClass.StaticBindTestMethod(arg)"));
        }
        public void ExplicitInterfaceMemberAccess_BindTestMethod_BaseClass()
        {
            var arg = new TestArg() as BaseTestArg;

            engine.AddRestrictedHostObject("arg", arg);
            Assert.AreEqual(testInterface.ExplicitInterfaceBindTestMethod(arg), engine.Evaluate("testInterface.ExplicitInterfaceBindTestMethod(arg)"));
        }
 public void FunctionWithArgTest()
 {
     var genericTestArg = new TestArg();
     Func<TestArg, TestClass> functionWithArg = TestClassConverter;
     var result = functionWithArg(genericTestArg);
     Assert.AreEqual(genericTestArg, result.Arg);
 }
示例#9
0
        public List <TestResultModel> GetTestSqlData(TestArg arg)
        {
            TestCoreSqlDao         testSqlDao = new TestCoreSqlDao();
            List <TestResultModel> result     = testSqlDao.GetTestSqlData(arg);

            return(result);
        }
 public void ConverterTest()
 {
     var genericTestArg = new TestArg();
     Converter<TestArg, TestClass> convertTestArgToTestClass = TestClassConverter;
     var result = convertTestArgToTestClass(genericTestArg);
     Assert.AreEqual(genericTestArg, result.Arg);
 }
示例#11
0
        public IActionResult Case(TestArg arg)
        {
            try
            {
                //for (int i = 0; i < 20; i++)
                //{
                //    Thread.Sleep(1000);
                //    LogUtility.Info(i.ToString());
                //    //Console.WriteLine(i.ToString());
                //}

                //logger.Error("TT");
                //logger.Info(defaultCulture);
                //logger.Warn(defaultCulture);
                //logger.Debug(defaultCulture);
                //throw new ExecutionEngineException();
                TestService            testService = new TestService();
                List <TestResultModel> result      = testService.GetTestSqlData(arg);

                return(Ok(this.ThrowResult <List <TestResultModel> >(Enum.ApiStatusEnum.OK, "", result)));
            }
            catch (Exception ex)
            {
                return(Ok(this.ThrowResult <string>(Enum.ApiStatusEnum.InternalServerError, ex.ToString(), string.Empty)));
            }
        }
        public void ExplicitBaseInterfaceMemberAccess_ExtensionBindTestMethod_Interface()
        {
            var arg = new TestArg() as ITestArg;

            engine.AddRestrictedHostObject("arg", arg);
            Assert.AreEqual(testInterface.ExplicitBaseInterfaceExtensionBindTestMethod(arg), engine.Evaluate("testInterface.ExplicitBaseInterfaceExtensionBindTestMethod(arg)"));
        }
        public void GenericFunctionWithArgDelegate()
        {
            var genericTestArg = new TestArg();
            GenericFunctionWithGenericArg <TestClass, TestArg> genericFunctionWithGenericArg = MyGenericFunctionWithGenericArg;
            var returnValue = genericFunctionWithGenericArg(genericTestArg);

            Assert.AreEqual(genericTestArg, returnValue.Arg);
        }
        public void ConverterTest()
        {
            var genericTestArg = new TestArg();
            Converter <TestArg, TestClass> convertTestArgToTestClass = TestClassConverter;
            var result = convertTestArgToTestClass(genericTestArg);

            Assert.AreEqual(genericTestArg, result.Arg);
        }
        public void FunctionWithArgTest()
        {
            var genericTestArg = new TestArg();
            Func <TestArg, TestClass> functionWithArg = TestClassConverter;
            var result = functionWithArg(genericTestArg);

            Assert.AreEqual(genericTestArg, result.Arg);
        }
 public void ActionWithArgTest()
 {
     TestArg testGenericDelegateArg = null;
     var genericTestArg = new TestArg();
     Action<TestArg> actionWithTestArg = a => testGenericDelegateArg = a;
     actionWithTestArg(genericTestArg);
     Assert.AreEqual(genericTestArg, testGenericDelegateArg);
 }
示例#17
0
        public void ActionWithArgTest()
        {
            TestArg          testGenericDelegateArg = null;
            var              genericTestArg         = new TestArg();
            Action <TestArg> actionWithTestArg      = a => testGenericDelegateArg = a;

            actionWithTestArg(genericTestArg);
            Assert.AreEqual(genericTestArg, testGenericDelegateArg);
        }
示例#18
0
            public void Should_FormatMessage_ManyArgs_ManyPlaceholders()
            {
                var parametersChecked1 = 0;

                var testArg1 = new TestArg(parameters =>
                {
                    parameters.Should().BeNull();
                    parametersChecked1++;
                })
                {
                    AllowedParameters = Array.Empty <string>(),
                    Name  = "test1",
                    Value = "testValue1",
                };

                var parametersChecked2 = 0;

                var testArg2 = new TestArg(parameters =>
                {
                    parameters.Should().BeNull();
                    parametersChecked2++;
                })
                {
                    AllowedParameters = Array.Empty <string>(),
                    Name  = "test2",
                    Value = "testValue2",
                };

                var formattedMessage = ArgHelper.FormatMessage(
                    "test {test1} {test2} {test1}",
                    new[]
                {
                    new ArgPlaceholder()
                    {
                        Name        = "test1",
                        Placeholder = "{test1}",
                        Parameters  = null
                    },
                    new ArgPlaceholder()
                    {
                        Name        = "test2",
                        Placeholder = "{test2}",
                        Parameters  = null
                    },
                },
                    new IArg[]
                {
                    testArg1,
                    testArg2
                });

                formattedMessage.Should().Be("test testValue1 testValue2 testValue1");

                parametersChecked1.Should().Be(1);
                parametersChecked2.Should().Be(1);
            }
示例#19
0
        /// <summary>
        /// Test
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public List <TestResultModel> GetTestProxyData(TestArg arg)
        {
            string apiUrl = URLVariable.ApiRootUrl + URLVariable.TestData;

            apiUrl = "https://demos.telerik.com/kendo-ui/service/Products";
            var apiResult = new ApiResult <List <TestResultModel> >();

            this.porxyHelper.ProxyPostAction <List <TestResultModel> >
                (apiUrl, JsonSerializer.objToJsonString(arg), Variable.Enum.ContentTypeEnum.Json, ref apiResult);
            return(apiResult.Data);
        }
示例#20
0
            public void Should_FormatMessage_NotPassParametersToArgs_When_AtLeastOneParameterNotAllowed()
            {
                var parameters = new Dictionary <string, string>()
                {
                    ["param1"] = "paramValue1",
                    ["param2"] = "paramValue2",
                };

                var parametersChecked1 = 0;

                var testArg1 = new TestArg(p =>
                {
                    p.Should().BeSameAs(parameters);
                    parametersChecked1++;
                })
                {
                    AllowedParameters = new[] { "param1", "param2" },
                    Name  = "test1",
                    Value = "testValue1",
                };

                var formattedMessage = ArgHelper.FormatMessage(
                    "test1 {test1|param1=paramValue1|param2=paramValue2} {test1|param1=paramValue1|param2=paramValue2|invalidParameter=someValue}",
                    new[]
                {
                    new ArgPlaceholder()
                    {
                        Name        = "test1",
                        Placeholder = "{test1|param1=paramValue1|param2=paramValue2}",
                        Parameters  = parameters,
                    },
                    new ArgPlaceholder()
                    {
                        Name        = "test1",
                        Placeholder = "{test1|param1=paramValue1|param2=paramValue2|invalidParameter=someValue}",
                        Parameters  = new Dictionary <string, string>()
                        {
                            ["param1"]           = "paramValue1",
                            ["param2"]           = "paramValue2",
                            ["invalidParameter"] = "someValue"
                        },
                    },
                },
                    new IArg[]
                {
                    testArg1
                });

                formattedMessage.Should().Be("test1 testValue1 {test1|param1=paramValue1|param2=paramValue2|invalidParameter=someValue}");

                parametersChecked1.Should().Be(1);
            }
 public void ConverterTest()
 {
     var converterExecuted = false;
     var genericTestArg = new TestArg();
     Converter<TestArg, TestClass> convertTestArgToTestClass = a =>
     {
         converterExecuted = true;
         return new TestClass{Arg = a};
     };
     var result = convertTestArgToTestClass(genericTestArg);
     Assert.AreEqual(genericTestArg, result.Arg);
     Assert.IsTrue(converterExecuted);
 }
示例#22
0
        public IActionResult CasePost(TestArg arg)
        {
            try
            {
                TestService            testService = new TestService();
                List <TestResultModel> result      = testService.GetTestSqlData(arg);

                return(Ok(this.ThrowResult <List <TestResultModel> >(Enum.ApiStatusEnum.OK, "", result)));
            }
            catch (Exception ex)
            {
                return(Ok(this.ThrowResult <string>(Enum.ApiStatusEnum.InternalServerError, ex.ToString(), string.Empty)));
            }
        }
示例#23
0
        public void Should_NotPassParameters_When_ContainsInvalidParameters()
        {
            var argCount = 0;

            var arg = new TestArg(parameters => { argCount++; })
            {
                Name = "arg", Value = "value", AllowedParameters = new[] { "param" }
            };

            var result = MessageFormatter.Format("test {arg|param=x|someparameter=somevalue}", new IMessageArg[] { arg });

            Assert.Equal("test {arg|param=x|someparameter=somevalue}", result);
            Assert.Equal(0, argCount);
        }
        public void ConverterTest()
        {
            var converterExecuted = false;
            var genericTestArg    = new TestArg();
            Converter <TestArg, TestClass> convertTestArgToTestClass = delegate(TestArg arg)
            {
                converterExecuted = true;
                return(new TestClass {
                    Arg = arg
                });
            };
            var result = convertTestArgToTestClass(genericTestArg);

            Assert.AreEqual(genericTestArg, result.Arg);
            Assert.IsTrue(converterExecuted);
        }
        public void FunctionWithArgTest()
        {
            var functionExecuted = false;
            var genericTestArg   = new TestArg();
            Func <TestArg, TestClass> functionWithArg = delegate(TestArg arg)
            {
                functionExecuted = true;
                return(new TestClass {
                    Arg = arg
                });
            };
            var result = functionWithArg(genericTestArg);

            Assert.AreEqual(genericTestArg, result.Arg);
            Assert.IsTrue(functionExecuted);
        }
示例#26
0
        public void Should_Stringify_When_SingleVariable_ManyOccurances()
        {
            var argCount = 0;

            var arg = new TestArg(parameters =>
            {
                Assert.Null(parameters);
                argCount++;
            })
            {
                Name = "arg", Value = "value"
            };

            var result = MessageFormatter.Format("test {arg} {arg}", new IMessageArg[] { arg });

            Assert.Equal("test value value", result);
            Assert.Equal(1, argCount);
        }
示例#27
0
        public void Should_ReturnSameString_When_UsingInvalidName()
        {
            var argCount = 0;

            var arg = new TestArg(parameters =>
            {
                Assert.Null(parameters);
                argCount++;
            })
            {
                Name = "arg", Value = "value"
            };

            var result = MessageFormatter.Format("test {argument}", new IMessageArg[] { arg });

            Assert.Equal("test {argument}", result);
            Assert.Equal(0, argCount);
        }
示例#28
0
        public void Should_PassParameters_When_SingleParameter()
        {
            var argCount = 0;

            var arg = new TestArg(parameters =>
            {
                Assert.Equal(1, parameters.Count);
                Assert.Equal("x", parameters["param"]);
                argCount++;
            })
            {
                Name = "arg", Value = "value", AllowedParameters = new[] { "param" }
            };

            var result = MessageFormatter.Format("test {arg|param=x}", new IMessageArg[] { arg });

            Assert.Equal("test value", result);
            Assert.Equal(1, argCount);
        }
示例#29
0
        public void ConstructValidTests()
        {
            var constructor = new ObjectConstructor();
            var testarg     = new TestArg()
            {
                Text = "amagad"
            };
            var testarg2 = new TestArg2()
            {
                Text = "amagad"
            };

            //anyone can construct on object!
            constructor.Construct(typeof(TestClass1), testarg);
            constructor.Construct(typeof(TestClass1), testarg2);

            //basic case - identical Type parameter
            var instance = (TestClass2)constructor.Construct(typeof(TestClass2), testarg);

            Assert.AreEqual(instance.A.Text, "amagad");
            //also allowed because testarg2 is a testarg derrived class
            constructor.Construct(typeof(TestClass2), testarg2);

            //not allowed because class 3 explicitly requires a TestArg2
            Assert.Throws <ObjectLacksCompatibleConstructorException>(() => constructor.Construct(typeof(TestClass3), testarg));

            //allowed
            constructor.Construct(typeof(TestClass3), testarg2);

            //valid because even though both constructors are valid there is one that matches EXACTLY on Type
            constructor.Construct(typeof(TestClass4), testarg2);

            var testarg3 = new TestArg3();

            //not valid because there are 2 constructors that are both base classes of TestArg3 so ObjectConstructor doesn't know which to invoke
            var ex = Assert.Throws <ObjectLacksCompatibleConstructorException>(() => constructor.Construct(typeof(TestClass4), testarg3));

            Assert.IsTrue(ex.Message.Contains("Could not pick the correct constructor between"));

            //exactly the same as the above case but one constructor has been decorated with ImportingConstructor
            constructor.Construct(typeof(TestClass5), testarg3);
        }
示例#30
0
        /// <summary>
        /// 查詢 Get
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public List <TestResultModel> GetTestSqlData(TestArg arg)
        {
            string sql = @"select ID as Id,NAME as Name,SEQ as Seq from TEST where ID = @Id ";

            if (string.IsNullOrEmpty(arg.Id))
            {
                sql = @"select ID as Id,NAME as Name,SEQ as Seq from TEST ";
            }
            DynamicParameters paramter = new DynamicParameters();

            paramter.Add("@Id", arg.Id);

            var result = new List <TestResultModel>();

            using (SqlConnection conexao = new SqlConnection(ConfigProvider.Default))
            {
                result = conexao.Query <TestResultModel>(sql, paramter).AsList <TestResultModel>();
            }

            return(result);
        }
示例#31
0
            public void Should_FormatMessage_PassParametersToArgs()
            {
                var parameters = new Dictionary <string, string>()
                {
                    ["param1"] = "paramValue1",
                };

                var parametersChecked1 = 0;

                var testArg1 = new TestArg(p =>
                {
                    p.Should().BeSameAs(parameters);
                    parametersChecked1++;
                })
                {
                    AllowedParameters = new[] { "param1" },
                    Name  = "test1",
                    Value = "testValue1",
                };

                var formattedMessage = ArgHelper.FormatMessage(
                    "test1 {test1|param1=paramValue1}",
                    new[]
                {
                    new ArgPlaceholder()
                    {
                        Name        = "test1",
                        Placeholder = "{test1|param1=paramValue1}",
                        Parameters  = parameters
                    },
                },
                    new IArg[]
                {
                    testArg1
                });

                formattedMessage.Should().Be("test1 testValue1");

                parametersChecked1.Should().Be(1);
            }
示例#32
0
        /// <summary>
        /// 更新Update
        /// </summary>
        /// <param name="arg"></param>
        /// <returns></returns>
        public bool UpdateTestData(TestArg arg)
        {
            string sql = @"update ...";

            DynamicParameters paramter = new DynamicParameters();

            paramter.Add("@Id", "XXXXX");

            using (SqlConnection conexao = new SqlConnection(ConfigProvider.Default))
            {
                IDbTransaction tran = conexao.BeginTransaction();
                try
                {
                    conexao.Execute(sql, paramter, tran);
                    tran.Commit();
                    return(true);
                }
                catch (Exception ex)
                {
                    tran.Rollback();
                    return(false);
                }
            }
        }
 public void StaticMemberAccess_BindTestMethod_Interface()
 {
     var arg = new TestArg() as ITestArg;
     engine.AddRestrictedHostObject("arg", arg);
     Assert.AreEqual(StaticTestClass.StaticBindTestMethod(arg), engine.Evaluate("StaticTestClass.StaticBindTestMethod(arg)"));
 }
 public void ExplicitInterfaceMemberAccess_BindTestMethod_Interface()
 {
     var arg = new TestArg() as ITestArg;
     engine.AddRestrictedHostObject("arg", arg);
     Assert.AreEqual(testInterface.ExplicitInterfaceBindTestMethod(arg), engine.Evaluate("testInterface.ExplicitInterfaceBindTestMethod(arg)"));
 }
 public void ExplicitBaseInterfaceMemberAccess_ExtensionBindTestMethod_BaseClass()
 {
     var arg = new TestArg() as BaseTestArg;
     engine.AddRestrictedHostObject("arg", arg);
     Assert.AreEqual(testInterface.ExplicitBaseInterfaceExtensionBindTestMethod(arg), engine.Evaluate("testInterface.ExplicitBaseInterfaceExtensionBindTestMethod(arg)"));
 }
 public void BaseMemberAccess_ExtensionBindTestMethod_Interface()
 {
     var arg = new TestArg() as ITestArg;
     engine.AddRestrictedHostObject("arg", arg);
     Assert.AreEqual(testObject.BaseExtensionBindTestMethod(arg), engine.Evaluate("testObject.BaseExtensionBindTestMethod(arg)"));
 }
 TestClass TestClassConverter(TestArg arg)
 {
     return new TestClass {Arg = arg};
 }
示例#38
0
 public TestClass2(TestArg a)
 {
     A = a;
 }
 public void FunctionWithArgTest()
 {
     var functionExecuted = false;
     var genericTestArg = new TestArg();
     Func<TestArg, TestClass> functionWithArg = a =>
     {
         functionExecuted = true;
         return new TestClass{Arg = a};
     };
     var result = functionWithArg(genericTestArg);
     Assert.AreEqual(genericTestArg, result.Arg);
     Assert.IsTrue(functionExecuted);
 }
示例#40
0
 public TestClass5(TestArg2 a)
 {
     A = a;
 }
 public void BaseMemberAccess_BindTestMethod_BaseClass()
 {
     var arg = new TestArg() as BaseTestArg;
     engine.AddRestrictedHostObject("arg", arg);
     Assert.AreEqual(testObject.BaseBindTestMethod(arg), engine.Evaluate("testObject.BaseBindTestMethod(arg)"));
 }
 void MyActionWithArg(TestArg arg)
 {
     testGenericDelegateArg = arg;
 }