public void AddMethodFor2Test(bool isCSharp)
        {
            string baseMethodName = "MyMethod"; // required param

            string comments      = this.TestContext.DataRow["comments"].ToString();
            string paramDeclArgs = this.TestContext.DataRow["parameterDeclaration"].ToString();

            CodeParameterDeclarationExpression parameterDeclaration = null;

            if (paramDeclArgs == "")
            {
                parameterDeclaration = new CodeParameterDeclarationExpression();
            }
            else if (paramDeclArgs != "null")
            {
                string[] args = paramDeclArgs.Split(new char[] { ',' });
                parameterDeclaration = new CodeParameterDeclarationExpression(args[0], args[1]);
            }

            if (comments == "null")
            {
                comments = null;
            }

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            target.AddMethodFor(baseMethodName, parameterDeclaration, comments);

            Assert.IsNotNull(GetSnippet(target, baseMethodName), "Could not find generated method, Language: " + (isCSharp ? "C#" : "VB"));
        }
        public void NotificationMethodGeneratorConstructorTest()
        {
            bool isCSharp = false;
            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            Assert.IsNotNull(target.PartialMethodsSnippetBlock);
        }
        public void GetMethodInvokeExpressionStatementForTest(bool isCSharp)
        {
            string comments = this.TestContext.DataRow["comments"].ToString();

            string[] baseMethodNames = this.TestContext.DataRow["baseMethodNames"].ToString().Split(new char[] { ',' });
            string   paramDeclsArgs  = this.TestContext.DataRow["parameters"].ToString();

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            CodeParameterDeclarationExpressionCollection expressions = GetCodeParameterDeclaraionExpressions(paramDeclsArgs);

            CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[expressions.Count];

            expressions.CopyTo(parameters, 0);

            foreach (string baseMethodName in baseMethodNames)
            {
                target.AddMethodFor(baseMethodName, expressions, comments);

                CodeExpressionStatement    actual           = target.GetMethodInvokeExpressionStatementFor(baseMethodName);
                CodeMethodInvokeExpression actualExpression = actual.Expression as CodeMethodInvokeExpression;

                Assert.AreEqual(actualExpression.Method.MethodName, "On" + baseMethodName);

                for (int idx = 0; idx < parameters.Length; idx++)
                {
                    string paramName = ((CodeArgumentReferenceExpression)actualExpression.Parameters[idx]).ParameterName;
                    Assert.AreEqual(paramName, parameters[idx].Name);
                }
            }
        }
        /// <summary>
        /// Checks if a code snippet was generated for the specified method name.
        /// This code does not check whether the code snippet is valir or not.
        /// </summary>
        private static CodeSnippetTypeMember GetSnippet(NotificationMethodGenerator target, string baseMethodName)
        {
            CodeSnippetTypeMember genMethod = null;

            foreach (CodeTypeMember member in target.PartialMethodsSnippetBlock)
            {
                genMethod = member as CodeSnippetTypeMember;
                if (genMethod != null && genMethod.Text.Contains(baseMethodName))
                {
                    return(genMethod);
                }
                genMethod = null;
            }

            return(genMethod);
        }
        public void AddMethodFor1Test(bool isCSharp)
        {
            string baseMethodName = "MyMethod"; // required param

            string comments = this.TestContext.DataRow["comments"].ToString();

            if (comments == "null")
            {
                comments = null;
            }

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            target.AddMethodFor(baseMethodName, comments);

            Assert.IsNotNull(GetSnippet(target, baseMethodName), "Could not find generated method, Language: " + (isCSharp ? "C#" : "VB"));
        }
        public void PartialMethodsSnippetBlockTest(bool isCSharp)
        {
            string comments = this.TestContext.DataRow["comments"].ToString();

            string[] baseMethodNames = this.TestContext.DataRow["baseMethodNames"].ToString().Split(new char[] { ',' });
            string   paramDeclsArgs  = this.TestContext.DataRow["parameters"].ToString();

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));
            CodeParameterDeclarationExpressionCollection expressions = GetCodeParameterDeclaraionExpressions(paramDeclsArgs);

            foreach (string baseMethodName in baseMethodNames)
            {
                target.AddMethodFor(baseMethodName, expressions, comments);
            }

            // do verification ...
            if (XmlReader == null)
            {
                XmlReader = XmlReader.Create(this.TestContext.TestDeploymentDir + "\\NotificationMethodGeneratorTestCodeSnippets.xml");
            }

            do
            {
                XmlReader.Read();
            }while (!XmlReader.EOF && XmlReader.NodeType != XmlNodeType.CDATA);
            string snippetstr = "";

            foreach (CodeSnippetTypeMember snippet in target.PartialMethodsSnippetBlock)
            {
                foreach (CodeCommentStatement comment in snippet.Comments)
                {
                    if (!isCSharp)
                    {
                        Assert.IsTrue(comment.Comment.Text.StartsWith(" "), "All VB XML Doc comments must be prefixed with a space");
                    }
                    snippetstr += comment.Comment.Text.TrimStart();
                }
                snippetstr += snippet.Text;
            }
            Assert.AreEqual(snippetstr.Replace("\r\n", "").TrimEnd(), XmlReader.Value.Replace("\n", ""));
        }
        public void PartialMethodsSnippetBlockTest(bool isCSharp)
        {
            string comments = this.TestContext.DataRow["comments"].ToString();
            string[] baseMethodNames = this.TestContext.DataRow["baseMethodNames"].ToString().Split(new char[] { ',' });
            string paramDeclsArgs = this.TestContext.DataRow["parameters"].ToString();

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));
            CodeParameterDeclarationExpressionCollection expressions = GetCodeParameterDeclaraionExpressions(paramDeclsArgs);

            foreach (string baseMethodName in baseMethodNames)
            {
                target.AddMethodFor(baseMethodName, expressions, comments);
            }

            // do verification ...
            if (XmlReader == null)
            {
                XmlReader = XmlReader.Create(this.TestContext.TestDeploymentDir + "\\NotificationMethodGeneratorTestCodeSnippets.xml");
            }

            do
            {
                XmlReader.Read();
            }
            while (!XmlReader.EOF && XmlReader.NodeType != XmlNodeType.CDATA);
            string snippetstr = "";

            foreach (CodeSnippetTypeMember snippet in target.PartialMethodsSnippetBlock)
            {
                foreach (CodeCommentStatement comment in snippet.Comments)
                {
                    if (!isCSharp)
                    {
                        Assert.IsTrue(comment.Comment.Text.StartsWith(" "), "All VB XML Doc comments must be prefixed with a space");
                    }
                    snippetstr += comment.Comment.Text.TrimStart();
                }
                snippetstr += snippet.Text;
            }
            Assert.AreEqual(snippetstr.Replace("\r\n", "").TrimEnd(), XmlReader.Value.Replace("\n", ""));
        }
        public void OnCreatedMethodInvokeExpressionTest(bool isCSharp)
        {
            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            Assert.AreEqual(target.OnCreatedMethodInvokeExpression.Method.MethodName, "OnCreated");
        }
 public void NotificationMethodGeneratorConstructorTest()
 {
     bool isCSharp = false;
     NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));
     Assert.IsNotNull(target.PartialMethodsSnippetBlock);
 }
        /// <summary>
        /// Checks if a code snippet was generated for the specified method name.
        /// This code does not check whether the code snippet is valir or not.
        /// </summary>
        private static CodeSnippetTypeMember GetSnippet(NotificationMethodGenerator target, string baseMethodName)
        {
            CodeSnippetTypeMember genMethod = null;

            foreach (CodeTypeMember member in target.PartialMethodsSnippetBlock)
            {
                genMethod = member as CodeSnippetTypeMember;
                if (genMethod != null && genMethod.Text.Contains(baseMethodName))
                {
                    return genMethod;
                }
                genMethod = null;
            }

            return genMethod;
        }
        public void AddMethodFor3Test(bool isCSharp)
        {
            string baseMethodName = "MyMethod"; // required param

            string comments = this.TestContext.DataRow["comments"].ToString();
            string paramDeclsArgs = this.TestContext.DataRow["parameters"].ToString();

            CodeParameterDeclarationExpressionCollection parameters = GetCodeParameterDeclaraionExpressions(paramDeclsArgs);

            if (comments == "null") comments = null;

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            target.AddMethodFor(baseMethodName, parameters, comments);

            Assert.IsNotNull(GetSnippet(target, baseMethodName), "Could not find generated method, Language: " + (isCSharp ? "C#" : "VB"));
        }
        public void AddMethodFor2Test(bool isCSharp)
        {
            string baseMethodName = "MyMethod"; // required param

            string comments = this.TestContext.DataRow["comments"].ToString();
            string paramDeclArgs = this.TestContext.DataRow["parameterDeclaration"].ToString();

            CodeParameterDeclarationExpression parameterDeclaration = null;

            if (paramDeclArgs == "")
            {
                parameterDeclaration = new CodeParameterDeclarationExpression();
            }
            else if (paramDeclArgs != "null")
            {
                string[] args = paramDeclArgs.Split(new char[] { ',' });
                parameterDeclaration = new CodeParameterDeclarationExpression(args[0], args[1]);
            }

            if (comments == "null") comments = null;

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            target.AddMethodFor(baseMethodName, parameterDeclaration, comments);

            Assert.IsNotNull(GetSnippet(target, baseMethodName), "Could not find generated method, Language: " + (isCSharp ? "C#" : "VB"));
        }
        public void AddMethodFor1Test(bool isCSharp)
        {
            string baseMethodName = "MyMethod"; // required param

            string comments = this.TestContext.DataRow["comments"].ToString();

            if (comments == "null") comments = null;

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            target.AddMethodFor(baseMethodName, comments);

            Assert.IsNotNull(GetSnippet(target, baseMethodName), "Could not find generated method, Language: " + (isCSharp ? "C#" : "VB"));
        }
        public void GetMethodInvokeExpressionStatementForTest(bool isCSharp)
        {
            string comments = this.TestContext.DataRow["comments"].ToString();
            string[] baseMethodNames = this.TestContext.DataRow["baseMethodNames"].ToString().Split(new char[] { ',' });
            string paramDeclsArgs = this.TestContext.DataRow["parameters"].ToString();

            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            CodeParameterDeclarationExpressionCollection expressions = GetCodeParameterDeclaraionExpressions(paramDeclsArgs);
            CodeParameterDeclarationExpression[] parameters = new CodeParameterDeclarationExpression[expressions.Count];

            expressions.CopyTo(parameters, 0);

            foreach (string baseMethodName in baseMethodNames)
            {
                target.AddMethodFor(baseMethodName, expressions, comments);

                CodeExpressionStatement actual = target.GetMethodInvokeExpressionStatementFor(baseMethodName);
                CodeMethodInvokeExpression actualExpression = actual.Expression as CodeMethodInvokeExpression;

                Assert.AreEqual(actualExpression.Method.MethodName, "On" + baseMethodName);

                for (int idx = 0; idx < parameters.Length; idx++)
                {
                    string paramName = ((CodeArgumentReferenceExpression)actualExpression.Parameters[idx]).ParameterName;
                    Assert.AreEqual(paramName, parameters[idx].Name);
                }
            }
        }
        public void OnCreatedMethodInvokeExpressionTest(bool isCSharp)
        {
            NotificationMethodGenerator target = new NotificationMethodGenerator(CreateProxyGenerator(isCSharp));

            Assert.AreEqual(target.OnCreatedMethodInvokeExpression.Method.MethodName, "OnCreated");
        }