Exemplo n.º 1
0
        public void Should_Add_The_Test_Assembly_Regex_Escaped_To_Module_Excludes_When_IncludeTestAssembly_Is_False(bool includeTestAssembly1, bool includeTestAssembly2)
        {
            var testContainers = new List <ITestContainer>()
            {
                CreateTestContainer("Source1"),
                CreateTestContainer("Source2"),
            };

            Dictionary <string, IUserRunSettingsProjectDetails> userRunSettingsProjectDetailsLookup = new Dictionary <string, IUserRunSettingsProjectDetails>
            {
                {
                    "Source1",
                    new TestUserRunSettingsProjectDetails
                    {
                        CoverageOutputFolder = "",
                        Settings             = new TestMsCodeCoverageOptions {
                            IncludeTestAssembly = includeTestAssembly1,
                            ModulePathsExclude  = new string[] { "ModulePathExclude" }
                        },
                        ExcludedReferencedProjects = new List <string>(),
                        IncludedReferencedProjects = new List <string>(),
                        TestDllFile = @"Some\Path1"
                    }
                },
                {
                    "Source2",
                    new TestUserRunSettingsProjectDetails
                    {
                        CoverageOutputFolder = "",
                        Settings             = new TestMsCodeCoverageOptions {
                            IncludeTestAssembly = includeTestAssembly2
                        },
                        ExcludedReferencedProjects = new List <string>(),
                        IncludedReferencedProjects = new List <string>(),
                        TestDllFile = @"Some\Path2"
                    }
                },
            };

            var testDlls = userRunSettingsProjectDetailsLookup.Select(kvp => kvp.Value.TestDllFile).ToList();

            string GetModulePathExcludeWhenExcludingTestAssembly(bool first)
            {
                var regexed = MsCodeCoverageRegex.RegexEscapePath(testDlls[first ? 0 : 1]);

                return(ModulePathElement(regexed));
            }

            var expectedModulePathExcludes1 = !includeTestAssembly1?GetModulePathExcludeWhenExcludingTestAssembly(true) : "";

            var expectedModulePathExcludes2 = !includeTestAssembly2?GetModulePathExcludeWhenExcludingTestAssembly(false) : "";

            var expectedModulePathExcludes = expectedModulePathExcludes1 + expectedModulePathExcludes2 + ModulePathElement("ModulePathExclude");

            var replacements = runSettingsTemplateReplacementsFactory.Create(testContainers, userRunSettingsProjectDetailsLookup, null);

            Assert.AreEqual(expectedModulePathExcludes, replacements.ModulePathsExclude);
        }
Exemplo n.º 2
0
        public void Should_Have_ModulePathsExclude_Replacements_From_ExcludedReferencedProjects_Settings_And_Excluded_Test_Assembly()
        {
            var msCodeCoverageOptions = new TestCoverageProjectOptions
            {
                ModulePathsExclude  = new[] { "FromSettings" },
                IncludeTestAssembly = false
            };

            var coverageProject = CreateCoverageProject(mock =>
            {
                mock.Setup(cp => cp.Settings).Returns(msCodeCoverageOptions);
                mock.Setup(cp => cp.ExcludedReferencedProjects).Returns(new List <string>
                {
                    "ModuleName"
                });
                mock.Setup(cp => cp.TestDllFile).Returns(@"Path\To\Test.dll");
            });

            var replacements = runSettingsTemplateReplacementsFactory.Create(coverageProject, null);
            var expectedModulePathsExclude = $"{ModulePathElement(MsCodeCoverageRegex.RegexModuleName("ModuleName"))}{ModulePathElement(MsCodeCoverageRegex.RegexEscapePath(@"Path\To\Test.dll"))}{ModulePathElement("FromSettings")}";

            Assert.AreEqual(expectedModulePathsExclude, replacements.ModulePathsExclude);
        }