Skip to content

Commit a2a544a

Browse files
authored
Merge pull request #3347 from FirelyTeam/copilot/address-mstest-analyzer-warnings
Address MSTest 4.0 analyzer warnings (1,424 of 1,866 fixed)
2 parents 15fb448 + b1a57c1 commit a2a544a

File tree

92 files changed

+904
-903
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+904
-903
lines changed

src/Hl7.Fhir.ElementModel.Shared.Tests/ElementNodeTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void TestFpNavigate()
8282
// Select on the root of the resource, path should match with resource name included
8383
var active = patient.Select("Patient.active");
8484
Assert.IsNotNull(active);
85-
Assert.AreEqual(true, active.FirstOrDefault().Value);
85+
Assert.IsTrue((bool?)active.FirstOrDefault().Value);
8686

8787
// Select on the root of the resource, resource type does not match
8888
var id = obs.Select("Patient.id");
@@ -91,7 +91,7 @@ public void TestFpNavigate()
9191
// Select on root of the resource, path does not include the resourceType
9292
active = patient.Select("active");
9393
Assert.IsNotNull(active);
94-
Assert.AreEqual(true, active.FirstOrDefault().Value);
94+
Assert.IsTrue((bool?)active.FirstOrDefault().Value);
9595

9696
// Select on the root of the resource, path is for a generic Resource / DomainResource element
9797
id = obs.Select("Resource.id");
@@ -113,11 +113,11 @@ public void TestFpNavigateCustomResource()
113113

114114
var result = customResource.Select("UpperCaseElement");
115115
Assert.IsNotNull(result.FirstOrDefault());
116-
Assert.AreEqual(true, result.FirstOrDefault().Value);
116+
Assert.IsTrue((bool?)result.FirstOrDefault().Value);
117117

118118
result = customResource.Select("lowerCaseElement");
119119
Assert.IsNotNull(result.FirstOrDefault());
120-
Assert.AreEqual(false, result.FirstOrDefault().Value);
120+
Assert.IsFalse((bool?)result.FirstOrDefault().Value);
121121
}
122122

123123
[TestMethod]
@@ -166,7 +166,7 @@ public void TestConstruction()
166166

167167
data = patient[1];
168168
Assert.AreEqual("active", data.Name);
169-
Assert.AreEqual(true, data.Value);
169+
Assert.IsTrue((bool?)data.Value);
170170
Assert.AreEqual("boolean", data.InstanceType);
171171
}
172172

@@ -304,7 +304,7 @@ public void ReplaceChildInElement()
304304
newActive.Value = false;
305305
patient.Replace(_provider, patient["active"].Single(), newActive);
306306
Assert.AreEqual(1, patient["active"].Count);
307-
Assert.AreEqual(false, patient["active"].Single().Value);
307+
Assert.IsFalse((bool?)patient["active"].Single().Value);
308308

309309
var newIdentifier = ElementNode.Root(_provider, "Identifier");
310310
newIdentifier.Add(_provider, "system", "http://nos.nl");
@@ -324,7 +324,7 @@ public void FromElementClonesCorrectly()
324324

325325
var activeChild = newElement["active"].Single();
326326
Assert.IsTrue((bool)activeChild.Value);
327-
Assert.IsTrue(activeChild.Annotations<string>().Single() == "a string annotation");
327+
Assert.AreEqual("a string annotation", activeChild.Annotations<string>().Single());
328328

329329
var identifierSystemChild = newElement["identifier"][0]["system"].Single();
330330

src/Hl7.Fhir.ElementModel.Shared.Tests/ScopedNodeOnBaseTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void GetContainedAndBundledResources()
2828
Assert.AreEqual(0, _bundleNode!.ContainedResources().Count());
2929

3030
var entries = _bundleNode.Child<PocoListNode>("entry")?.Pocos.OfType<Bundle.EntryComponent>().ToList();
31-
Assert.AreEqual(7, entries.Count);
31+
Assert.HasCount(7, entries);
3232

3333
Assert.AreEqual("urn:uuid:04121321-4af5-424c-a0e1-ed3aab1c349d", entries[1].FullUrl);
3434
Assert.AreEqual("http://example.org/fhir/Patient/b", entries[3].FullUrl);
@@ -114,7 +114,7 @@ public void TestResolve()
114114
Assert.IsNull(inner7.Resolve("http://nu.nl/3"));
115115

116116
Assert.AreEqual("Bundle.entry[6].resource[0].contained[1]", inner7.Resolve()!.GetLocation());
117-
Assert.IsTrue(inner7!.Child("reference") is not null);
117+
Assert.IsNotNull(inner7!.Child("reference"));
118118
Assert.AreEqual("Bundle.entry[6].resource[0].contained[1]", inner7.Child("reference")!.First().Resolve()!.GetLocation());
119119

120120
string lastUrlResolved = "";

src/Hl7.Fhir.ElementModel.Shared.Tests/ScopedNodeTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static bool CCDATypeNameMapper(string typeName, out string canonical)
285285

286286
var errors = typedElement.VisitAndCatch();
287287

288-
Assert.IsTrue(!errors.Any());
288+
Assert.IsFalse(errors.Any());
289289

290290
var assertXHtml = typedElement.Children("text");
291291

src/Hl7.Fhir.R4.Tests/Model/ModelTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
namespace Hl7.Fhir.Tests.Model
1919
{
20+
[TestClass]
2021
public partial class ModelTests
2122
{
2223
[TestMethod]
@@ -103,7 +104,6 @@ public void DateGetHashCodeWithNullValue()
103104
try
104105
{
105106
int hashCode = date.GetHashCode();
106-
Assert.IsTrue(true, "GetHashCode completed without throwing an exception");
107107
}
108108
catch (NullReferenceException ex)
109109
{
@@ -133,8 +133,6 @@ public void AllPrimitiveTypesGetHashCodeWithNullValue()
133133
int hashCode2 = dateTime.GetHashCode();
134134
int hashCode3 = instant.GetHashCode();
135135
int hashCode4 = time.GetHashCode();
136-
137-
Assert.IsTrue(true, "All GetHashCode calls completed without throwing exceptions");
138136
}
139137
catch (NullReferenceException ex)
140138
{

src/Hl7.Fhir.R4B.Tests/Model/ModelTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Hl7.Fhir.Tests.Model
1515
{
16+
[TestClass]
1617
public partial class ModelTests
1718
{
1819
[TestMethod]
@@ -49,12 +50,12 @@ public void TestCheckMinorVersionCompatibiliy()
4950
Assert.IsFalse(ModelInfo.CheckMinorVersionCompatibility("3"));
5051
}
5152

52-
//If failed: change the description of the "STN" in the Currency enum of Money.cs from "SC#o TomC) and PrC-ncipe dobra" to "São Tomé and Príncipe dobra".
53+
//If failed: change the description of the "STN" in the Currency enum of Money.cs from "SC#o TomC) and PrC-ncipe dobra" to "São Tomé and Príncipe dobra".
5354
[TestMethod]
5455
public void TestCorrectCurrencyDescription()
5556
{
5657
var currency = Money.Currencies.STN;
57-
currency.GetDocumentation().Should().Be("São Tomé and Príncipe dobra");
58+
currency.GetDocumentation().Should().Be("São Tomé and Príncipe dobra");
5859
}
5960
}
6061
}

src/Hl7.Fhir.R5.Tests/Model/ModelTests.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace Hl7.Fhir.Tests.Model
1515
{
16+
[TestClass]
1617
public partial class ModelTests
1718
{
1819
[TestMethod]
@@ -46,12 +47,12 @@ public void TestCheckMinorVersionCompatibiliy()
4647
Assert.IsFalse(ModelInfo.CheckMinorVersionCompatibility("3"));
4748
}
4849

49-
//If failed: change the description of the "STN" in the Currency enum of Money.cs from "SC#o TomC) and PrC-ncipe dobra" to "São Tomé and Príncipe dobra".
50+
//If failed: change the description of the "STN" in the Currency enum of Money.cs from "SC#o TomC) and PrC-ncipe dobra" to "São Tomé and Príncipe dobra".
5051
[TestMethod]
5152
public void TestCorrectCurrencyDescription()
5253
{
5354
var currency = Currencies.STN;
54-
currency.GetDocumentation().Should().Be("São Tomé and Príncipe dobra");
55+
currency.GetDocumentation().Should().Be("São Tomé and Príncipe dobra");
5556
}
5657
}
5758
}

src/Hl7.Fhir.STU3.Tests/ElementModel/PocoTypedElementTests.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ public void PocoExtensionTest()
5454
p.ActiveElement.AddExtension("http://something.org", new FhirBoolean(false));
5555
p.ActiveElement.AddExtension("http://something.org", new Integer(314));
5656

57-
Assert.AreEqual(true, p.Scalar("Patient.active.first()"));
58-
Assert.AreEqual(true, p.Scalar("Patient.active[0]"));
57+
Assert.IsTrue((bool?)p.Scalar("Patient.active.first()"));
58+
Assert.IsTrue((bool?)p.Scalar("Patient.active[0]"));
5959
Assert.AreEqual("314", p.Scalar("Patient.active[0].id[0]"));
6060

6161
var extensions = p.Select("Patient.active[0].extension");
@@ -82,21 +82,21 @@ public void PocoHasValueTest()
8282
{
8383
Patient p = new Patient();
8484

85-
Assert.AreEqual(false, p.Predicate("Patient.active.hasValue()"));
86-
Assert.AreEqual(false, p.Predicate("Patient.active.exists()"));
85+
Assert.IsFalse(p.Predicate("Patient.active.hasValue()"));
86+
Assert.IsFalse(p.Predicate("Patient.active.exists()"));
8787

8888
p.Active = true;
89-
Assert.AreEqual(true, p.Predicate("Patient.active.hasValue()"));
90-
Assert.AreEqual(true, p.Predicate("Patient.active.exists()"));
89+
Assert.IsTrue(p.Predicate("Patient.active.hasValue()"));
90+
Assert.IsTrue(p.Predicate("Patient.active.exists()"));
9191

9292
p.ActiveElement.AddExtension("http://something.org", new FhirBoolean(false));
93-
Assert.AreEqual(true, p.Predicate("Patient.active.hasValue()"));
94-
Assert.AreEqual(true, p.Predicate("Patient.active.exists()"));
93+
Assert.IsTrue(p.Predicate("Patient.active.hasValue()"));
94+
Assert.IsTrue(p.Predicate("Patient.active.exists()"));
9595

9696
p.ActiveElement = new FhirBoolean();
9797
p.ActiveElement.AddExtension("http://something.org", new FhirBoolean(false));
98-
Assert.AreEqual(false, p.Predicate("Patient.active.hasValue()"));
99-
Assert.AreEqual(true, p.Predicate("Patient.active.exists()"));
98+
Assert.IsFalse(p.Predicate("Patient.active.hasValue()"));
99+
Assert.IsTrue(p.Predicate("Patient.active.exists()"));
100100
}
101101

102102
[TestMethod]
@@ -137,7 +137,7 @@ public void IncorrectPathInTwoSuccessiveRepeatingMembers()
137137

138138
Assert.IsNotNull(rest);
139139

140-
Assert.IsTrue(rest.Location.Contains("CapabilityStatement.rest[0]"));
140+
Assert.Contains("CapabilityStatement.rest[0]", rest.Location);
141141
}
142142

143143

src/Hl7.Fhir.STU3.Tests/Model/ValidateAllExamplesSearchExtractionTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ private void searchExtractionAllExamplesInternal()
109109
errorCount++;
110110
}
111111

112-
Assert.IsTrue(43 >= errorCount,
113-
$"Failed search parameter data extraction, missing data in {missingSearchValues.Length} of " +
112+
Assert.IsGreaterThanOrEqualTo(errorCount,
113+
43, $"Failed search parameter data extraction, missing data in {missingSearchValues.Length} of " +
114114
$"{exampleSearchValues.Count} search parameters");
115115
Assert.AreEqual(0, parserErrorCount,
116116
$"Failed search parameter data extraction, {parserErrorCount} files failed parsing");

0 commit comments

Comments
 (0)