예제 #1
0
        public void CommitStaticClassInvokeWith()
        {
            var expected           = "DateTime";
            var expectedMethodName = "MethodName";
            var expectedPrimitive  = 123.456d;
            var binder             = testVarCreate.StaticClass(expected).Invoke(expectedMethodName).With(expectedPrimitive);
            var result             = binder.Commit();

            Assert.AreSame(this.methodVarCreate, result);

            Assert.IsNotEmpty(methodVarCreate.StatementsOfType <CodeVariableDeclarationStatement>().Where(e => e.Name == "variableNameCreate"));
            AssertEx.That(methodVarCreate.StatementsOfType <CodeVariableDeclarationStatement>()
                          .Where().Expression <CodeMethodInvokeExpression>(Is.MethodNamed(expectedMethodName)).WasFound(1)
                          .Assert());
            AssertEx.That(methodVarCreate.StatementsOfType <CodeVariableDeclarationStatement>()
                          .Where().Expression <CodeMethodInvokeExpression>(Contains.MethodPrimitiveParameter(expectedPrimitive)).WasFound(1)
                          .Assert());


            // no create
            binder = testVarNoCreate.StaticClass(expected).Invoke(expectedMethodName).With(expectedPrimitive);
            result = binder.Commit();
            Assert.AreSame(this.methodVarNoCreate, result);

            AssertEx.That(methodVarNoCreate.StatementsOfType <CodeAssignStatement>().Where()
                          .ExpressionLeft <CodeVariableReferenceExpression>(Is.VarRefNamed("variableNameNoCreate")).WasFound()
                          .ExpressionRight <CodeMethodInvokeExpression>(Is.MethodNamed(expectedMethodName)).WasFound()
                          .Assert());
        }