|
| 1 | +using NUnit.Framework; |
| 2 | +using FineCodeCoverage.Engine.MsTestPlatform.CodeCoverage; |
| 3 | +using System; |
| 4 | + |
| 5 | +namespace FineCodeCoverageTests.MsCodeCoverage |
| 6 | +{ |
| 7 | + public class BuiltInRunSettingsTemplate_ConfigureCustom_Tests |
| 8 | + { |
| 9 | + [Test] |
| 10 | + public void Should_Add_Replaceable_RunConfiguration_If_Not_Present() |
| 11 | + { |
| 12 | + var custom = $@" |
| 13 | + <RunSettings> |
| 14 | + <DataCollectionRunSettings> |
| 15 | + <DataCollectors> |
| 16 | + <DataCollector friendlyName='Code Coverage' enabled='true'> |
| 17 | + <Configuration> |
| 18 | + <Format>Cobertura</Format> |
| 19 | + </Configuration> |
| 20 | + </DataCollector> |
| 21 | + </DataCollectors> |
| 22 | + </DataCollectionRunSettings> |
| 23 | + </RunSettings>"; |
| 24 | + |
| 25 | + var replacements = new TestRunSettingsTemplateReplacements |
| 26 | + { |
| 27 | + ResultsDirectory = "results directory", |
| 28 | + TestAdapter = "ms collector path" |
| 29 | + }; |
| 30 | + |
| 31 | + |
| 32 | + var expected = $@" |
| 33 | + <RunSettings> |
| 34 | + <RunConfiguration> |
| 35 | + <ResultsDirectory>{replacements.ResultsDirectory}</ResultsDirectory> |
| 36 | + <TestAdaptersPaths>{replacements.TestAdapter}</TestAdaptersPaths> |
| 37 | + <CollectSourceInformation>False</CollectSourceInformation> |
| 38 | + </RunConfiguration> |
| 39 | + <DataCollectionRunSettings> |
| 40 | + <DataCollectors> |
| 41 | + <DataCollector friendlyName='Code Coverage' enabled='true'> |
| 42 | + <Configuration> |
| 43 | + <Format>Cobertura</Format> |
| 44 | + <FCCGenerated/> |
| 45 | + </Configuration> |
| 46 | + </DataCollector> |
| 47 | + </DataCollectors> |
| 48 | + </DataCollectionRunSettings> |
| 49 | + </RunSettings>"; |
| 50 | + |
| 51 | + ConfiguredCustomReplaceTest(custom, expected, replacements); |
| 52 | + |
| 53 | + } |
| 54 | + |
| 55 | + [Test] |
| 56 | + public void Should_Add_Replaceable_ResultsDirectory_And_TestAdaptersPath_If_Not_Present() |
| 57 | + { |
| 58 | + var custom = $@" |
| 59 | + <RunSettings> |
| 60 | + <RunConfiguration> |
| 61 | + </RunConfiguration> |
| 62 | + <DataCollectionRunSettings> |
| 63 | + <DataCollectors> |
| 64 | + <DataCollector friendlyName='Code Coverage' enabled='true'> |
| 65 | + <Configuration> |
| 66 | + <Format>Cobertura</Format> |
| 67 | + </Configuration> |
| 68 | + </DataCollector> |
| 69 | + </DataCollectors> |
| 70 | + </DataCollectionRunSettings> |
| 71 | + </RunSettings>"; |
| 72 | + |
| 73 | + var replacements = new TestRunSettingsTemplateReplacements |
| 74 | + { |
| 75 | + ResultsDirectory = "results directory", |
| 76 | + TestAdapter = "ms collector path" |
| 77 | + }; |
| 78 | + |
| 79 | + |
| 80 | + var expected = $@" |
| 81 | + <RunSettings> |
| 82 | + <RunConfiguration> |
| 83 | + <ResultsDirectory>{replacements.ResultsDirectory}</ResultsDirectory> |
| 84 | + <TestAdaptersPaths>{replacements.TestAdapter}</TestAdaptersPaths> |
| 85 | + </RunConfiguration> |
| 86 | + <DataCollectionRunSettings> |
| 87 | + <DataCollectors> |
| 88 | + <DataCollector friendlyName='Code Coverage' enabled='true'> |
| 89 | + <Configuration> |
| 90 | + <Format>Cobertura</Format> |
| 91 | + <FCCGenerated/> |
| 92 | + </Configuration> |
| 93 | + </DataCollector> |
| 94 | + </DataCollectors> |
| 95 | + </DataCollectionRunSettings> |
| 96 | + </RunSettings>"; |
| 97 | + |
| 98 | + ConfiguredCustomReplaceTest(custom, expected, replacements); |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + [Test] |
| 103 | + public void Should_Add_Replaceable_DataCollectionRunSettings_If_Not_Present() |
| 104 | + { |
| 105 | + var custom = $@" |
| 106 | + <RunSettings> |
| 107 | + <RunConfiguration> |
| 108 | + <ResultsDirectory>Path</ResultsDirectory> |
| 109 | + <TestAdaptersPaths>Path</TestAdaptersPaths> |
| 110 | + </RunConfiguration> |
| 111 | + </RunSettings>"; |
| 112 | + |
| 113 | + var replacements = new TestRunSettingsTemplateReplacements |
| 114 | + { |
| 115 | + AttributesExclude = "<AttributesExclude/>", |
| 116 | + AttributesInclude = "<AttributesInclude/>", |
| 117 | + CompanyNamesExclude = "<CompanyNamesExclude/>", |
| 118 | + CompanyNamesInclude = "<CompanyNamesInclude/>", |
| 119 | + FunctionsExclude = "<FunctionsExclude/>", |
| 120 | + FunctionsInclude = "<FunctionsInclude/>", |
| 121 | + ModulePathsInclude = "<ModulePathsInclude/>", |
| 122 | + ModulePathsExclude = "<ModulePathsExclude/>", |
| 123 | + PublicKeyTokensExclude = "<PublicKeyTokensExclude/>", |
| 124 | + PublicKeyTokensInclude = "<PublicKeyTokensInclude/>", |
| 125 | + SourcesExclude = "<SourcesExclude/>", |
| 126 | + SourcesInclude = "<SourcesInclude/>", |
| 127 | + |
| 128 | + Enabled = "enabledreplaced" |
| 129 | + }; |
| 130 | + |
| 131 | + var expected = $@" |
| 132 | + <RunSettings> |
| 133 | + <RunConfiguration> |
| 134 | + <ResultsDirectory>Path</ResultsDirectory> |
| 135 | + <TestAdaptersPaths>Path</TestAdaptersPaths> |
| 136 | + </RunConfiguration> |
| 137 | + <DataCollectionRunSettings> |
| 138 | + <DataCollectors> |
| 139 | + <DataCollector friendlyName='Code Coverage' enabled='{replacements.Enabled}'> |
| 140 | + <Configuration> |
| 141 | + <CodeCoverage> |
| 142 | + <ModulePaths> |
| 143 | + <Exclude> |
| 144 | + {replacements.ModulePathsExclude} |
| 145 | + </Exclude> |
| 146 | + <Include> |
| 147 | + {replacements.ModulePathsInclude} |
| 148 | + </Include> |
| 149 | + </ModulePaths> |
| 150 | + <Functions> |
| 151 | + <Exclude> |
| 152 | + {replacements.FunctionsExclude} |
| 153 | + </Exclude> |
| 154 | + <Include> |
| 155 | + {replacements.FunctionsInclude} |
| 156 | + </Include> |
| 157 | + </Functions> |
| 158 | + <Attributes> |
| 159 | + <Exclude> |
| 160 | + {replacements.AttributesExclude} |
| 161 | + </Exclude> |
| 162 | + <Include> |
| 163 | + {replacements.AttributesInclude} |
| 164 | + </Include> |
| 165 | + </Attributes> |
| 166 | + <Sources> |
| 167 | + <Exclude> |
| 168 | + {replacements.SourcesExclude} |
| 169 | + </Exclude> |
| 170 | + <Include> |
| 171 | + {replacements.SourcesInclude} |
| 172 | + </Include> |
| 173 | + </Sources> |
| 174 | + <CompanyNames> |
| 175 | + <Exclude> |
| 176 | + {replacements.CompanyNamesExclude} |
| 177 | + </Exclude> |
| 178 | + <Include> |
| 179 | + {replacements.CompanyNamesInclude} |
| 180 | + </Include> |
| 181 | + </CompanyNames> |
| 182 | + <PublicKeyTokens> |
| 183 | + <Exclude> |
| 184 | + {replacements.PublicKeyTokensExclude} |
| 185 | + </Exclude> |
| 186 | + <Include> |
| 187 | + {replacements.PublicKeyTokensInclude} |
| 188 | + </Include> |
| 189 | + </PublicKeyTokens> |
| 190 | + </CodeCoverage> |
| 191 | + <Format>Cobertura</Format> |
| 192 | + <FCCGenerated/> |
| 193 | + </Configuration> |
| 194 | + </DataCollector> |
| 195 | + </DataCollectors> |
| 196 | + </DataCollectionRunSettings> |
| 197 | + </RunSettings>"; |
| 198 | + |
| 199 | + ConfiguredCustomReplaceTest(custom, expected, replacements); |
| 200 | + } |
| 201 | + |
| 202 | + [Test] |
| 203 | + |
| 204 | + public void Should_Add_Replaceable_DataCollectors_If_Not_Present() |
| 205 | + { |
| 206 | + throw new NotImplementedException(); |
| 207 | + } |
| 208 | + |
| 209 | + [Test] |
| 210 | + public void Should_Add_Replaceable_Ms_DataCollector_If_Not_Present() |
| 211 | + { |
| 212 | + throw new NotImplementedException(); |
| 213 | + } |
| 214 | + |
| 215 | + [Test] |
| 216 | + public void Should_AddEnabledReplacementAttributeIfNotPresent_To_Existing_Ms_DataCollector() |
| 217 | + { |
| 218 | + throw new NotImplementedException(); |
| 219 | + } |
| 220 | + |
| 221 | + [Test] |
| 222 | + public void Should_Add_Configuration_Element_If_Not_Present_To_Existing_Ms_DataCollector() |
| 223 | + { |
| 224 | + throw new NotImplementedException(); |
| 225 | + } |
| 226 | + |
| 227 | + [Test] |
| 228 | + public void Should_Add_Cobertura_Format_To_Existing_Configuration_Element_If_Not_Present() |
| 229 | + { |
| 230 | + throw new NotImplementedException(); |
| 231 | + } |
| 232 | + |
| 233 | + [Test] |
| 234 | + public void Should_Correct_Existing_Format_To_Cobertura_When_Different_Format() |
| 235 | + { |
| 236 | + throw new NotImplementedException(); |
| 237 | + } |
| 238 | + |
| 239 | + [Test] |
| 240 | + public void Should_Add_FCCGenerated_To_Existing_Configuration_Element() |
| 241 | + { |
| 242 | + throw new NotImplementedException(); |
| 243 | + } |
| 244 | + |
| 245 | + private void ConfiguredCustomReplaceTest(string custom,string expected,IRunSettingsTemplateReplacements replacements) |
| 246 | + { |
| 247 | + var builtInRunSettingsTemplate = new BuiltInRunSettingsTemplate(); |
| 248 | + |
| 249 | + var customTemplate = builtInRunSettingsTemplate.ConfigureCustom(custom); |
| 250 | + |
| 251 | + var replaced = builtInRunSettingsTemplate.Replace(customTemplate, replacements).Replaced; |
| 252 | + |
| 253 | + XmlAssert.NoXmlDifferences(expected, replaced); |
| 254 | + } |
| 255 | + } |
| 256 | +} |
0 commit comments