From a9410b2bf1e5dc88561d308b57b522f449c2f7bb Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 17 Jan 2025 21:47:39 +0100 Subject: [PATCH] Switch DataTestMethod to TestMethod (#849) * Switch DataTestMethod to TestMethod * Fix duplicate TestMethod attribute * Add missing [TestMethod] attributes in tests Minor tweaks for consistency --------- Co-authored-by: Dave Tryon <45672944+DaveTryon@users.noreply.github.com> Co-authored-by: Sarah Oslund --- .../FormatValidator/FormatValidatorTests.cs | 2 +- .../Parser/SbomFileParserTests.cs | 9 +++------ .../Parser/SbomPackageParserTests.cs | 9 ++++----- .../Parser/SbomParserTests.cs | 6 +++--- .../Parser/SbomRelationshipParserTests.cs | 9 +++------ .../Utils/SPDXExtensionsTest.cs | 3 +-- 6 files changed, 15 insertions(+), 23 deletions(-) diff --git a/test/Microsoft.Sbom.Api.Tests/FormatValidator/FormatValidatorTests.cs b/test/Microsoft.Sbom.Api.Tests/FormatValidator/FormatValidatorTests.cs index dd0a2565..5ac238c9 100644 --- a/test/Microsoft.Sbom.Api.Tests/FormatValidator/FormatValidatorTests.cs +++ b/test/Microsoft.Sbom.Api.Tests/FormatValidator/FormatValidatorTests.cs @@ -37,7 +37,7 @@ public async Task FormatValidator_CanReadValidSbom() } } - [DataTestMethod] + [TestMethod] [DataRow(FormatValidatorTestStrings.JsonMissingSpdxVersion, "spdxVersion")] [DataRow(FormatValidatorTestStrings.JsonMissingSpdxDataLicense, "dataLicense")] [DataRow(FormatValidatorTestStrings.JsonMissingDocumentNamespace, "documentNamespace")] diff --git a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomFileParserTests.cs b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomFileParserTests.cs index 8ff7ea64..7e30ba95 100644 --- a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomFileParserTests.cs +++ b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomFileParserTests.cs @@ -100,12 +100,11 @@ public void MissingPropertiesTest_ThrowsSHA256() Assert.ThrowsException(() => 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); @@ -116,12 +115,11 @@ public void MissingPropertiesTest_Throws(string json) _ = Assert.ThrowsException(() => 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); @@ -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); diff --git a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomPackageParserTests.cs b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomPackageParserTests.cs index 141a5800..83f75270 100644 --- a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomPackageParserTests.cs +++ b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomPackageParserTests.cs @@ -48,7 +48,7 @@ public void StreamEmptyTestThrowsException() Assert.ThrowsException(() => new SPDXParser(stream)); } - [DataTestMethod] + [TestMethod] [DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingDownloadLocation)] [DataRow(SbomPackageStrings.PackageJsonWith1PackageMissingVersionInfo)] public void MissingPropertiesTest_DoesNotThrow(string json) @@ -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)] @@ -83,7 +83,7 @@ public void MissingPropertiesTest_Throws(string json) Assert.ThrowsException(() => this.Parse(parser)); } - [DataTestMethod] + [TestMethod] [DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalString)] [DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalArray)] [DataRow(SbomPackageStrings.PackageJsonWith1PackageAdditionalObject)] @@ -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); diff --git a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomParserTests.cs b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomParserTests.cs index fe1252ba..ac15d213 100644 --- a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomParserTests.cs +++ b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomParserTests.cs @@ -51,7 +51,7 @@ public void ParseMultiplePropertiesTest() Assert.AreEqual(0, result.ReferencesCount); } - [DataTestMethod] + [TestMethod] [DataRow(SbomParserStrings.JsonWithMissingFiles)] [DataRow(SbomParserStrings.JsonWithMissingPackages)] [DataRow(SbomParserStrings.JsonWithMissingRelationships)] @@ -62,7 +62,7 @@ public void MissingPropertyThrows(string json) Assert.ThrowsException(() => this.IterateAllPropertiesAsync(stream)); } - [DataTestMethod] + [TestMethod] [DataRow(SbomParserStrings.MalformedJson)] [DataRow(SbomParserStrings.MalformedJsonIncorrectRefsType)] [DataRow(SbomParserStrings.MalformedJsonIncorrectFilesType)] @@ -76,7 +76,7 @@ public void MalformedJsonThrows(string json) Assert.ThrowsException(() => this.IterateAllPropertiesAsync(stream)); } - [DataTestMethod] + [TestMethod] [DataRow(SbomParserStrings.MalformedJsonEmptyJsonObject)] [DataRow(SbomParserStrings.MalformedJsonEmptyArrayObject)] public void MalformedJsonEmptyValuesDoesNotThrow(string json) diff --git a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomRelationshipParserTests.cs b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomRelationshipParserTests.cs index f89c2a63..33369daa 100644 --- a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomRelationshipParserTests.cs +++ b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Parser/SbomRelationshipParserTests.cs @@ -37,10 +37,9 @@ public void StreamEmptyTestReturnsNull() Assert.ThrowsException(() => new SPDXParser(stream)); } - [DataTestMethod] + [TestMethod] [DataRow(RelationshipStrings.JsonRelationshipsStringMissingElementId)] [DataRow(RelationshipStrings.JsonRelationshipsStringMissingRelatedElement)] - [TestMethod] public void MissingPropertiesTest_Throws(string json) { var bytes = Encoding.UTF8.GetBytes(json); @@ -51,12 +50,11 @@ public void MissingPropertiesTest_Throws(string json) Assert.ThrowsException(() => 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); @@ -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); diff --git a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Utils/SPDXExtensionsTest.cs b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Utils/SPDXExtensionsTest.cs index eaf025e0..137a76b7 100644 --- a/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Utils/SPDXExtensionsTest.cs +++ b/test/Microsoft.Sbom.Parsers.Spdx22SbomParser.Tests/Utils/SPDXExtensionsTest.cs @@ -77,10 +77,9 @@ public void AddPackageUrlsTest_WithNonNullExternalRef_Success() Assert.AreEqual(0, spdxPackage.ExternalReferences.Count()); } - [DataTestMethod] + [TestMethod] [DataRow("pkg:npm/glob@7.1.6", "pkg:npm/glob@7.1.6")] [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();