Ejemplo n.º 1
0
        /// <summary>
        /// Runs specified test.
        /// </summary>
        private void RunTest(
            string targetRule,
            string comment,
            Dictionary <string, object> customSettings,
            int errorCount,
            string description,
            string sourceCode)
        {
            if (File.Exists(m_tempFileName))
            {
                File.Delete(m_tempFileName);
            }

            File.WriteAllText(m_tempFileName, sourceCode, Encoding.UTF8);

            StyleCopPlusRunner runner = new StyleCopPlusRunner();

            runner.Run(
                m_tempFileName,
                new SpecialRunningParameters
            {
                OnlyEnabledRule = targetRule,
                CustomSettings  = customSettings
            });

            string message;

            if (String.IsNullOrEmpty(comment))
            {
                message = String.Format(
                    "{0}: {1}",
                    targetRule,
                    description);
            }
            else
            {
                message = String.Format(
                    "{0} // {1}: {2}",
                    targetRule,
                    comment,
                    description);
            }

            Assert.AreEqual(
                errorCount,
                runner.Violations.Count,
                message);

            for (int i = 0; i < errorCount; i++)
            {
                runner.Violations.Remove(targetRule);
            }

            Assert.AreEqual(
                0,
                runner.Violations.Count,
                message);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs specified test.
        /// </summary>
        private void RunTest(
            string targetRule,
            string comment,
            Dictionary<string, object> customSettings,
            int errorCount,
            string description,
            string sourceCode)
        {
            if (File.Exists(m_tempFileName))
            {
                File.Delete(m_tempFileName);
            }

            File.WriteAllText(m_tempFileName, sourceCode, Encoding.UTF8);

            StyleCopPlusRunner runner = new StyleCopPlusRunner();
            runner.Run(
                m_tempFileName,
                new SpecialRunningParameters
                {
                    OnlyEnabledRule = targetRule,
                    CustomSettings = customSettings
                });

            string message;
            if (String.IsNullOrEmpty(comment))
            {
                message = String.Format(
                    "{0}: {1}",
                    targetRule,
                    description);
            }
            else
            {
                message = String.Format(
                    "{0} // {1}: {2}",
                    targetRule,
                    comment,
                    description);
            }

            Assert.AreEqual(
                errorCount,
                runner.Violations.Count,
                message);

            for (int i = 0; i < errorCount; i++)
            {
                runner.Violations.Remove(targetRule);
            }

            Assert.AreEqual(
                0,
                runner.Violations.Count,
                message);
        }