Skip to content

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed
 

‎src/LCT.Common.UTests/PipelineArtifactUploaderTest.cs

+20-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// SPDX-License-Identifier: MIT
55
// --------------------------------------------------------------------------------------------------------------------
66

7+
using log4net.Appender;
8+
using log4net.Config;
79
using NUnit.Framework;
810
using System;
911
using System.IO;
@@ -14,6 +16,7 @@ namespace LCT.Common.UTest
1416
public class PipelineArtifactUploaderTests
1517
{
1618
private StringWriter consoleOutput;
19+
private MemoryAppender memoryAppender;
1720

1821
[SetUp]
1922
public void SetUp()
@@ -58,13 +61,19 @@ public void UploadLogs_ShouldNotUpload_WhenInUnknownEnvironment()
5861
{
5962
// Arrange
6063
Environment.SetEnvironmentVariable("Build_BuildId", null); // No pipeline detected
61-
64+
memoryAppender = new MemoryAppender();
65+
BasicConfigurator.Configure(memoryAppender);
6266
// Act
6367
PipelineArtifactUploader.UploadLogs();
64-
string output = consoleOutput.ToString().Trim();
68+
69+
string expectedlogmessage = "Uploading of logs is not supported.";
70+
71+
var logEvents = memoryAppender.GetEvents();
6572

6673
// Assert
67-
Assert.AreNotEqual(output, "Uploading of SBOM is not supported.");
74+
Assert.IsNotEmpty(logEvents);
75+
var actualLogMessage = logEvents[0].RenderedMessage;
76+
Assert.AreEqual(expectedlogmessage, actualLogMessage);
6877
}
6978

7079
[Test]
@@ -91,13 +100,18 @@ public void UploadBom_ShouldNotUpload_WhenInUnknownEnvironment()
91100
{
92101
// Arrange
93102
Environment.SetEnvironmentVariable("Build_BuildId", null); // No pipeline detected
94-
103+
memoryAppender = new MemoryAppender();
104+
BasicConfigurator.Configure(memoryAppender);
95105
// Act
96106
PipelineArtifactUploader.UploadBom();
97-
string output = consoleOutput.ToString().Trim();
107+
string expectedlogmessage = "Uploading of SBOM is not supported.";
108+
109+
var logEvents = memoryAppender.GetEvents();
98110

99111
// Assert
100-
Assert.AreEqual(output, "Uploading of SBOM is not supported.");
112+
Assert.IsNotEmpty(logEvents);
113+
var actualLogMessage = logEvents[0].RenderedMessage;
114+
Assert.AreEqual(expectedlogmessage, actualLogMessage);
101115
}
102116
}
103117
}

0 commit comments

Comments
 (0)
Please sign in to comment.