File tree Expand file tree Collapse file tree 4 files changed +84
-2
lines changed
src/DemaConsulting.SpdxModel
test/DemaConsulting.SpdxModel.Tests Expand file tree Collapse file tree 4 files changed +84
-2
lines changed Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ public abstract class SpdxElement
3636 /// Regular expression for checking element IDs of the form "SPDXRef-name"
3737 /// </summary>
3838 protected static readonly Regex SpdxRefRegex = new (
39- "^SPDXRef-[a-zA-Z0-9, -]+$" ,
39+ "^SPDXRef-[a-zA-Z0-9. -]+$" ,
4040 RegexOptions . None ,
4141 TimeSpan . FromMilliseconds ( 100 ) ) ;
4242
Original file line number Diff line number Diff line change @@ -242,6 +242,40 @@ public void SpdxFile_Validate_ReportsInvalidFileId()
242242 issues . Any ( issue => issue . Contains ( "File ./file1.txt Invalid SPDX Identifier Field" ) ) ) ;
243243 }
244244
245+ /// <summary>
246+ /// Tests that a valid file passes validation.
247+ /// </summary>
248+ [ TestMethod ]
249+ public void SpdxFile_Validate_Success ( )
250+ {
251+ // Arrange: Create a valid SpdxFile instance
252+ var spdxFile = new SpdxFile
253+ {
254+ Id = "SPDXRef-File--file1.txt-85ed0817af83a24ad8da68c2b5094de69833983c" ,
255+ FileName = "./file1.txt" ,
256+ Checksums =
257+ [
258+ new SpdxChecksum
259+ {
260+ Algorithm = SpdxChecksumAlgorithm . Sha1 ,
261+ Value = "85ed0817af83a24ad8da68c2b5094de69833983c"
262+ } ,
263+ new SpdxChecksum
264+ {
265+ Algorithm = SpdxChecksumAlgorithm . Sha256 ,
266+ Value = "2e5c078f9471ccf53c786b3949b34dbb9d2937da0752317f79693879ddf34d5b"
267+ }
268+ ]
269+ } ;
270+
271+ // Act: Perform validation on the SpdxFile instance.
272+ var issues = new List < string > ( ) ;
273+ spdxFile . Validate ( issues ) ;
274+
275+ // Assert: Verify that the validation reports no issues.
276+ Assert . AreEqual ( 0 , issues . Count ) ;
277+ }
278+
245279 /// <summary>
246280 /// Tests the <see cref="SpdxFileTypeExtensions.FromText(string)" /> method with valid inputs.
247281 /// </summary>
Original file line number Diff line number Diff line change @@ -203,4 +203,28 @@ public void SpdxPackage_Validate_ReportsInvalidPackageIds()
203203 Assert . IsTrue (
204204 issues . Any ( i => i . StartsWith ( "Package TestPackage Invalid SPDX Identifier Field" ) ) ) ;
205205 }
206+
207+ /// <summary>
208+ /// Tests that a valid package passes validation.
209+ /// </summary>
210+ [ TestMethod ]
211+ public void SpdxPackage_Validate_Success ( )
212+ {
213+ // Arrange: Construct a valid SpdxPackage
214+ var package = new SpdxPackage
215+ {
216+ Id = "SPDXRef-Package-SpdxModel" ,
217+ Name = "DemaConsulting.SpdxModel" ,
218+ Version = "0.0.0" ,
219+ DownloadLocation = "https://www.nuget.org/packages/DemaConsulting.SpdxModel" ,
220+ Supplier = "Organization: DemaConsulting"
221+ } ;
222+
223+ // Act: Validate the package
224+ var issues = new List < string > ( ) ;
225+ package . Validate ( issues , null , true ) ;
226+
227+ // Assert: Verify that the validation reports no issues.
228+ Assert . AreEqual ( 0 , issues . Count ) ;
229+ }
206230}
Original file line number Diff line number Diff line change @@ -153,7 +153,6 @@ public void SpdxSnippet_Enhance_AddsOrUpdatesInformationCorrectly()
153153 Assert . AreEqual ( 40 , snippets [ 1 ] . SnippetByteEnd ) ;
154154 }
155155
156-
157156 /// <summary>
158157 /// Tests that an invalid snippet ID fails validation.
159158 /// </summary>
@@ -177,4 +176,29 @@ public void SpdxSnippet_Validate_ReportsInvalidSnippetId()
177176 Assert . IsTrue (
178177 issues . Any ( issue => issue . Contains ( "Snippet Invalid SPDX Identifier Field" ) ) ) ;
179178 }
179+
180+ /// <summary>
181+ /// Tests that a valid snippet passes validation.
182+ /// </summary>
183+ [ TestMethod ]
184+ public void SpdxSnippet_Validate_Success ( )
185+ {
186+ // Arrange: Create a valid SpdxSnippet
187+ var snippet = new SpdxSnippet
188+ {
189+ Id = "SPDXRef-Snippet" ,
190+ SnippetFromFile = "SPDXRef-File1" ,
191+ SnippetByteStart = 100 ,
192+ SnippetByteEnd = 200 ,
193+ ConcludedLicense = "MIT" ,
194+ CopyrightText = "Copyright(c) 2024 DEMA Consulting"
195+ } ;
196+
197+ // Act: Validate the snippet
198+ var issues = new List < string > ( ) ;
199+ snippet . Validate ( issues ) ;
200+
201+ // Assert: Verify that the validation reports no issues.
202+ Assert . AreEqual ( 0 , issues . Count ) ;
203+ }
180204}
You can’t perform that action at this time.
0 commit comments