Skip to content

Commit 8c77719

Browse files
Copilotpragnya17
andcommitted
Combine duplicate FileInfoWriter tests as requested
Co-authored-by: pragnya17 <59893188+pragnya17@users.noreply.github.com>
1 parent ad1c6ff commit 8c77719

1 file changed

Lines changed: 3 additions & 46 deletions

File tree

test/Microsoft.Sbom.Api.Tests/Executors/FileInfoWriterTests.cs

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public async Task Write_FileWithinDropPath_WritesToFilesSection()
5959
var sbomConfigs = new[] { sbomConfigMock.Object };
6060
var fileInfo = new InternalSbomFileInfo
6161
{
62-
Path = "test_file.txt",
62+
Path = "internal/package.spdx.json",
6363
IsOutsideDropPath = false,
6464
FileTypes = new[] { FileType.SPDX },
6565
Checksum = new[] { new Checksum { Algorithm = AlgorithmName.SHA256, ChecksumValue = "abc123" } }
@@ -69,8 +69,9 @@ public async Task Write_FileWithinDropPath_WritesToFilesSection()
6969
await fileInfoChannel.Writer.WriteAsync(fileInfo);
7070
fileInfoChannel.Writer.Complete();
7171

72-
// Setup expectations
72+
// Setup expectations - SPDX files within drop path should record both types of IDs
7373
sbomPackageDetailsRecorderMock.Setup(m => m.RecordFileId(It.IsAny<string>()));
74+
sbomPackageDetailsRecorderMock.Setup(m => m.RecordSPDXFileId(It.IsAny<string>()));
7475

7576
// Act
7677
var (result, errors) = testSubject.Write(fileInfoChannel.Reader, sbomConfigs);
@@ -133,48 +134,4 @@ public async Task Write_FileOutsideDropPath_DoesNotWriteToFilesSection()
133134
Assert.AreEqual(0, resultList.Count);
134135
Assert.AreEqual(0, errorList.Count);
135136
}
136-
137-
[TestMethod]
138-
public async Task Write_SpdxFileWithinDropPath_RecordsBothFileIdAndSpdxFileId()
139-
{
140-
// Arrange
141-
var sbomConfigs = new[] { sbomConfigMock.Object };
142-
var fileInfo = new InternalSbomFileInfo
143-
{
144-
Path = "internal/package.spdx.json",
145-
IsOutsideDropPath = false,
146-
FileTypes = new[] { FileType.SPDX },
147-
Checksum = new[] { new Checksum { Algorithm = AlgorithmName.SHA256, ChecksumValue = "ghi789" } }
148-
};
149-
150-
var fileInfoChannel = Channel.CreateUnbounded<InternalSbomFileInfo>();
151-
await fileInfoChannel.Writer.WriteAsync(fileInfo);
152-
fileInfoChannel.Writer.Complete();
153-
154-
// Setup expectations - allow but don't require
155-
sbomPackageDetailsRecorderMock.Setup(m => m.RecordFileId(It.IsAny<string>()));
156-
sbomPackageDetailsRecorderMock.Setup(m => m.RecordSPDXFileId(It.IsAny<string>()));
157-
158-
// Act
159-
var (result, errors) = testSubject.Write(fileInfoChannel.Reader, sbomConfigs);
160-
161-
// Assert
162-
var resultList = new List<JsonDocWithSerializer>();
163-
await foreach (var item in result.ReadAllAsync())
164-
{
165-
resultList.Add(item);
166-
}
167-
168-
var errorList = new List<FileValidationResult>();
169-
await foreach (var error in errors.ReadAllAsync())
170-
{
171-
errorList.Add(error);
172-
}
173-
174-
// Verify file was written to files section
175-
Assert.AreEqual(1, resultList.Count);
176-
Assert.AreEqual(0, errorList.Count);
177-
178-
// Verification of both IDs being recorded happens in the mock setup
179-
}
180137
}

0 commit comments

Comments
 (0)