public void Should_Merge_If_Property_Element_Merge()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            appOptions.Exclude = new string[] { "global" };
            var stringArrayElement = XElement.Parse($@"
<Root defaultMerge='false'>
  <Exclude merge='true'>
    1
    2
  </Exclude>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                stringArrayElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(new string[] { "global", "1", "2" }, appOptions.Exclude);
        }
        public void Should_Not_Throw_If_Merge_Current_Null_String_Array_Type()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            appOptions.Exclude = null;
            var stringArrayElement = XElement.Parse($@"
<Root>
  <Exclude merge='true'>
    1
    2
  </Exclude>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                stringArrayElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(new string[] { "1", "2" }, appOptions.Exclude);
        }
        public void Should_Overwrite_String_Array_By_Default()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            appOptions.Exclude = new string[] { "global" };
            var stringArrayElement = XElement.Parse($@"
<Root>
  <Exclude>
    1
    2
  </Exclude>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                stringArrayElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(new string[] { "1", "2" }, appOptions.Exclude);
        }
        public void Should_Use_Global_Settings_If_No_Project_Level_Or_FCC_Settings_Files()
        {
            var mockAppOptions = new Mock <IAppOptions>(MockBehavior.Strict);
            var appOptions     = mockAppOptions.Object;

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(appOptions, new List <XElement>(), null);

            Assert.AreSame(appOptions, mergedSettings);
        }
        public void Should_Overwrite_GlobalOptions_Bool_Properties_From_Settings_File()
        {
            var mockAppOptions = new Mock <IAppOptions>(MockBehavior.Strict);

            mockAppOptions.SetupSet(o => o.IncludeReferencedProjects = true);
            var appOptions = mockAppOptions.Object;

            var settingsMerger      = new SettingsMerger(null);
            var settingsFileElement = CreateIncludeReferencedProjectsElement(true);
            var mergedSettings      = settingsMerger.Merge(appOptions, new List <XElement> {
                settingsFileElement
            }, null);

            Assert.AreSame(appOptions, mergedSettings);
        }
        public void Should_Overwrite_GlobalOptions_Bool_Properties_From_Project(bool last)
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            var settingsMerger      = new SettingsMerger(null);
            var settingsFileElement = CreateIncludeReferencedProjectsElement(!last);
            var projectElement      = CreateIncludeReferencedProjectsElement(last);
            var mergedSettings      = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
                settingsFileElement
            },
                projectElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(last, appOptions.IncludeReferencedProjects);
        }
        public void Should_Overwrite_String_Properties()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            var stringElement = XElement.Parse($@"
<Root>
    <ToolsDirectory>ToolsDirectory</ToolsDirectory>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                stringElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual("ToolsDirectory", appOptions.ToolsDirectory);
        }
        public void Should_Overwrite_Enum_Properties()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            var enumElement = XElement.Parse($@"
<Root>
    <RunMsCodeCoverage>IfInRunSettings</RunMsCodeCoverage>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                enumElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(RunMsCodeCoverage.IfInRunSettings, appOptions.RunMsCodeCoverage);
        }
        public void Should_Overwrite_Int_Properties()
        {
            var mockAppOptions = new Mock <IAppOptions>();

            mockAppOptions.SetupAllProperties();
            var appOptions = mockAppOptions.Object;

            var intElement = XElement.Parse($@"
<Root>
    <ThresholdForCyclomaticComplexity>123</ThresholdForCyclomaticComplexity>
</Root>
");

            var settingsMerger = new SettingsMerger(null);
            var mergedSettings = settingsMerger.Merge(
                appOptions,
                new List <XElement> {
            },
                intElement);

            Assert.AreSame(appOptions, mergedSettings);
            Assert.AreEqual(123, appOptions.ThresholdForCyclomaticComplexity);
        }