/// <summary> /// Checks whether there is a single "SonarQubeSetting" item with the expected name and setting value /// </summary> private static void AssertExpectedAnalysisSetting(BuildLog actualResult, string settingName, string expectedValue) { /* The equivalent XML would look like this: * <ItemGroup> * <SonarQubeSetting Include="settingName"> * <Value>expectedValue</Value * </SonarQubeSetting> * </ItemGroup> */ var settings = actualResult.GetItem(BuildTaskConstants.SettingItemName); settings.Should().NotBeEmpty(); var matches = settings.Where(v => v.Text.Equals(settingName, System.StringComparison.Ordinal)).ToList(); matches.Should().ContainSingle($"Only one and only expecting one SonarQubeSetting with include value of '{0}' to exist. Count: {matches.Count}", settingName); var item = matches[0]; if (item.Metadata.TryGetValue(BuildTaskConstants.SettingValueMetadataName, out var value)) { value.Should().Be(expectedValue, "SonarQubeSetting with include value '{0}' does not have the expected value", settingName); } else { Assert.Fail("SonarQubeSetting does not have value."); } }
private void DumpLists(BuildLog actualResult, string itemType, string[] expected) { TestContext.WriteLine(""); TestContext.WriteLine("Dumping <" + itemType + "> list: expected"); foreach (var item in expected) { TestContext.WriteLine("\t{0}", item); } TestContext.WriteLine(""); TestContext.WriteLine(""); TestContext.WriteLine("Dumping <" + itemType + "> list: actual"); foreach (var item in actualResult.GetItem(itemType)) { TestContext.WriteLine("\t{0}", item.Text); } TestContext.WriteLine(""); }
/// <summary> /// Checks that a SonarQubeSetting does not exist /// </summary> private static void AssertAnalysisSettingDoesNotExist(BuildLog actualResult, string settingName) { var matches = actualResult.GetItem(BuildTaskConstants.SettingItemName); matches.Should().BeEmpty("Not expected SonarQubeSetting with include value of '{0}' to exist. Actual occurrences: {1}", settingName, matches.Count()); }