Skip to content

Commit 7c173f4

Browse files
fixed failing tests
1 parent dd9b385 commit 7c173f4

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

src/OneBitSoftware.Utilities.OperationResult.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OneBitSoftware.Utilities.Op
77
EndProject
88
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneBitSoftware.Utilities.OperationResultTests", "..\tests\OneBitSoftware.Utilities.OperationResultTests\OneBitSoftware.Utilities.OperationResultTests.csproj", "{142313C6-5DC0-4428-AE63-487B8D41552E}"
99
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{02EA681E-C7D8-13C7-8484-4AC65E1B71E8}"
11+
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{6F29D051-AD77-482A-99A7-4E5ED288AB22}"
13+
ProjectSection(SolutionItems) = preProject
14+
..\.github\workflows\main.yml = ..\.github\workflows\main.yml
15+
..\.github\workflows\pull-request-validation.yml = ..\.github\workflows\pull-request-validation.yml
16+
EndProjectSection
17+
EndProject
1018
Global
1119
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1220
Debug|Any CPU = Debug|Any CPU
@@ -25,6 +33,9 @@ Global
2533
GlobalSection(SolutionProperties) = preSolution
2634
HideSolutionNode = FALSE
2735
EndGlobalSection
36+
GlobalSection(NestedProjects) = preSolution
37+
{6F29D051-AD77-482A-99A7-4E5ED288AB22} = {02EA681E-C7D8-13C7-8484-4AC65E1B71E8}
38+
EndGlobalSection
2839
GlobalSection(ExtensibilityGlobals) = postSolution
2940
SolutionGuid = {3A384A11-1CD9-4A02-A6BB-3EC782DBF254}
3041
EndGlobalSection

src/OneBitSoftware.Utilities.OperationResult/Errors/OperationError.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
public class OperationError : IOperationError
77
{
8-
public OperationError(string? message = null, int? code = null, string? details = null)
8+
public OperationError(string? message = null, int? code = null, string? details = null, LogLevel? logLevel = null)
99
{
1010
this.Message = message;
1111
this.Code = code;
1212
this.Details = details;
13+
this.LogLevel = logLevel;
1314
}
1415

1516
public int? Code { get; set; }

src/OneBitSoftware.Utilities.OperationResult/OperationResult.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public OperationResult AppendError(string message, int? code = null, LogLevel? l
120120
{
121121
if (string.IsNullOrWhiteSpace(message)) throw new ArgumentNullException(nameof(message));
122122

123-
var error = new OperationError(message, code) { Details = details };
123+
var error = new OperationError(message, code) { Details = details, LogLevel = logLevel };
124124
this.AppendError(error, logLevel);
125125

126126
return this;
@@ -140,7 +140,7 @@ public OperationResult AppendError<T>(string message, int? code = null, LogLevel
140140
{
141141
if (string.IsNullOrWhiteSpace(message)) throw new ArgumentNullException(nameof(message));
142142

143-
var error = new T() { Message = message, Code = code, Details = details };
143+
var error = new T() { Message = message, Code = code, Details = details, LogLevel = logLevel };
144144
this.AppendError(error, logLevel);
145145

146146
return this;
@@ -179,7 +179,7 @@ public OperationResult AppendException(Exception exception, int? errorCode = nul
179179
// Append the exception as a first if it is not yet set.
180180
this.InitialException ??= exception;
181181

182-
var error = new OperationError(exception.ToString(), errorCode);
182+
var error = new OperationError(exception.ToString(), errorCode, null, LogLevel.Error);
183183
this.AppendError(error, logLevel);
184184

185185
return this;

tests/OneBitSoftware.Utilities.OperationResultTests/Serialization/OperationResultSerializationSystemTextJsonTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task SerializeWithSystemTextJsonIncludesTypeDiscriminator()
5656
// Assert
5757
Assert.Contains(testText, text);
5858
Assert.Contains(operationErrorText, text);
59-
var expectText = @"{""Success"":false,""Errors"":[{""type"":""operation_error"",""Code"":123,""Message"":""Test"",""Details"":""\u0022type\u0022""}]}";
59+
var expectText = @"{""Success"":false,""Errors"":[{""type"":""operation_error"",""Code"":123,""Message"":""Test"",""Details"":""\u0022type\u0022"",""LogLevel"":null}]}";
6060
Assert.Equal(expectText, text);
6161
}
6262

@@ -67,15 +67,15 @@ public async Task SerializeWithSystemTextJsonSetsExpectedJson()
6767
var testText = "\"type\"";
6868
var outputStream = new MemoryStream();
6969
var operationResult = new OperationResult();
70-
operationResult.AppendError(new OperationError(message: "Test") { Code = 123, Details = testText });
70+
operationResult.AppendError(new OperationError(message: "Test") { Code = 123, Details = testText, LogLevel = Microsoft.Extensions.Logging.LogLevel.Warning });
7171

7272
// Act
7373
await JsonSerializer.SerializeAsync(outputStream, operationResult, GetSerializationOptions());
7474
outputStream.Position = 0;
7575
string text = new StreamReader(outputStream).ReadToEnd();
7676

7777
// Assert
78-
var expectText = @"{""Success"":false,""Errors"":[{""type"":""operation_error"",""Code"":123,""Message"":""Test"",""Details"":""\u0022type\u0022""}]}";
78+
var expectText = @"{""Success"":false,""Errors"":[{""type"":""operation_error"",""Code"":123,""Message"":""Test"",""Details"":""\u0022type\u0022"",""LogLevel"":3}]}";
7979
Assert.Equal(expectText, text);
8080
}
8181

0 commit comments

Comments
 (0)