Skip to content

Commit

Permalink
Switch DataTestMethod to TestMethod (#849)
Browse files Browse the repository at this point in the history
* Switch DataTestMethod to TestMethod

* Fix duplicate TestMethod attribute

* Add missing [TestMethod] attributes in tests

Minor tweaks for consistency

---------

Co-authored-by: Dave Tryon <[email protected]>
Co-authored-by: Sarah Oslund <[email protected]>
  • Loading branch information
3 people authored Jan 17, 2025
1 parent c0b7668 commit a9410b2
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public async Task FormatValidator_CanReadValidSbom()
}
}

[DataTestMethod]
[TestMethod]
[DataRow(FormatValidatorTestStrings.JsonMissingSpdxVersion, "spdxVersion")]
[DataRow(FormatValidatorTestStrings.JsonMissingSpdxDataLicense, "dataLicense")]
[DataRow(FormatValidatorTestStrings.JsonMissingDocumentNamespace, "documentNamespace")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,11 @@ public void MissingPropertiesTest_ThrowsSHA256()
Assert.ThrowsException<ParserException>(() => result.Files.Select(f => f.ToSbomFile()).ToList());
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomFileJsonStrings.JsonWith1FileMissingNameString)]
[DataRow(SbomFileJsonStrings.JsonWith1FileMissingIDString)]
[DataRow(SbomFileJsonStrings.JsonWith1FileMissingChecksumsString)]
[DataRow(SbomFileJsonStrings.JsonWith1FileMissingCopyrightAndPathString)]
[TestMethod]
public void MissingPropertiesTest_Throws(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand All @@ -116,12 +115,11 @@ public void MissingPropertiesTest_Throws(string json)
_ = Assert.ThrowsException<ParserException>(() => this.Parse(parser));
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomFileJsonStrings.GoodJsonWith1FileAdditionalObjectPropertyString)]
[DataRow(SbomFileJsonStrings.GoodJsonWith1FileAdditionalArrayPropertyString)]
[DataRow(SbomFileJsonStrings.GoodJsonWith1FileAdditionalStringPropertyString)]
[DataRow(SbomFileJsonStrings.GoodJsonWith1FileAdditionalValueArrayPropertyString)]
[TestMethod]
public void IgnoresAdditionalPropertiesTest(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand All @@ -134,11 +132,10 @@ public void IgnoresAdditionalPropertiesTest(string json)
Assert.AreEqual(1, result.FilesCount);
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomFileJsonStrings.MalformedJson)]
[DataRow(SbomFileJsonStrings.MalformedJsonEmptyObject)]
[DataRow(SbomFileJsonStrings.MalformedJsonEmptyObjectNoArrayEnd)]
[TestMethod]
public void MalformedJsonTest_Throws(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void StreamEmptyTestThrowsException()
Assert.ThrowsException<EndOfStreamException>(() => new SPDXParser(stream));
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingDownloadLocation)]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingVersionInfo)]
public void MissingPropertiesTest_DoesNotThrow(string json)
Expand All @@ -61,7 +61,7 @@ public void MissingPropertiesTest_DoesNotThrow(string json)
var result = this.Parse(parser);
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingCopyrightText)]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingLicenseInfoFromFiles)]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingSupplier)]
Expand All @@ -83,7 +83,7 @@ public void MissingPropertiesTest_Throws(string json)
Assert.ThrowsException<ParserException>(() => this.Parse(parser));
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalString)]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalArray)]
[DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalObject)]
Expand All @@ -98,11 +98,10 @@ public void IgnoresAdditionalPropertiesTest(string json)
var result = this.Parse(parser);
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomPackageStrings.MalformedJson)]
[DataRow(SbomPackageStrings.MalformedJsonEmptyObject)]
[DataRow(SbomPackageStrings.MalformedJsonEmptyObjectNoArrayEnd)]
[TestMethod]
public void MalformedJsonTest_Throws(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void ParseMultiplePropertiesTest()
Assert.AreEqual(0, result.ReferencesCount);
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomParserStrings.JsonWithMissingFiles)]
[DataRow(SbomParserStrings.JsonWithMissingPackages)]
[DataRow(SbomParserStrings.JsonWithMissingRelationships)]
Expand All @@ -62,7 +62,7 @@ public void MissingPropertyThrows(string json)
Assert.ThrowsException<ParserException>(() => this.IterateAllPropertiesAsync(stream));
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomParserStrings.MalformedJson)]
[DataRow(SbomParserStrings.MalformedJsonIncorrectRefsType)]
[DataRow(SbomParserStrings.MalformedJsonIncorrectFilesType)]
Expand All @@ -76,7 +76,7 @@ public void MalformedJsonThrows(string json)
Assert.ThrowsException<ParserException>(() => this.IterateAllPropertiesAsync(stream));
}

[DataTestMethod]
[TestMethod]
[DataRow(SbomParserStrings.MalformedJsonEmptyJsonObject)]
[DataRow(SbomParserStrings.MalformedJsonEmptyArrayObject)]
public void MalformedJsonEmptyValuesDoesNotThrow(string json)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ public void StreamEmptyTestReturnsNull()
Assert.ThrowsException<EndOfStreamException>(() => new SPDXParser(stream));
}

[DataTestMethod]
[TestMethod]
[DataRow(RelationshipStrings.JsonRelationshipsStringMissingElementId)]
[DataRow(RelationshipStrings.JsonRelationshipsStringMissingRelatedElement)]
[TestMethod]
public void MissingPropertiesTest_Throws(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand All @@ -51,12 +50,11 @@ public void MissingPropertiesTest_Throws(string json)
Assert.ThrowsException<ParserException>(() => this.Parse(parser));
}

[DataTestMethod]
[TestMethod]
[DataRow(RelationshipStrings.GoodJsonWithRelationshipsStringAdditionalString)]
[DataRow(RelationshipStrings.GoodJsonWithRelationshipsStringAdditionalObject)]
[DataRow(RelationshipStrings.GoodJsonWithRelationshipsStringAdditionalArray)]
[DataRow(RelationshipStrings.GoodJsonWithRelationshipsStringAdditionalArrayNoKey)]
[TestMethod]
public void IgnoresAdditionalPropertiesTest(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand All @@ -69,9 +67,8 @@ public void IgnoresAdditionalPropertiesTest(string json)
Assert.IsTrue(result.RelationshipsCount > 0);
}

[DataTestMethod]
[DataRow(RelationshipStrings.MalformedJsonRelationshipsString)]
[TestMethod]
[DataRow(RelationshipStrings.MalformedJsonRelationshipsString)]
public void MalformedJsonTest_Throws(string json)
{
var bytes = Encoding.UTF8.GetBytes(json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ public void AddPackageUrlsTest_WithNonNullExternalRef_Success()
Assert.AreEqual(0, spdxPackage.ExternalReferences.Count());
}

[DataTestMethod]
[TestMethod]
[DataRow("pkg:npm/[email protected]", "pkg:npm/[email protected]")]
[DataRow("https://github.com/actions/virtual-environments", "https://github.com/actions/virtual-environments")]

public void AddPackageUrlsTest_WithSpecialCharacter_Success(string inputUrl, string expectedUrl)
{
spdxPackage = new SPDXPackage();
Expand Down

0 comments on commit a9410b2

Please sign in to comment.