Skip to content

Commit f78f845

Browse files
committed
Fix serialization of Type
1 parent 800ffa1 commit f78f845

File tree

9 files changed

+66
-69
lines changed

9 files changed

+66
-69
lines changed

Dependencies.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<ForEvolveXunitVersion Condition="'$(FOREVOLVE_XUNIT_VERSION)'==''">2.4.1</ForEvolveXunitVersion>
2525
<ForEvolveMoqVersion Condition="'$(FOREVOLVE_MOQ_VERSION)'==''">4.14.1</ForEvolveMoqVersion>
2626
<ForEvolveTestSdkVersion Condition="'$(FOREVOLVE_TEST_SDK_VERSION)'==''">16.6.1</ForEvolveTestSdkVersion>
27-
<ForEvolveAspNetCoreTestHostVersion Condition="'$(FOREVOLVE_ASPNETCORE_TESTHOST_VERSION)'==''">5.0.0-preview.3.20215.14</ForEvolveAspNetCoreTestHostVersion>
27+
<ForEvolveAspNetCoreTestHostVersion Condition="'$(FOREVOLVE_ASPNETCORE_TESTHOST_VERSION)'==''">5.0.0</ForEvolveAspNetCoreTestHostVersion>
2828
</PropertyGroup>
2929

3030
</Project>

src/ForEvolve.OperationResults.AspNetCore/MediatR/ValidationBehavior.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,11 @@ private static IMessage Map(ValidationFailure validationFailure)
6464
});
6565
}
6666

67-
private static OperationMessageLevel Map(Severity severity)
67+
private static OperationMessageLevel Map(Severity severity) => severity switch
6868
{
69-
switch (severity)
70-
{
71-
case Severity.Warning:
72-
return OperationMessageLevel.Warning;
73-
case Severity.Info:
74-
return OperationMessageLevel.Information;
75-
default:
76-
return OperationMessageLevel.Error;
77-
}
78-
}
69+
Severity.Warning => OperationMessageLevel.Warning,
70+
Severity.Info => OperationMessageLevel.Information,
71+
_ => OperationMessageLevel.Error,
72+
};
7973
}
8074
}

src/ForEvolve.OperationResults/ExceptionMessage.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
23
using System.Text.Json.Serialization;
34

45
namespace ForEvolve.OperationResults

src/ForEvolve.OperationResults/IMessage.cs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Text.Json.Serialization;
34

45
namespace ForEvolve.OperationResults
56
{
@@ -24,6 +25,7 @@ public interface IMessage
2425
/// Gets the message type.
2526
/// </summary>
2627
/// <value>The type of message.</value>
28+
[JsonIgnore]
2729
Type Type { get; }
2830

2931
/// <summary>

src/ForEvolve.OperationResults/Message.cs

+45-44
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
23
using System.Collections.Generic;
34
using System.ComponentModel;
45
using System.Text.Json.Serialization;
@@ -207,52 +208,52 @@ protected void LoadProblemDetails(ProblemDetails problemDetails)
207208
}
208209

209210

210-
/// <summary>
211-
/// A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
212-
/// </summary>
213-
public class ProblemDetails
214-
{
215-
/// <summary>
216-
/// A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when
217-
/// dereferenced, it provide human-readable documentation for the problem type
218-
/// (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be
219-
/// "about:blank".
220-
/// </summary>
221-
public string Type { get; set; }
211+
///// <summary>
212+
///// A machine-readable format for specifying errors in HTTP API responses based on https://tools.ietf.org/html/rfc7807.
213+
///// </summary>
214+
//public class ProblemDetails
215+
//{
216+
// /// <summary>
217+
// /// A URI reference [RFC3986] that identifies the problem type. This specification encourages that, when
218+
// /// dereferenced, it provide human-readable documentation for the problem type
219+
// /// (e.g., using HTML [W3C.REC-html5-20141028]). When this member is not present, its value is assumed to be
220+
// /// "about:blank".
221+
// /// </summary>
222+
// public string Type { get; set; }
222223

223-
/// <summary>
224-
/// A short, human-readable summary of the problem type.It SHOULD NOT change from occurrence to occurrence
225-
/// of the problem, except for purposes of localization(e.g., using proactive content negotiation;
226-
/// see[RFC7231], Section 3.4).
227-
/// </summary>
228-
public string Title { get; set; }
224+
// /// <summary>
225+
// /// A short, human-readable summary of the problem type.It SHOULD NOT change from occurrence to occurrence
226+
// /// of the problem, except for purposes of localization(e.g., using proactive content negotiation;
227+
// /// see[RFC7231], Section 3.4).
228+
// /// </summary>
229+
// public string Title { get; set; }
229230

230-
/// <summary>
231-
/// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
232-
/// </summary>
233-
public int? Status { get; set; }
231+
// /// <summary>
232+
// /// The HTTP status code([RFC7231], Section 6) generated by the origin server for this occurrence of the problem.
233+
// /// </summary>
234+
// public int? Status { get; set; }
234235

235-
/// <summary>
236-
/// A human-readable explanation specific to this occurrence of the problem.
237-
/// </summary>
238-
public string Detail { get; set; }
236+
// /// <summary>
237+
// /// A human-readable explanation specific to this occurrence of the problem.
238+
// /// </summary>
239+
// public string Detail { get; set; }
239240

240-
/// <summary>
241-
/// A URI reference that identifies the specific occurrence of the problem.It may or may not yield further information if dereferenced.
242-
/// </summary>
243-
public string Instance { get; set; }
241+
// /// <summary>
242+
// /// A URI reference that identifies the specific occurrence of the problem.It may or may not yield further information if dereferenced.
243+
// /// </summary>
244+
// public string Instance { get; set; }
244245

245-
/// <summary>
246-
/// Gets the <see cref="IDictionary{TKey, TValue}"/> for extension members.
247-
/// <para>
248-
/// Problem type definitions MAY extend the problem details object with additional members. Extension members appear in the same namespace as
249-
/// other members of a problem type.
250-
/// </para>
251-
/// </summary>
252-
/// <remarks>
253-
/// The round-tripping behavior for <see cref="Extensions"/> is determined by the implementation of the Input \ Output formatters.
254-
/// In particular, complex types or collection types may not round-trip to the original type when using the built-in JSON or XML formatters.
255-
/// </remarks>
256-
public IDictionary<string, object> Extensions { get; } = new Dictionary<string, object>(StringComparer.Ordinal);
257-
}
246+
// /// <summary>
247+
// /// Gets the <see cref="IDictionary{TKey, TValue}"/> for extension members.
248+
// /// <para>
249+
// /// Problem type definitions MAY extend the problem details object with additional members. Extension members appear in the same namespace as
250+
// /// other members of a problem type.
251+
// /// </para>
252+
// /// </summary>
253+
// /// <remarks>
254+
// /// The round-tripping behavior for <see cref="Extensions"/> is determined by the implementation of the Input \ Output formatters.
255+
// /// In particular, complex types or collection types may not round-trip to the original type when using the built-in JSON or XML formatters.
256+
// /// </remarks>
257+
// public IDictionary<string, object> Extensions { get; } = new Dictionary<string, object>(StringComparer.Ordinal);
258+
//}
258259
}

src/ForEvolve.OperationResults/OperationResult.cs

+5-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using System;
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
3+
using System.Text.Json.Serialization;
24

35
namespace ForEvolve.OperationResults
46
{
@@ -10,15 +12,10 @@ namespace ForEvolve.OperationResults
1012
public class OperationResult : IOperationResult
1113
{
1214
/// <inheritdoc />
13-
#if SYSTEM_TEXT_JSON
14-
[System.Text.Json.Serialization.JsonIgnore]
15-
#endif
15+
[JsonIgnore]
1616
public bool Succeeded => !Messages.HasError();
1717

1818
/// <inheritdoc />
19-
#if SYSTEM_TEXT_JSON
20-
[System.Text.Json.Serialization.JsonIgnore]
21-
#endif
2219
public MessageCollection Messages { get; } = new MessageCollection();
2320

2421
/// <inheritdoc />
@@ -214,7 +211,7 @@ public static TOperationResult OnFailure<TOperationResult>(this TOperationResult
214211
}
215212

216213
/// <summary>
217-
/// DELETE ME
214+
/// TODO: DELETE ME
218215
/// </summary>
219216
class MyClass
220217
{

test/Directory.Build.props

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
<PropertyGroup>
44
<IsPackable>false</IsPackable>
55
</PropertyGroup>
6-
6+
77
<ItemGroup>
8-
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.0-preview.3.20215.14" />
8+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="5.0.0" />
99
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="$(ForEvolveAspNetCoreTestHostVersion)" />
1010
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(ForEvolveTestSdkVersion)" />
1111
<PackageReference Include="Moq" Version="$(ForEvolveMoqVersion)" />
@@ -16,5 +16,5 @@
1616
<ItemGroup>
1717
<PackageReference Include="ForEvolve.Testing" Version="$(ForEvolveTestingVersion)" />
1818
</ItemGroup>
19-
19+
2020
</Project>

test/ForEvolve.OperationResults.AspNetCore.Tests/OperationResultSerializationTest.cs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Text;
55
using System.Text.Json;
6+
using System.Text.Json.Serialization;
67
using System.Threading.Tasks;
78
using Xunit;
89

test/ForEvolve.OperationResults.Tests/OperationResultTest.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Microsoft.AspNetCore.Mvc;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;

0 commit comments

Comments
 (0)