Skip to content

Commit bd28863

Browse files
committed
constants
1 parent f0f9bfd commit bd28863

18 files changed

Lines changed: 733 additions & 120 deletions

File tree

‎ManagedCode.Communication.Tests/Results/ResultJsonInteropTests.cs‎

Lines changed: 404 additions & 0 deletions
Large diffs are not rendered by default.

‎ManagedCode.Communication/CollectionResultT/CollectionResult.cs‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ internal static CollectionResult<T> CreateFailed(Problem problem, T[]? collectio
4747
/// Whether the operation succeeded.
4848
/// </summary>
4949
[JsonInclude]
50-
[JsonPropertyName("isSuccess")]
50+
[JsonPropertyName(CommunicationJsonNames.IsSuccess)]
5151
[JsonPropertyOrder(1)]
5252
[MemberNotNullWhen(true, nameof(Collection))]
5353
[MemberNotNullWhen(false, nameof(Problem))]
@@ -63,7 +63,7 @@ internal static CollectionResult<T> CreateFailed(Problem problem, T[]? collectio
6363
/// <summary>
6464
/// The items on this page. Empty when the result failed.
6565
/// </summary>
66-
[JsonPropertyName("collection")]
66+
[JsonPropertyName(CommunicationJsonNames.Collection)]
6767
[JsonPropertyOrder(2)]
6868
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
6969
public T[] Collection { get; init; } = [];
@@ -77,33 +77,33 @@ internal static CollectionResult<T> CreateFailed(Problem problem, T[]? collectio
7777
/// <summary>
7878
/// 1-based index of this page.
7979
/// </summary>
80-
[JsonPropertyName("pageNumber")]
80+
[JsonPropertyName(CommunicationJsonNames.PageNumber)]
8181
[JsonPropertyOrder(3)]
8282
public int PageNumber { get; init; }
8383

8484
/// <summary>
8585
/// Maximum number of items per page.
8686
/// </summary>
87-
[JsonPropertyName("pageSize")]
87+
[JsonPropertyName(CommunicationJsonNames.PageSize)]
8888
[JsonPropertyOrder(4)]
8989
public int PageSize { get; init; }
9090

9191
/// <summary>
9292
/// Total number of items across all pages.
9393
/// </summary>
94-
[JsonPropertyName("totalItems")]
94+
[JsonPropertyName(CommunicationJsonNames.TotalItems)]
9595
[JsonPropertyOrder(5)]
9696
public int TotalItems { get; init; }
9797

9898
/// <summary>
9999
/// Total number of pages.
100100
/// </summary>
101-
[JsonPropertyName("totalPages")]
101+
[JsonPropertyName(CommunicationJsonNames.TotalPages)]
102102
[JsonPropertyOrder(6)]
103103
public int TotalPages { get; init; }
104104

105105
[JsonInclude]
106-
[JsonPropertyName("problem")]
106+
[JsonPropertyName(CommunicationJsonNames.Problem)]
107107
[JsonPropertyOrder(7)]
108108
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
109109
private Problem? _problem;

‎ManagedCode.Communication/Commands/Command.cs‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,76 +33,76 @@ protected Command(Guid commandId, string commandType)
3333
/// Identity of the command. Generated as a time-ordered UUIDv7 unless supplied.
3434
/// </summary>
3535

36-
[JsonPropertyName("commandId")]
36+
[JsonPropertyName(CommunicationJsonNames.CommandId)]
3737
[JsonPropertyOrder(1)]
3838
public Guid CommandId { get; set; }
3939
/// <summary>
4040
/// Logical name of the command.
4141
/// </summary>
4242

43-
[JsonPropertyName("commandType")]
43+
[JsonPropertyName(CommunicationJsonNames.CommandType)]
4444
[JsonPropertyOrder(2)]
4545
public string CommandType { get; set; }
4646
/// <summary>
4747
/// When the command was created (UTC).
4848
/// </summary>
4949

50-
[JsonPropertyName("timestamp")]
50+
[JsonPropertyName(CommunicationJsonNames.Timestamp)]
5151
[JsonPropertyOrder(3)]
5252
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
5353
/// <summary>
5454
/// Ties this command to every other operation in the same logical flow. Not generated — set it yourself.
5555
/// </summary>
5656

57-
[JsonPropertyName("correlationId")]
57+
[JsonPropertyName(CommunicationJsonNames.CorrelationId)]
5858
[JsonPropertyOrder(4)]
5959
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
6060
public string? CorrelationId { get; set; }
6161
/// <summary>
6262
/// Identity of the command that caused this one. Not generated — set it yourself.
6363
/// </summary>
6464

65-
[JsonPropertyName("causationId")]
65+
[JsonPropertyName(CommunicationJsonNames.CausationId)]
6666
[JsonPropertyOrder(5)]
6767
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
6868
public string? CausationId { get; set; }
6969
/// <summary>
7070
/// Distributed-tracing trace identifier.
7171
/// </summary>
7272

73-
[JsonPropertyName("traceId")]
73+
[JsonPropertyName(CommunicationJsonNames.TraceId)]
7474
[JsonPropertyOrder(6)]
7575
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
7676
public string? TraceId { get; set; }
7777
/// <summary>
7878
/// Distributed-tracing span identifier.
7979
/// </summary>
8080

81-
[JsonPropertyName("spanId")]
81+
[JsonPropertyName(CommunicationJsonNames.SpanId)]
8282
[JsonPropertyOrder(7)]
8383
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8484
public string? SpanId { get; set; }
8585
/// <summary>
8686
/// User on whose behalf the command runs.
8787
/// </summary>
8888

89-
[JsonPropertyName("userId")]
89+
[JsonPropertyName(CommunicationJsonNames.UserId)]
9090
[JsonPropertyOrder(8)]
9191
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
9292
public string? UserId { get; set; }
9393
/// <summary>
9494
/// Session the command belongs to.
9595
/// </summary>
9696

97-
[JsonPropertyName("sessionId")]
97+
[JsonPropertyName(CommunicationJsonNames.SessionId)]
9898
[JsonPropertyOrder(9)]
9999
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
100100
public string? SessionId { get; set; }
101101
/// <summary>
102102
/// Execution policy and free-form metadata.
103103
/// </summary>
104104

105-
[JsonPropertyName("metadata")]
105+
[JsonPropertyName(CommunicationJsonNames.Metadata)]
106106
[JsonPropertyOrder(10)]
107107
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
108108
public CommandMetadata? Metadata { get; set; }

‎ManagedCode.Communication/Commands/CommandMetadata.cs‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,108 +23,108 @@ public CommandMetadata()
2323
/// <summary>
2424
/// Schema version of this metadata, so consumers can evolve the shape.
2525
/// </summary>
26-
[JsonPropertyName("version")]
26+
[JsonPropertyName(CommunicationJsonNames.Version)]
2727
public uint Version { get; set; } = 1;
2828

2929
/// <summary>
3030
/// Arbitrary properties attached by the application.
3131
/// </summary>
32-
[JsonPropertyName("properties")]
32+
[JsonPropertyName(CommunicationJsonNames.Properties)]
3333
public Dictionary<string, object?> Properties { get; set; }
3434

3535
/// <summary>
3636
/// Who or what issued the command.
3737
/// </summary>
38-
[JsonPropertyName("initiatedBy")]
38+
[JsonPropertyName(CommunicationJsonNames.InitiatedBy)]
3939
public string? InitiatedBy { get; set; }
4040

4141
/// <summary>
4242
/// System or component the command came from.
4343
/// </summary>
44-
[JsonPropertyName("source")]
44+
[JsonPropertyName(CommunicationJsonNames.Source)]
4545
public string? Source { get; set; }
4646

4747
/// <summary>
4848
/// System or component the command is aimed at.
4949
/// </summary>
50-
[JsonPropertyName("target")]
50+
[JsonPropertyName(CommunicationJsonNames.Target)]
5151
public string? Target { get; set; }
5252

5353
/// <summary>
5454
/// Caller's IP address, when known.
5555
/// </summary>
56-
[JsonPropertyName("ipAddress")]
56+
[JsonPropertyName(CommunicationJsonNames.IpAddress)]
5757
public string? IpAddress { get; set; }
5858

5959
/// <summary>
6060
/// Caller's user agent, when known.
6161
/// </summary>
62-
[JsonPropertyName("userAgent")]
62+
[JsonPropertyName(CommunicationJsonNames.UserAgent)]
6363
public string? UserAgent { get; set; }
6464

6565
/// <summary>
6666
/// Session the command belongs to.
6767
/// </summary>
68-
[JsonPropertyName("sessionId")]
68+
[JsonPropertyName(CommunicationJsonNames.SessionId)]
6969
public string? SessionId { get; set; }
7070

7171
/// <summary>
7272
/// Distributed-tracing trace identifier.
7373
/// </summary>
74-
[JsonPropertyName("traceId")]
74+
[JsonPropertyName(CommunicationJsonNames.TraceId)]
7575
public string? TraceId { get; set; }
7676

7777
/// <summary>
7878
/// Distributed-tracing span identifier.
7979
/// </summary>
80-
[JsonPropertyName("spanId")]
80+
[JsonPropertyName(CommunicationJsonNames.SpanId)]
8181
public string? SpanId { get; set; }
8282

8383
/// <summary>
8484
/// Relative execution priority. Defaults to <c>Normal</c>.
8585
/// </summary>
86-
[JsonPropertyName("priority")]
86+
[JsonPropertyName(CommunicationJsonNames.Priority)]
8787
public CommandPriority Priority { get; set; } = CommandPriority.Normal;
8888

8989
/// <summary>
9090
/// How many times execution has already been retried.
9191
/// </summary>
92-
[JsonPropertyName("retryCount")]
92+
[JsonPropertyName(CommunicationJsonNames.RetryCount)]
9393
public int RetryCount { get; set; }
9494

9595
/// <summary>
9696
/// Retry budget before the command is abandoned. Defaults to 3.
9797
/// </summary>
98-
[JsonPropertyName("maxRetries")]
98+
[JsonPropertyName(CommunicationJsonNames.MaxRetries)]
9999
public int MaxRetries { get; set; } = 3;
100100

101101
/// <summary>
102102
/// Execution timeout in seconds. Defaults to 30.
103103
/// </summary>
104-
[JsonPropertyName("timeoutSeconds")]
104+
[JsonPropertyName(CommunicationJsonNames.TimeoutSeconds)]
105105
public int TimeoutSeconds { get; set; } = 30;
106106

107107
/// <summary>
108108
/// How long execution took, filled in once the command completes.
109109
/// </summary>
110-
[JsonPropertyName("executionTime")]
110+
[JsonPropertyName(CommunicationJsonNames.ExecutionTime)]
111111
public TimeSpan ExecutionTime { get; set; }
112112

113113
/// <summary>
114114
/// How long the command stays valid; <c>null</c> means it does not expire.
115115
/// </summary>
116-
[JsonPropertyName("timeToLiveSeconds")]
116+
[JsonPropertyName(CommunicationJsonNames.TimeToLiveSeconds)]
117117
public int? TimeToLiveSeconds { get; set; }
118118

119119
/// <summary>
120120
/// String tags for routing, filtering or reporting.
121121
/// </summary>
122-
[JsonPropertyName("tags")]
122+
[JsonPropertyName(CommunicationJsonNames.Tags)]
123123
public Dictionary<string, string> Tags { get; set; }
124124

125125
/// <summary>
126126
/// Extension slot for data that does not fit the fields above.
127127
/// </summary>
128-
[JsonPropertyName("extensions")]
128+
[JsonPropertyName(CommunicationJsonNames.Extensions)]
129129
public Dictionary<string, object?> Extensions { get; set; }
130130
}

‎ManagedCode.Communication/Commands/CommandT.cs‎

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,84 +45,84 @@ protected Command(Guid commandId, string commandType, T? value)
4545
/// Identity of the command. Generated as a time-ordered UUIDv7 unless supplied.
4646
/// </summary>
4747

48-
[JsonPropertyName("commandId")]
48+
[JsonPropertyName(CommunicationJsonNames.CommandId)]
4949
[JsonPropertyOrder(1)]
5050
public Guid CommandId { get; set; }
5151
/// <summary>
5252
/// Logical name of the command.
5353
/// </summary>
5454

55-
[JsonPropertyName("commandType")]
55+
[JsonPropertyName(CommunicationJsonNames.CommandType)]
5656
[JsonPropertyOrder(2)]
5757
public string CommandType { get; set; }
5858
/// <summary>
5959
/// The payload.
6060
/// </summary>
6161

62-
[JsonPropertyName("value")]
62+
[JsonPropertyName(CommunicationJsonNames.Value)]
6363
[JsonPropertyOrder(3)]
6464
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingDefault)]
6565
public T? Value { get; set; }
6666
/// <summary>
6767
/// When the command was created (UTC).
6868
/// </summary>
6969

70-
[JsonPropertyName("timestamp")]
70+
[JsonPropertyName(CommunicationJsonNames.Timestamp)]
7171
[JsonPropertyOrder(4)]
7272
public DateTime Timestamp { get; set; } = DateTime.UtcNow;
7373
/// <summary>
7474
/// Ties this command to every other operation in the same logical flow. Not generated — set it yourself.
7575
/// </summary>
7676

77-
[JsonPropertyName("correlationId")]
77+
[JsonPropertyName(CommunicationJsonNames.CorrelationId)]
7878
[JsonPropertyOrder(5)]
7979
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8080
public string? CorrelationId { get; set; }
8181
/// <summary>
8282
/// Identity of the command that caused this one. Not generated — set it yourself.
8383
/// </summary>
8484

85-
[JsonPropertyName("causationId")]
85+
[JsonPropertyName(CommunicationJsonNames.CausationId)]
8686
[JsonPropertyOrder(6)]
8787
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
8888
public string? CausationId { get; set; }
8989
/// <summary>
9090
/// Distributed-tracing trace identifier.
9191
/// </summary>
9292

93-
[JsonPropertyName("traceId")]
93+
[JsonPropertyName(CommunicationJsonNames.TraceId)]
9494
[JsonPropertyOrder(7)]
9595
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
9696
public string? TraceId { get; set; }
9797
/// <summary>
9898
/// Distributed-tracing span identifier.
9999
/// </summary>
100100

101-
[JsonPropertyName("spanId")]
101+
[JsonPropertyName(CommunicationJsonNames.SpanId)]
102102
[JsonPropertyOrder(8)]
103103
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
104104
public string? SpanId { get; set; }
105105
/// <summary>
106106
/// User on whose behalf the command runs.
107107
/// </summary>
108108

109-
[JsonPropertyName("userId")]
109+
[JsonPropertyName(CommunicationJsonNames.UserId)]
110110
[JsonPropertyOrder(9)]
111111
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
112112
public string? UserId { get; set; }
113113
/// <summary>
114114
/// Session the command belongs to.
115115
/// </summary>
116116

117-
[JsonPropertyName("sessionId")]
117+
[JsonPropertyName(CommunicationJsonNames.SessionId)]
118118
[JsonPropertyOrder(10)]
119119
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
120120
public string? SessionId { get; set; }
121121
/// <summary>
122122
/// Execution policy and free-form metadata.
123123
/// </summary>
124124

125-
[JsonPropertyName("metadata")]
125+
[JsonPropertyName(CommunicationJsonNames.Metadata)]
126126
[JsonPropertyOrder(11)]
127127
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
128128
public CommandMetadata? Metadata { get; set; }

0 commit comments

Comments
 (0)