Example #1
0
        public void ConfigurationFactoryShouldReturnConfigurationFromConfigurationFactoryProvider()
        {
            IRule rule = Mocker.DynamicMock <IRule>();
            IRuleConfiguration        config  = Mocker.DynamicMock <IRuleConfiguration>();
            IRuleConfigurationFactory factory = Mocker.DynamicMock <IRuleConfigurationFactory>();

            Expect.Call(_provider.GetRuleConfigurationFactoryFor(rule.GetType())).Return(factory).Repeat.Once();
            Expect.Call(factory.Get(rule.GetType())).Return(config).Repeat.Once();
            Expect.Call(_project.GetProjectRuleConfigurationOverrides()).Return(new IRuleConfigurationOverride[] {}).Repeat.Once();

            Mocker.ReplayAll();

            Assert.AreEqual(config, _configFactory.GetRuleConfigurationFor(rule.GetType()));

            Mocker.VerifyAll();
        }
Example #2
0
        public void WriteToShouldWriteXmlToDestination()
        {
            IRule rule = Mocker.StrictMock <IRule>();

            StringBuilder bldr = new StringBuilder();

            bldr.Append(@"<?xml version=""1.0"" encoding=""utf-8""?>");
            bldr.Append(@"<calidusproject>");
            bldr.Append("<settings>");
            bldr.Append(@"<IgnoreAssemblyFiles>true</IgnoreAssemblyFiles>");
            bldr.Append(@"<IgnoreDesignerFiles>false</IgnoreDesignerFiles>");
            bldr.Append(@"<IgnoreProgramFiles>true</IgnoreProgramFiles>");
            bldr.Append("</settings>");
            bldr.Append("<ignore>");
            bldr.Append(@"<file path=""main\file1.cs"" />");
            bldr.Append(@"<file path=""test\testfile.cs"" />");
            bldr.Append("</ignore>");
            bldr.Append("</calidusproject>");

            IList <String> fileList = new List <String>();

            fileList.Add(@"main\file1.cs");
            fileList.Add(@"test\testfile.cs");

            ICalidusProject project = Mocker.StrictMock <ICalidusProject>();

            Expect.Call(project.IgnoreAssemblyFiles).Return(true).Repeat.Once();
            Expect.Call(project.IgnoreDesignerFiles).Return(false).Repeat.Once();
            Expect.Call(project.IgnoreProgramFiles).Return(true).Repeat.Once();
            Expect.Call(project.IgnoredFiles).Return(fileList).Repeat.Once();

            Expect.Call(project.GetProjectRuleConfigurationOverrides()).Return(new IRuleConfigurationOverride[] {}).Repeat.Once();

            Mocker.ReplayAll();

            Stream            destination = new MemoryStream();
            XmlWriterSettings settings    = new XmlWriterSettings();

            settings.Encoding = Encoding.UTF8;
            XmlWriter writer = XmlTextWriter.Create(destination, settings);

            _manager.WriteTo(project, writer);

            destination.Position = 0;
            StreamReader reader = new StreamReader(destination);

            Assert.AreEqual(bldr.ToString(), reader.ReadToEnd());

            Mocker.VerifyAll();
        }
Example #3
0
        public void WriteShouldCallRulesSectionManagerToWriteRuleOverrides()
        {
            ICalidusProject            project = Mocker.DynamicMock <ICalidusProject>();
            IRuleConfigurationOverride config  = Mocker.DynamicMock <IRuleConfigurationOverride>();

            Expect.Call(project.IgnoredFiles).Return(new String[] {}).Repeat.Once();
            Expect.Call(project.GetProjectRuleConfigurationOverrides()).Return(new[] { config }).Repeat.Once();
            Expect.Call(() => _rulesSectionManager.WriteTo(new[] { config }, null)).IgnoreArguments().Repeat.Once();

            Mocker.ReplayAll();

            MemoryStream stream = new MemoryStream();
            XmlWriter    writer = XmlTextWriter.Create(stream);

            _manager.WriteTo(project, writer);

            Mocker.VerifyAll();
        }
Example #4
0
        /// <summary>
        /// Writes the calidus project to the specified xml writer
        /// </summary>
        /// <param name="project">The project to write</param>
        /// <param name="writer">The writer to write to</param>
        public void WriteTo(ICalidusProject project, XmlWriter writer)
        {
            if (writer.Settings == null || writer.Settings.Encoding != Encoding.UTF8)
            {
                throw new CalidusException("The target XmlWriter must be set to write to UTF8");
            }

            XDocument doc = new XDocument();

            //write root element
            XElement root = new XElement("calidusproject");

            //write settings
            XElement ignoreAssemblyFiles = new XElement("IgnoreAssemblyFiles", project.IgnoreAssemblyFiles);
            XElement ignoreDesignerFiles = new XElement("IgnoreDesignerFiles", project.IgnoreDesignerFiles);
            XElement ignoreProgramFiles  = new XElement("IgnoreProgramFiles", project.IgnoreProgramFiles);

            XElement settings = new XElement("settings");

            settings.Add(ignoreAssemblyFiles);
            settings.Add(ignoreDesignerFiles);
            settings.Add(ignoreProgramFiles);

            root.Add(settings);

            //write full-file ignores
            XElement ignores = new XElement("ignore");

            foreach (String aFile in project.IgnoredFiles)
            {
                XElement file = new XElement("file", new XAttribute("path", aFile));
                ignores.Add(file);
            }
            root.Add(ignores);

            _rulesSectionManager.WriteTo(project.GetProjectRuleConfigurationOverrides(), root);

            //write document to file
            doc.Add(root);
            doc.WriteTo(writer);
            writer.Flush();
        }
        /// <summary>
        /// Gets the configuration for the specified rule type
        /// </summary>
        /// <param name="aType">The rule type</param>
        /// <returns>The rule configuration</returns>
        public IRuleConfiguration GetRuleConfigurationFor(Type aType)
        {
            IRuleConfigurationFactory factory = _provider.GetRuleConfigurationFactoryFor(aType);

            if (factory == null)
            {
                throw new CalidusException("No default configuration could be loaded for rule " + aType.FullName);
            }

            //determine default and overridden configuration
            IRuleConfiguration         defaultConfig  = factory.Get(aType);
            IRuleConfigurationOverride overrideConfig = _project.GetProjectRuleConfigurationOverrides().FirstOrDefault <IRuleConfigurationOverride>(p => p.Rule.FullName.Equals(aType.FullName));

            IRuleConfiguration actualConfig = defaultConfig;

            if (overrideConfig != null)
            {
                IList <IRuleConfigurationParameter> parameters = new List <IRuleConfigurationParameter>();
                foreach (IRuleConfigurationParameter aParam in overrideConfig.Parameters)
                {
                    //get the default value
                    IRuleConfigurationParameter defaultConfigParameter = defaultConfig.Parameters.FirstOrDefault <IRuleConfigurationParameter>(p => p.Name.Equals(aParam.Name));
                    //create an overridden parameter with the overridden value
                    DefaultRuleConfigurationParameter overriddenParam = new DefaultRuleConfigurationParameter();
                    overriddenParam.Name          = defaultConfigParameter.Name;
                    overriddenParam.ParameterType = defaultConfigParameter.ParameterType;
                    overriddenParam.Value         = aParam.Value;
                    //add the overridden parameter
                    parameters.Add(overriddenParam);
                }

                actualConfig = new DefaultRuleConfiguration(aType, defaultConfig.Description, parameters);
            }

            return(actualConfig);
        }
Example #6
0
 /// <summary>
 /// Gets the list of rule configurations that were changed from the defaults
 /// </summary>
 /// <returns>The list of configurations</returns>
 public IEnumerable <IRuleConfigurationOverride> GetProjectRuleConfigurationOverrides()
 {
     return(_project.GetProjectRuleConfigurationOverrides());
 }