Skip to content

Commit c97f2d1

Browse files
CopilotDaveTryon
andcommitted
Implement @DaveTryon's suggestion using Result property approach
Co-authored-by: DaveTryon <45672944+DaveTryon@users.noreply.github.com>
1 parent 76b439c commit c97f2d1

5 files changed

Lines changed: 19 additions & 3 deletions

File tree

src/Microsoft.Sbom.Api/Output/Telemetry/IRecorder.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Threading.Tasks;
77
using Microsoft.Sbom.Api.Entities;
8+
using Microsoft.Sbom.Api.Entities.Output;
89
using Microsoft.Sbom.Extensions.Entities;
910

1011
namespace Microsoft.Sbom.Api.Output.Telemetry;
@@ -105,4 +106,9 @@ public interface IRecorder
105106
/// Record telemetry for an AggregationSource.
106107
/// </summary>
107108
public void RecordAggregationSource(string identifier, int packageCount, int relationshipCount);
109+
110+
/// <summary>
111+
/// Gets the result status of the recorder execution.
112+
/// </summary>
113+
public Result Result { get; }
108114
}

src/Microsoft.Sbom.Api/Output/Telemetry/TelemetryRecorder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ public async Task LogException(Exception exception)
124124

125125
public IList<Exception> Exceptions => exceptions;
126126

127+
public Result Result => result;
128+
127129
/// <summary>
128130
/// Start recording the duration of exeuction of the given event.
129131
/// </summary>

src/Microsoft.Sbom.Api/SbomValidator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Threading.Tasks;
1010
using Microsoft.Sbom.Api.Config;
1111
using Microsoft.Sbom.Api.Config.Extensions;
12+
using Microsoft.Sbom.Api.Entities.Output;
1213
using Microsoft.Sbom.Api.Output.Telemetry;
1314
using Microsoft.Sbom.Api.Workflows;
1415
using Microsoft.Sbom.Common;
@@ -104,8 +105,7 @@ public async Task<SbomValidationResult> ValidateSbomAsync(
104105
await recorder.FinalizeAndLogTelemetryAsync();
105106

106107
var errors = recorder.Errors.Select(error => error.ToEntityError()).ToList();
107-
var hasExceptions = recorder.Exceptions.Any();
108-
return new SbomValidationResult(!errors.Any() && !hasExceptions, errors);
108+
return new SbomValidationResult(recorder.Result == Result.Success, errors);
109109
}
110110

111111
private InputConfiguration ValidateConfig(InputConfiguration config)

test/Microsoft.Sbom.Api.Tests/SbomValidatorTests.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Threading.Tasks;
78
using Microsoft.Sbom.Api.Entities;
9+
using Microsoft.Sbom.Api.Entities.Output;
810
using Microsoft.Sbom.Api.Output.Telemetry;
911
using Microsoft.Sbom.Api.Workflows;
1012
using Microsoft.Sbom.Common;
@@ -89,7 +91,10 @@ private void SetupMocksForValidation(List<FileValidationResult> errors, List<Exc
8991

9092
recorderMock.Setup(r => r.FinalizeAndLogTelemetryAsync()).Returns(Task.CompletedTask);
9193
recorderMock.Setup(r => r.Errors).Returns(errors);
92-
recorderMock.Setup(r => r.Exceptions).Returns(exceptions);
94+
95+
// Determine the result based on whether there are errors or exceptions
96+
var result = (errors.Any() || exceptions.Any()) ? Result.Failure : Result.Success;
97+
recorderMock.Setup(r => r.Result).Returns(result);
9398
}
9499

95100
[TestMethod]

test/Microsoft.Sbom.Api.Tests/VersionSpecificPins/Version_4_0/InterfaceConcretionTests.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Sbom.Api.Config.Args;
1616
using Microsoft.Sbom.Api.Convertors;
1717
using Microsoft.Sbom.Api.Entities;
18+
using Microsoft.Sbom.Api.Entities.Output;
1819
using Microsoft.Sbom.Api.Executors;
1920
using Microsoft.Sbom.Api.Filters;
2021
using Microsoft.Sbom.Api.FormatValidator;
@@ -130,6 +131,8 @@ private class PinnedIRecorder : IRecorder
130131

131132
public IList<Exception> Exceptions => throw new NotImplementedException();
132133

134+
public Result Result => throw new NotImplementedException();
135+
133136
public void AddResult(string propertyName, string value) => throw new NotImplementedException();
134137
public void AddToTotalCountOfLicenses(int count) => throw new NotImplementedException();
135138
public void AddToTotalNumberOfPackageDetailsEntries(int count) => throw new NotImplementedException();

0 commit comments

Comments
 (0)