chore: Fix whitespace in all files
These changes were generated automatically by running "Analyze and Code Cleanup". Showing a diff ignoring whitespace shows the removal of the UTF-8 BOM from three files, but that's all. Signed-off-by: Jon Skeet <jonskeet@google.com>
This commit is contained in:
parent
b04c141707
commit
ae75b32c28
|
@ -25,7 +25,7 @@ namespace HttpSend
|
|||
[Option(Description = "CloudEvents 'type' (default: com.example.myevent)", LongName = "type", ShortName = "t")]
|
||||
private string Type { get; } = "com.example.myevent";
|
||||
|
||||
[Required,Option(Description = "HTTP(S) address to send the event to", LongName = "url", ShortName = "u"),]
|
||||
[Required, Option(Description = "HTTP(S) address to send the event to", LongName = "url", ShortName = "u"),]
|
||||
private Uri Url { get; }
|
||||
|
||||
public static int Main(string[] args) => CommandLineApplication.Execute<Program>(args);
|
||||
|
|
|
@ -92,7 +92,7 @@ namespace CloudNative.CloudEvents.Avro
|
|||
{
|
||||
throw new ArgumentException($"Record has no '{AttributeName}' field");
|
||||
}
|
||||
IDictionary<string, object> recordAttributes = (IDictionary<string, object>)attrObj;
|
||||
IDictionary<string, object> recordAttributes = (IDictionary<string, object>) attrObj;
|
||||
|
||||
if (!recordAttributes.TryGetValue(CloudEventsSpecVersion.SpecVersionAttribute.Name, out var versionId) ||
|
||||
!(versionId is string versionIdString))
|
||||
|
@ -131,7 +131,7 @@ namespace CloudNative.CloudEvents.Avro
|
|||
}
|
||||
else if (value is string)
|
||||
{
|
||||
cloudEvent.SetAttributeFromString(key, (string)value);
|
||||
cloudEvent.SetAttributeFromString(key, (string) value);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
throw new ArgumentException($"Structured mode content does not represent a CloudEvent");
|
||||
}
|
||||
var specVersion = CloudEventsSpecVersion.FromVersionId((string?) specVersionToken)
|
||||
?? throw new ArgumentException($"Unsupported CloudEvents spec version '{(string?)specVersionToken}'");
|
||||
?? throw new ArgumentException($"Unsupported CloudEvents spec version '{(string?) specVersionToken}'");
|
||||
|
||||
var cloudEvent = new CloudEvent(specVersion, extensionAttributes);
|
||||
PopulateAttributesFromStructuredEvent(cloudEvent, jObject);
|
||||
|
@ -247,10 +247,10 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
|
||||
string? attributeValue = value.Type switch
|
||||
{
|
||||
JTokenType.String => (string?)value,
|
||||
JTokenType.Boolean => CloudEventAttributeType.Boolean.Format((bool)value),
|
||||
JTokenType.String => (string?) value,
|
||||
JTokenType.Boolean => CloudEventAttributeType.Boolean.Format((bool) value),
|
||||
JTokenType.Null => null,
|
||||
JTokenType.Integer => CloudEventAttributeType.Integer.Format((int)value),
|
||||
JTokenType.Integer => CloudEventAttributeType.Integer.Format((int) value),
|
||||
_ => throw new ArgumentException($"Invalid token type '{value.Type}' for CloudEvent attribute")
|
||||
};
|
||||
if (attributeValue is null)
|
||||
|
@ -345,7 +345,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
{
|
||||
throw new ArgumentException($"Structured mode property '{DataBase64PropertyName}' must be a string, when present.");
|
||||
}
|
||||
cloudEvent.Data = Convert.FromBase64String((string?)dataBase64Token);
|
||||
cloudEvent.Data = Convert.FromBase64String((string?) dataBase64Token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -696,7 +696,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson
|
|||
/// <inheritdoc />
|
||||
protected override void EncodeStructuredModeData(CloudEvent cloudEvent, JsonWriter writer)
|
||||
{
|
||||
T data = (T)cloudEvent.Data;
|
||||
T data = (T) cloudEvent.Data;
|
||||
writer.WritePropertyName(DataPropertyName);
|
||||
Serializer.Serialize(writer, data);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -229,7 +229,7 @@ namespace CloudNative.CloudEvents.Protobuf
|
|||
// Note: impossible to cover in tests
|
||||
throw new ArgumentException($"Unhandled protobuf attribute case: {pair.Value.AttrCase}", paramName);
|
||||
}
|
||||
|
||||
|
||||
// If we've already got an extension attribute specified for this name,
|
||||
// we validate against it and require the value in the proto to have the right
|
||||
// type. Otherwise, we create a new extension attribute of the correct type.
|
||||
|
@ -254,7 +254,7 @@ namespace CloudNative.CloudEvents.Protobuf
|
|||
throw new ArgumentException(
|
||||
$"Attribute '{attr.Name}' was specified with type '{attr.Type}', but has type '{attrTypeFromProto}' in the protobuf representation.");
|
||||
}
|
||||
|
||||
|
||||
// Note: the indexer performs validation.
|
||||
cloudEvent[attr] = pair.Value.AttrCase switch
|
||||
{
|
||||
|
|
|
@ -331,7 +331,7 @@ namespace CloudNative.CloudEvents.SystemTextJson
|
|||
{
|
||||
// If no content type has been specified, default to application/json
|
||||
cloudEvent.DataContentType ??= JsonMediaType;
|
||||
|
||||
|
||||
DecodeStructuredModeDataProperty(dataElement, cloudEvent);
|
||||
}
|
||||
}
|
||||
|
@ -677,7 +677,7 @@ namespace CloudNative.CloudEvents.SystemTextJson
|
|||
{
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
T data = (T)cloudEvent.Data;
|
||||
T data = (T) cloudEvent.Data;
|
||||
return JsonSerializer.SerializeToUtf8Bytes(data, SerializerOptions);
|
||||
}
|
||||
|
||||
|
@ -697,7 +697,7 @@ namespace CloudNative.CloudEvents.SystemTextJson
|
|||
/// <inheritdoc />
|
||||
protected override void EncodeStructuredModeData(CloudEvent cloudEvent, Utf8JsonWriter writer)
|
||||
{
|
||||
T data = (T)cloudEvent.Data;
|
||||
T data = (T) cloudEvent.Data;
|
||||
writer.WritePropertyName(DataPropertyName);
|
||||
JsonSerializer.Serialize(writer, data, SerializerOptions);
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@ namespace CloudNative.CloudEvents
|
|||
Validation.CheckNotNull(attributeName, nameof(attributeName));
|
||||
Validation.CheckArgument(attributeName != CloudEventsSpecVersion.SpecVersionAttributeName, nameof(attributeName), () => Strings.ErrorCannotIndexBySpecVersionAttribute);
|
||||
return attributeValues.GetValueOrDefault(Validation.CheckNotNull(attributeName, nameof(attributeName)));
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
Validation.CheckNotNull(attributeName, nameof(attributeName));
|
||||
|
@ -229,7 +229,7 @@ namespace CloudNative.CloudEvents
|
|||
public string? DataContentType
|
||||
{
|
||||
// TODO: Guard against a version that doesn't have this attribute?
|
||||
get => (string?)this[SpecVersion.DataContentTypeAttribute];
|
||||
get => (string?) this[SpecVersion.DataContentTypeAttribute];
|
||||
set => this[SpecVersion.DataContentTypeAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -239,7 +239,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public string? Id
|
||||
{
|
||||
get => (string?)this[SpecVersion.IdAttribute];
|
||||
get => (string?) this[SpecVersion.IdAttribute];
|
||||
set => this[SpecVersion.IdAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -250,7 +250,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public Uri? DataSchema
|
||||
{
|
||||
get => (Uri?)this[SpecVersion.DataSchemaAttribute];
|
||||
get => (Uri?) this[SpecVersion.DataSchemaAttribute];
|
||||
set => this[SpecVersion.DataSchemaAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -262,7 +262,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public Uri? Source
|
||||
{
|
||||
get => (Uri?)this[SpecVersion.SourceAttribute];
|
||||
get => (Uri?) this[SpecVersion.SourceAttribute];
|
||||
set => this[SpecVersion.SourceAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -280,7 +280,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public string? Subject
|
||||
{
|
||||
get => (string?)this[SpecVersion.SubjectAttribute];
|
||||
get => (string?) this[SpecVersion.SubjectAttribute];
|
||||
set => this[SpecVersion.SubjectAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -290,7 +290,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public DateTimeOffset? Time
|
||||
{
|
||||
get => (DateTimeOffset?)this[SpecVersion.TimeAttribute];
|
||||
get => (DateTimeOffset?) this[SpecVersion.TimeAttribute];
|
||||
set => this[SpecVersion.TimeAttribute] = value;
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ namespace CloudNative.CloudEvents
|
|||
/// </summary>
|
||||
public string? Type
|
||||
{
|
||||
get => (string?)this[SpecVersion.TypeAttribute];
|
||||
get => (string?) this[SpecVersion.TypeAttribute];
|
||||
set => this[SpecVersion.TypeAttribute] = value;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ namespace CloudNative.CloudEvents
|
|||
throw new ArgumentException($"Value of type {value.GetType()} is incompatible with expected type {ClrType}", nameof(value));
|
||||
}
|
||||
|
||||
ValidateImpl((T)Validation.CheckNotNull(value, nameof(value)));
|
||||
ValidateImpl((T) Validation.CheckNotNull(value, nameof(value)));
|
||||
}
|
||||
|
||||
protected abstract T ParseImpl(string value);
|
||||
|
@ -168,12 +168,12 @@ namespace CloudNative.CloudEvents
|
|||
// Directly from the spec
|
||||
if (c <= 0x1f || (c >= 0x7f && c <= 0x9f))
|
||||
{
|
||||
throw new ArgumentException($"Control character U+{(ushort)c:x4} is not permitted in string attributes");
|
||||
throw new ArgumentException($"Control character U+{(ushort) c:x4} is not permitted in string attributes");
|
||||
}
|
||||
// First two ranges in http://www.unicode.org/faq/private_use.html#noncharacters
|
||||
if (c >= 0xfffe || (c >= 0xfdd0 && c <= 0xfdef))
|
||||
{
|
||||
throw new ArgumentException($"Noncharacter U+{(ushort)c:x4} is not permitted in string attributes");
|
||||
throw new ArgumentException($"Noncharacter U+{(ushort) c:x4} is not permitted in string attributes");
|
||||
}
|
||||
|
||||
// Handle surrogate pairs, based on this character and whether the last character was a high surrogate.
|
||||
|
@ -185,7 +185,7 @@ namespace CloudNative.CloudEvents
|
|||
{
|
||||
if (lastCharWasHighSurrogate)
|
||||
{
|
||||
throw new ArgumentException($"High surrogate character U+{(ushort)value[i - 1]:x4} must be followed by a low surrogate character");
|
||||
throw new ArgumentException($"High surrogate character U+{(ushort) value[i - 1]:x4} must be followed by a low surrogate character");
|
||||
}
|
||||
lastCharWasHighSurrogate = true;
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ namespace CloudNative.CloudEvents
|
|||
{
|
||||
if (!lastCharWasHighSurrogate)
|
||||
{
|
||||
throw new ArgumentException($"Low surrogate character U+{(ushort)c:x4} must be preceded by a high surrogate character");
|
||||
throw new ArgumentException($"Low surrogate character U+{(ushort) c:x4} must be preceded by a high surrogate character");
|
||||
}
|
||||
// Convert the surrogate pair to validate it's not a non-character.
|
||||
// This is the third rule in http://www.unicode.org/faq/private_use.html#noncharacters
|
||||
|
@ -208,12 +208,12 @@ namespace CloudNative.CloudEvents
|
|||
}
|
||||
else if (lastCharWasHighSurrogate)
|
||||
{
|
||||
throw new ArgumentException($"High surrogate character U+{(ushort)value[i - 1]:x4} must be followed by a low surrogate character");
|
||||
throw new ArgumentException($"High surrogate character U+{(ushort) value[i - 1]:x4} must be followed by a low surrogate character");
|
||||
}
|
||||
}
|
||||
if (lastCharWasHighSurrogate)
|
||||
{
|
||||
throw new ArgumentException($"String must not end with high surrogate character U+{(ushort)value[value.Length - 1]:x4}");
|
||||
throw new ArgumentException($"String must not end with high surrogate character U+{(ushort) value[value.Length - 1]:x4}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -185,7 +185,7 @@ namespace CloudNative.CloudEvents
|
|||
/// <param name="cloudEvent">The CloudEvent to get or infer the data content type from. Must not be null.</param>
|
||||
/// <returns>The data content type of the CloudEvent, or null for no data content type.</returns>
|
||||
public virtual string? GetOrInferDataContentType(CloudEvent cloudEvent)
|
||||
{
|
||||
{
|
||||
Validation.CheckNotNull(cloudEvent, nameof(cloudEvent));
|
||||
return cloudEvent.DataContentType is string dataContentType ? dataContentType
|
||||
: cloudEvent.Data is not object data ? null
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -73,6 +73,6 @@ namespace CloudNative.CloudEvents
|
|||
}
|
||||
|
||||
return formatter;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,7 @@ namespace CloudNative.CloudEvents
|
|||
/// or null if no such version is known.
|
||||
/// </summary>
|
||||
/// <param name="versionId">The version ID to check. May be null, in which case the result will be null.</param>
|
||||
[return:NotNullIfNotNull(nameof(VersionId))]
|
||||
[return: NotNullIfNotNull(nameof(VersionId))]
|
||||
public static CloudEventsSpecVersion? FromVersionId(string? versionId) =>
|
||||
allVersions.FirstOrDefault(version => version.VersionId == versionId);
|
||||
|
||||
|
@ -159,7 +159,7 @@ namespace CloudNative.CloudEvents
|
|||
|
||||
private static void NonEmptyString(object value)
|
||||
{
|
||||
string text = (string)value;
|
||||
string text = (string) value;
|
||||
if (text.Length == 0)
|
||||
{
|
||||
throw new ArgumentException("Value must be non-empty");
|
||||
|
@ -179,7 +179,7 @@ namespace CloudNative.CloudEvents
|
|||
{
|
||||
try
|
||||
{
|
||||
_ = new ContentType((string)value);
|
||||
_ = new ContentType((string) value);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace CloudNative.CloudEvents.Core
|
|||
// It's safe to use memory.GetBuffer() and memory.Position here, as this is a stream
|
||||
// we've created using the parameterless constructor.
|
||||
var buffer = memory.GetBuffer();
|
||||
return new ReadOnlyMemory<byte>(buffer, 0, (int)memory.Position);
|
||||
return new ReadOnlyMemory<byte>(buffer, 0, (int) memory.Position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace CloudNative.CloudEvents.Extensions
|
|||
|
||||
private static void PositiveInteger(object value)
|
||||
{
|
||||
if ((int)value <= 0)
|
||||
if ((int) value <= 0)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException("Sampled rate must be positive.");
|
||||
}
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace CloudNative.CloudEvents.Extensions
|
|||
/// <param name="cloudEvent">The CloudEvent from which to retrieve the attribute. Must not be null.</param>
|
||||
/// <returns>The <see cref="SequenceTypeAttribute"/> value, as a string, or null if the attribute is not set.</returns>
|
||||
public static string? GetSequenceType(this CloudEvent cloudEvent) =>
|
||||
(string?)Validation.CheckNotNull(cloudEvent, nameof(cloudEvent))[SequenceTypeAttribute];
|
||||
(string?) Validation.CheckNotNull(cloudEvent, nameof(cloudEvent))[SequenceTypeAttribute];
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the <see cref="SequenceAttribute"/> value from the event,
|
||||
|
@ -107,7 +107,7 @@ namespace CloudNative.CloudEvents.Extensions
|
|||
return null;
|
||||
}
|
||||
var type = GetSequenceType(cloudEvent);
|
||||
if (type == null)
|
||||
if (type == null)
|
||||
{
|
||||
return sequence;
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ namespace CloudNative.CloudEvents.Http
|
|||
Validation.CheckNotNull(httpRequestMessage, nameof(httpRequestMessage));
|
||||
return HasCloudEventsBatchContentType(httpRequestMessage.Content);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Indicates whether this <see cref="HttpResponseMessage"/> holds a batch of CloudEvents.
|
||||
/// </summary>
|
||||
|
|
|
@ -223,7 +223,7 @@ namespace CloudNative.CloudEvents.Http
|
|||
this HttpListenerRequest httpListenerRequest,
|
||||
CloudEventFormatter formatter,
|
||||
params CloudEventAttribute[]? extensionAttributes) =>
|
||||
ToCloudEventBatchAsync(httpListenerRequest, formatter, (IEnumerable<CloudEventAttribute>?)extensionAttributes);
|
||||
ToCloudEventBatchAsync(httpListenerRequest, formatter, (IEnumerable<CloudEventAttribute>?) extensionAttributes);
|
||||
|
||||
/// <summary>
|
||||
/// Converts this HTTP request message into a CloudEvent batch.
|
||||
|
@ -263,7 +263,7 @@ namespace CloudNative.CloudEvents.Http
|
|||
CloudEventFormatter formatter,
|
||||
IEnumerable<CloudEventAttribute>? extensionAttributes) =>
|
||||
ToCloudEventBatchInternalAsync(httpListenerRequest, formatter, extensionAttributes, async: false).GetAwaiter().GetResult();
|
||||
|
||||
|
||||
private async static Task<IReadOnlyList<CloudEvent>> ToCloudEventBatchInternalAsync(HttpListenerRequest httpListenerRequest,
|
||||
CloudEventFormatter formatter, IEnumerable<CloudEventAttribute>? extensionAttributes, bool async)
|
||||
{
|
||||
|
|
|
@ -51,7 +51,7 @@ namespace CloudNative.CloudEvents
|
|||
{
|
||||
// TODO: Check this and add a test
|
||||
Validation.CheckNotNull(input, nameof(input));
|
||||
|
||||
|
||||
if (input.Length < MinLength) // "yyyy-MM-ddTHH:mm:ssZ" is the shortest possible value.
|
||||
{
|
||||
result = default;
|
||||
|
|
|
@ -30,7 +30,7 @@ namespace CloudNative.CloudEvents.Amqp.UnitTests
|
|||
{
|
||||
// The AMQPNetLite library is factored such that we don't need to do a wire test here.
|
||||
var cloudEvent = CreateSampleCloudEvent();
|
||||
var message = cloudEvent.ToAmqpMessage(ContentMode.Binary, new JsonEventFormatter());
|
||||
var message = cloudEvent.ToAmqpMessage(ContentMode.Binary, new JsonEventFormatter());
|
||||
Assert.True(message.IsCloudEvent());
|
||||
var encodedAmqpMessage = message.Encode();
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ namespace CloudNative.CloudEvents.AspNetCore.UnitTests
|
|||
var formatter = new JsonEventFormatter();
|
||||
var response = CreateResponse();
|
||||
await cloudEvent.CopyToHttpResponseAsync(response, ContentMode.Binary, formatter);
|
||||
|
||||
|
||||
var content = GetContent(response);
|
||||
Assert.Equal("text/plain", response.ContentType);
|
||||
Assert.Equal("plain text", Encoding.UTF8.GetString(content.Span));
|
||||
|
@ -76,7 +76,7 @@ namespace CloudNative.CloudEvents.AspNetCore.UnitTests
|
|||
var cloudEvent = new CloudEvent().PopulateRequiredAttributes();
|
||||
var formatter = new JsonEventFormatter();
|
||||
var response = CreateResponse();
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => cloudEvent.CopyToHttpResponseAsync(response, (ContentMode)100, formatter));
|
||||
await Assert.ThrowsAsync<ArgumentOutOfRangeException>(() => cloudEvent.CopyToHttpResponseAsync(response, (ContentMode) 100, formatter));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -117,7 +117,7 @@ namespace CloudNative.CloudEvents.AspNetCore.UnitTests
|
|||
var parsedBatch = new JsonEventFormatter().DecodeBatchModeMessage(content, new ContentType(response.ContentType), extensionAttributes: null);
|
||||
AssertBatchesEqual(batch, parsedBatch);
|
||||
}
|
||||
|
||||
|
||||
private static HttpResponse CreateResponse() => new DefaultHttpResponse(new DefaultHttpContext()) { Body = new MemoryStream() };
|
||||
private static ReadOnlyMemory<byte> GetContent(HttpResponse response)
|
||||
{
|
||||
|
|
|
@ -61,9 +61,9 @@ namespace CloudNative.CloudEvents.Avro.UnitTests
|
|||
Assert.Equal(MediaTypeNames.Text.Xml, cloudEvent.DataContentType);
|
||||
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
|
||||
|
||||
Assert.Equal("value", (string?)cloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("value", (string?) cloudEvent["comexampleextension1"]);
|
||||
}
|
||||
|
||||
|
||||
[Fact]
|
||||
public void StructuredParseWithExtensionsSuccess()
|
||||
{
|
||||
|
|
|
@ -59,7 +59,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
{
|
||||
var attr = CloudEventsSpecVersion.V1_0.TimeAttribute;
|
||||
Assert.Equal("time", attr.Name);
|
||||
Assert.Equal("time", attr.ToString());
|
||||
Assert.Equal("time", attr.ToString());
|
||||
Assert.Equal(CloudEventAttributeType.Timestamp, attr.Type);
|
||||
Assert.False(attr.IsRequired);
|
||||
Assert.False(attr.IsExtension);
|
||||
|
@ -152,7 +152,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
|
||||
private void ValidateNonNegative(object value)
|
||||
{
|
||||
if ((int)value < 0)
|
||||
if ((int) value < 0)
|
||||
{
|
||||
throw new Exception("Custom validation message");
|
||||
}
|
||||
|
|
|
@ -74,9 +74,9 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
[Theory]
|
||||
[InlineData("")]
|
||||
// Examples from https://en.wikipedia.org/wiki/Base64
|
||||
[InlineData("TWFu", (byte) 77, (byte)97, (byte) 110)]
|
||||
[InlineData("TWE=", (byte)77, (byte)97)]
|
||||
[InlineData("TQ==", (byte)77)]
|
||||
[InlineData("TWFu", (byte) 77, (byte) 97, (byte) 110)]
|
||||
[InlineData("TWE=", (byte) 77, (byte) 97)]
|
||||
[InlineData("TQ==", (byte) 77)]
|
||||
public void ParseAndFormat_Valid(string text, params byte[] bytes)
|
||||
{
|
||||
var parsedBytes = CloudEventAttributeType.Binary.Parse(text);
|
||||
|
@ -199,7 +199,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
[InlineData(0x20, 0xd800)] // High surrogate at end of string
|
||||
public void InvalidSurrogates(int first, int second)
|
||||
{
|
||||
string text = $"{(char)first}{(char)second}";
|
||||
string text = $"{(char) first}{(char) second}";
|
||||
Assert.Throws<ArgumentException>(() => CloudEventAttributeType.String.Validate(text));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
Assert.Equal(MediaTypeNames.Text.Xml, cloudEvent.DataContentType);
|
||||
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
|
||||
|
||||
Assert.Equal("value", (string?)cloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("value", (string?) cloudEvent["comexampleextension1"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -47,7 +47,7 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
|
||||
var cloudEvent = new CloudEvent(new[] { extension })
|
||||
{
|
||||
Type = "com.github.pull.create",
|
||||
Type = "com.github.pull.create",
|
||||
Id = "A234-1234-1234",
|
||||
Time = sampleTimestamp,
|
||||
[extension] = 10
|
||||
|
@ -263,10 +263,10 @@ namespace CloudNative.CloudEvents.UnitTests
|
|||
public void Indexer_NullKey_Throws()
|
||||
{
|
||||
var cloudEvent = new CloudEvent();
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(string)null!]);
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(CloudEventAttribute)null!]);
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(string)null!] = "text");
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(CloudEventAttribute)null!] = "text");
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(string) null!]);
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(CloudEventAttribute) null!]);
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(string) null!] = "text");
|
||||
Assert.Throws<ArgumentNullException>(() => cloudEvent[(CloudEventAttribute) null!] = "text");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -216,7 +216,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
};
|
||||
|
||||
await cloudEvent.CopyToHttpListenerResponseAsync(context.Response, ContentMode.Binary, new JsonEventFormatter());
|
||||
context.Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.OK;
|
||||
});
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
|
@ -283,7 +283,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
|
||||
// The non-ASCII attribute value should have been correctly URL-decoded.
|
||||
Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.NoContent;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
|
@ -314,7 +314,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
};
|
||||
|
||||
await cloudEvent.CopyToHttpListenerResponseAsync(context.Response, ContentMode.Structured, new JsonEventFormatter());
|
||||
context.Response.StatusCode = (int)HttpStatusCode.OK;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.OK;
|
||||
});
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
|
@ -384,7 +384,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
|
||||
Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.NoContent;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
|
|
|
@ -305,7 +305,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
{
|
||||
executed = true;
|
||||
result = await handler(context);
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.NoContent;
|
||||
};
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
|
|
|
@ -103,7 +103,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
try
|
||||
{
|
||||
listener.Start();
|
||||
return ((IPEndPoint)listener.LocalEndpoint).Port;
|
||||
return ((IPEndPoint) listener.LocalEndpoint).Port;
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -56,11 +56,11 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
|
||||
Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.NoContent;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
var result = (HttpWebResponse)await httpWebRequest.GetResponseAsync();
|
||||
var result = (HttpWebResponse) await httpWebRequest.GetResponseAsync();
|
||||
var content = new StreamReader(result.GetResponseStream()).ReadToEnd();
|
||||
Assert.True(result.StatusCode == HttpStatusCode.NoContent, content);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ namespace CloudNative.CloudEvents.Http.UnitTests
|
|||
|
||||
Assert.Equal("value", receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("æøå", receivedCloudEvent["utf8examplevalue"]);
|
||||
context.Response.StatusCode = (int)HttpStatusCode.NoContent;
|
||||
context.Response.StatusCode = (int) HttpStatusCode.NoContent;
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
Data = "<much wow=\"xml\"/>",
|
||||
["comexampleextension1"] = "value"
|
||||
};
|
||||
|
||||
|
||||
var message = cloudEvent.ToKafkaMessage(ContentMode.Structured, new JsonEventFormatter());
|
||||
|
||||
Assert.True(message.IsCloudEvent());
|
||||
|
@ -79,7 +79,7 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
|
||||
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
|
||||
|
||||
Assert.Equal("value", (string?)receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("value", (string?) receivedCloudEvent["comexampleextension1"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -126,7 +126,7 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
|
||||
Assert.Equal("hello much wow", (string?) receivedCloudEvent[Partitioning.PartitionKeyAttribute]);
|
||||
|
||||
Assert.Equal("value", (string?)receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("value", (string?) receivedCloudEvent["comexampleextension1"]);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -176,8 +176,8 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
AssertTimestampsEqual("2018-04-05T17:31:00Z", receivedCloudEvent.Time!.Value);
|
||||
Assert.Equal(contentType, receivedCloudEvent.DataContentType);
|
||||
Assert.Equal(expectedDecodedResult, receivedCloudEvent.Data);
|
||||
Assert.Equal("hello much wow", (string?)receivedCloudEvent[Partitioning.PartitionKeyAttribute]);
|
||||
Assert.Equal("value", (string?)receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("hello much wow", (string?) receivedCloudEvent[Partitioning.PartitionKeyAttribute]);
|
||||
Assert.Equal("value", (string?) receivedCloudEvent["comexampleextension1"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -207,12 +207,12 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
var surrogate = serializer.Deserialize<List<Header>>(reader)!;
|
||||
var headers = new Headers();
|
||||
|
||||
foreach(var header in surrogate)
|
||||
foreach (var header in surrogate)
|
||||
{
|
||||
headers.Add(header.Key, header.GetValueBytes());
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ namespace CloudNative.CloudEvents.Kafka.UnitTests
|
|||
|
||||
public override void WriteJson(JsonWriter writer, object? value, JsonSerializer serializer)
|
||||
{
|
||||
var header = (IHeader)value!;
|
||||
var header = (IHeader) value!;
|
||||
var container = new HeaderContainer { Key = header.Key, Value = header.GetValueBytes() };
|
||||
serializer.Serialize(writer, container);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ namespace CloudNative.CloudEvents.Mqtt.UnitTests
|
|||
Assert.Equal(MediaTypeNames.Text.Xml, receivedCloudEvent.DataContentType);
|
||||
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
|
||||
|
||||
Assert.Equal("value", (string?)receivedCloudEvent["comexampleextension1"]);
|
||||
Assert.Equal("value", (string?) receivedCloudEvent["comexampleextension1"]);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public class ConformanceTest
|
|||
// We don't have a convenience method for batches, so serialize the array back to JSON.
|
||||
var json = test.Batch.ToString();
|
||||
var body = Encoding.UTF8.GetBytes(json);
|
||||
IReadOnlyList<CloudEvent> actual = new JsonEventFormatter().DecodeBatchModeMessage(body, contentType: null, extensions);
|
||||
IReadOnlyList<CloudEvent> actual = new JsonEventFormatter().DecodeBatchModeMessage(body, contentType: null, extensions);
|
||||
TestHelpers.AssertBatchesEqual(expected, actual, TestHelpers.InstantOnlyTimestampComparer);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public class ConformanceTestFile
|
|||
test.TestType ??= testFile.TestType;
|
||||
}
|
||||
return testFile;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class JsonConformanceTest
|
||||
|
@ -43,7 +43,7 @@ public class JsonConformanceTest
|
|||
}
|
||||
|
||||
public enum ConformanceTestType
|
||||
{
|
||||
{
|
||||
ValidSingleEvent,
|
||||
ValidBatch,
|
||||
InvalidSingleEvent,
|
||||
|
|
|
@ -26,7 +26,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var formatter = CreateFormatter<AttributedModel>();
|
||||
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, null, null);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var formatter = CreateFormatter<AttributedModel>();
|
||||
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, new ContentType("text/plain"), null);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var cloudEvent = new CloudEvent();
|
||||
formatter.DecodeBinaryModeEventData(bytes, cloudEvent);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
@ -98,7 +98,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var body = formatter.EncodeStructuredModeMessage(cloudEvent, out _);
|
||||
var jobject = JsonEventFormatterTest.ParseJson(body);
|
||||
Assert.False(jobject.ContainsKey("data_base64"));
|
||||
var data = (JObject)jobject["data"]!;
|
||||
var data = (JObject) jobject["data"]!;
|
||||
|
||||
new JTokenAsserter
|
||||
{
|
||||
|
|
|
@ -1176,7 +1176,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
string text = BinaryDataUtilities.GetString(data, Encoding.UTF8);
|
||||
var serializer = new JsonSerializer
|
||||
{
|
||||
DateParseHandling = DateParseHandling.None
|
||||
DateParseHandling = DateParseHandling.None
|
||||
};
|
||||
return serializer.Deserialize<T>(new JsonTextReader(new StringReader(text)))!;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Copyright 2021 Cloud Native Foundation.
|
||||
// Licensed under the Apache 2.0 license.
|
||||
// See LICENSE file in the project root for full license information.
|
||||
|
||||
|
@ -158,7 +158,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
{
|
||||
if (cloudEvent.DataContentType == TextBinaryContentType && dataBase64Token.Type == JTokenType.String)
|
||||
{
|
||||
cloudEvent.Data = Encoding.UTF8.GetString(Convert.FromBase64String((string)dataBase64Token!));
|
||||
cloudEvent.Data = Encoding.UTF8.GetString(Convert.FromBase64String((string) dataBase64Token!));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -170,7 +170,7 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
{
|
||||
if (cloudEvent.DataContentType == GuidContentType && dataToken.Type == JTokenType.String)
|
||||
{
|
||||
string text = (string)dataToken!;
|
||||
string text = (string) dataToken!;
|
||||
if (!text.StartsWith(GuidPrefix))
|
||||
{
|
||||
throw new ArgumentException("Invalid GUID text data");
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var event1 = formatter.DecodeStructuredModeMessage(CreateJsonStream(), null, null);
|
||||
var event2 = formatter.DecodeStructuredModeMessage(CreateJsonStream(), null, null);
|
||||
|
||||
JObject data1 = (JObject)event1.Data!;
|
||||
JObject data2 = (JObject)event2.Data!;
|
||||
JObject data1 = (JObject) event1.Data!;
|
||||
JObject data2 = (JObject) event2.Data!;
|
||||
|
||||
var property1 = data1.Properties().Single();
|
||||
var property2 = data2.Properties().Single();
|
||||
|
@ -49,8 +49,8 @@ namespace CloudNative.CloudEvents.NewtonsoftJson.UnitTests
|
|||
var event1 = formatter.DecodeStructuredModeMessage(CreateJsonStream(), null, null);
|
||||
var event2 = formatter.DecodeStructuredModeMessage(CreateJsonStream(), null, null);
|
||||
|
||||
JObject data1 = (JObject)event1.Data!;
|
||||
JObject data2 = (JObject)event2.Data!;
|
||||
JObject data1 = (JObject) event1.Data!;
|
||||
JObject data2 = (JObject) event2.Data!;
|
||||
|
||||
var property1 = data1.Properties().Single();
|
||||
var property2 = data2.Properties().Single();
|
||||
|
|
|
@ -56,7 +56,7 @@ public class JsonConformanceTest
|
|||
}
|
||||
|
||||
public enum ConformanceTestType
|
||||
{
|
||||
{
|
||||
ValidSingleEvent,
|
||||
ValidBatch,
|
||||
InvalidSingleEvent,
|
||||
|
|
|
@ -27,7 +27,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
var formatter = CreateFormatter<AttributedModel>();
|
||||
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, null, null);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
var formatter = CreateFormatter<AttributedModel>();
|
||||
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, new ContentType("text/plain"), null);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
var cloudEvent = new CloudEvent();
|
||||
formatter.DecodeBinaryModeEventData(bytes, cloudEvent);
|
||||
|
||||
var model = (AttributedModel)cloudEvent.Data!;
|
||||
var model = (AttributedModel) cloudEvent.Data!;
|
||||
Assert.Equal("test", model.AttributedProperty);
|
||||
}
|
||||
|
||||
|
|
|
@ -435,7 +435,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
var array = BinaryDataUtilities.AsArray(data);
|
||||
Assert.Equal(array, SampleBinaryData);
|
||||
}
|
||||
|
||||
|
||||
// Note: batch mode testing is restricted to the batch aspects; we assume that the
|
||||
// per-CloudEvent implementation is shared with structured mode, so we rely on
|
||||
// structured mode testing for things like custom serialization.
|
||||
|
@ -469,7 +469,7 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
Assert.Equal("application/cloudevents-batch+json; charset=utf-8", contentType.ToString());
|
||||
var array = ParseJson(bytes).EnumerateArray().ToList();
|
||||
Assert.Equal(2, array.Count);
|
||||
|
||||
|
||||
var asserter1 = new JsonElementAsserter
|
||||
{
|
||||
{ "specversion", JsonValueKind.String, "1.0" },
|
||||
|
@ -672,10 +672,10 @@ namespace CloudNative.CloudEvents.SystemTextJson.UnitTests
|
|||
var formatter = new JsonEventFormatter();
|
||||
var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, s_jsonCloudEventContentType, AllTypesExtensions);
|
||||
Assert.Equal(SampleBinaryData, cloudEvent["binary"]);
|
||||
Assert.True((bool)cloudEvent["boolean"]!);
|
||||
Assert.True((bool) cloudEvent["boolean"]!);
|
||||
Assert.Equal(10, cloudEvent["integer"]);
|
||||
Assert.Equal("text", cloudEvent["string"]);
|
||||
AssertTimestampsEqual(SampleTimestamp, (DateTimeOffset)cloudEvent["timestamp"]!);
|
||||
AssertTimestampsEqual(SampleTimestamp, (DateTimeOffset) cloudEvent["timestamp"]!);
|
||||
Assert.Equal(SampleUri, cloudEvent["uri"]);
|
||||
Assert.Equal(SampleUriReference, cloudEvent["urireference"]);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue