Merge pull request #12 from clemensv/master

Update for version 0.3 support
This commit is contained in:
Clemens Vasters 2019-05-20 08:05:10 +02:00 committed by GitHub
commit f2ba906799
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
21 changed files with 294 additions and 119 deletions

28
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,28 @@
{
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/test/CloudNative.CloudEvents.UnitTests/bin/Debug/netcoreapp2.1/CloudNative.CloudEvents.UnitTests.dll",
"args": [],
"cwd": "${workspaceFolder}/test/CloudNative.CloudEvents.UnitTests",
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
"console": "internalConsole",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart"
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
,]
}

15
.vscode/tasks.json vendored Normal file
View File

@ -0,0 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/test/CloudNative.CloudEvents.UnitTests/CloudNative.CloudEvents.UnitTests.csproj"
],
"problemMatcher": "$msCompile"
}
]
}

View File

@ -0,0 +1,2 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=datacontentencoding/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -10,26 +10,28 @@ The `CloudNative.CloudEvents` package provides utility methods and classes for c
## CloudEvent ## CloudEvent
The `CloudEvent` class reflects the event envelope defined by the CNCF CloudEvents specification. The `CloudEvent` class reflects the event envelope defined by the CNCF CloudEvents specification.
It supports both version 0.1 and (yet to be finalized) version 0.2 of the CloudEvents specification, It supports versions 0.1, 0.2, and 0.3 of the CloudEvents specification.
even though the strongly typed API already reflects the 0.2 naming. The strongly typed API already reflects the 0.3 naming with backwards compatible property overrides
for 0.2 that are explicitly marked as obsolete.
The default specification version is 0.2, you can override this by specifying the version explicitly: The default specification version is 0.3, you can override this by specifying the version explicitly:
`new CloudEvent(CloudEventsSpecVersion.V0_1)`. The `SpecVersion` property also allows the `new CloudEvent(CloudEventsSpecVersion.V0_1)`. The `SpecVersion` property also allows the
version to be switched, meaning you can receive a 0.1 event, switch the version number, and forward version to be switched, meaning you can receive a 0.1 event, switch the version number, and forward
it as a 0.2 event. it as a 0.3 event.
| 0.1 | 0.2 | Property name | CLR type | 0.1 | 0.2 | 0.3 | Property name | CLR type
|-----------------------|-----------------------|----------------------------|---------- |-----------------------|-----------------------|----------------------------|----------
| eventID | id | `CloudEvent.Id` | `System.String` | eventID | id | id | `CloudEvent.Id` | `System.String`
| eventType | type | `CloudEvent.Type` | `System.String` | eventType | type | type | `CloudEvent.Type` | `System.String`
| cloudEventsVersion | specversion | `CloudEvent.SpecVersion` | `System.String` | cloudEventsVersion | specversion | specversion | `CloudEvent.SpecVersion` | `System.String`
| eventTime | time | `CloudEvent.Time` | `System.DateTime` | eventTime | time | time | `CloudEvent.Time` | `System.DateTime`
| source | source | `CloudEvent.Source` | `System.Uri` | source | source | source | `CloudEvent.Source` | `System.Uri`
| schemaUrl | schemaurl | `CloudEvent.SchemaUrl` | `System.Uri` | - | - | subject | `CloudEvent.Source` | `System.String`
| source | source | `CloudEvent.Source` | `System.Uri` | schemaUrl | schemaurl | schemaurl | `CloudEvent.SchemaUrl` | `System.Uri`
| contentType | contenttype | `CloudEvent.ContentType` | `System.Net.Mime.ContentType` | contentType | contenttype | datacontenttype | `CloudEvent.ContentType` | `System.Net.Mime.ContentType`
| data | data | `CloudEvent.Data` | `System.Object` | - | - | datacontentencoding | `CloudEvent.DataContentEncoding` | `System.String` |
| data | data | data | `CloudEvent.Data` | `System.Object`
The `CloudEvent.Data` property is `object` typed, and may hold any valid serializable The `CloudEvent.Data` property is `object` typed, and may hold any valid serializable

View File

@ -32,7 +32,7 @@ namespace HttpSend
{ {
var cloudEvent = new CloudEvent(this.Type, new Uri(this.Source)) var cloudEvent = new CloudEvent(this.Type, new Uri(this.Source))
{ {
ContentType = new ContentType(MediaTypeNames.Application.Json), DataContentType = new ContentType(MediaTypeNames.Application.Json),
Data = JsonConvert.SerializeObject("hey there!") Data = JsonConvert.SerializeObject("hey there!")
}; };

View File

@ -68,8 +68,10 @@ namespace CloudNative.CloudEvents.Amqp
? CloudEventsSpecVersion.V0_1 ? CloudEventsSpecVersion.V0_1
: message.ApplicationProperties.Map.ContainsKey(SpecVersionAmqpHeader2) : message.ApplicationProperties.Map.ContainsKey(SpecVersionAmqpHeader2)
? (message.ApplicationProperties.Map[SpecVersionAmqpHeader2] as string == "0.2" ? (message.ApplicationProperties.Map[SpecVersionAmqpHeader2] as string == "0.2"
? CloudEventsSpecVersion.V0_2 ? CloudEventsSpecVersion.V0_2 :
: CloudEventsSpecVersion.Default) (message.ApplicationProperties.Map[SpecVersionAmqpHeader2] as string == "0.3"
? CloudEventsSpecVersion.V0_3
: CloudEventsSpecVersion.Default))
: CloudEventsSpecVersion.Default, extensions); : CloudEventsSpecVersion.Default, extensions);
var attributes = cloudEvent.GetAttributes(); var attributes = cloudEvent.GetAttributes();
foreach (var prop in message.ApplicationProperties.Map) foreach (var prop in message.ApplicationProperties.Map)
@ -96,7 +98,7 @@ namespace CloudNative.CloudEvents.Amqp
} }
} }
cloudEvent.ContentType = message.Properties.ContentType != null cloudEvent.DataContentType = message.Properties.ContentType != null
? new ContentType(message.Properties.ContentType) ? new ContentType(message.Properties.ContentType)
: null; : null;
cloudEvent.Data = message.Body; cloudEvent.Data = message.Body;

View File

@ -47,7 +47,7 @@ namespace CloudNative.CloudEvents.Amqp
this.BodySection = new AmqpValue() { Value = cloudEvent.Data }; this.BodySection = new AmqpValue() { Value = cloudEvent.Data };
} }
this.Properties = new Properties() { ContentType = cloudEvent.ContentType?.MediaType }; this.Properties = new Properties() { ContentType = cloudEvent.DataContentType?.MediaType };
this.ApplicationProperties = new ApplicationProperties(); this.ApplicationProperties = new ApplicationProperties();
MapHeaders(cloudEvent); MapHeaders(cloudEvent);
} }
@ -57,7 +57,7 @@ namespace CloudNative.CloudEvents.Amqp
foreach (var attribute in cloudEvent.GetAttributes()) foreach (var attribute in cloudEvent.GetAttributes())
{ {
if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) && if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) &&
!attribute.Key.Equals(CloudEventAttributes.ContentTypeAttributeName(cloudEvent.SpecVersion))) !attribute.Key.Equals(CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion)))
{ {
if (attribute.Value is Uri) if (attribute.Value is Uri)
{ {

View File

@ -26,7 +26,7 @@ namespace CloudNative.CloudEvents
/// <param name="time">'time' of the CloudEvent</param> /// <param name="time">'time' of the CloudEvent</param>
/// <param name="extensions">Extensions to be added to this CloudEvents</param> /// <param name="extensions">Extensions to be added to this CloudEvents</param>
public CloudEvent(string type, Uri source, string id = null, DateTime? time = null, public CloudEvent(string type, Uri source, string id = null, DateTime? time = null,
params ICloudEventExtension[] extensions) : this(CloudEventsSpecVersion.V0_2, type, source, id, time, extensions) params ICloudEventExtension[] extensions) : this(CloudEventsSpecVersion.Default, type, source, id, time, extensions)
{ {
} }
@ -48,6 +48,22 @@ namespace CloudNative.CloudEvents
Time = time ?? DateTime.UtcNow; Time = time ?? DateTime.UtcNow;
} }
/// <summary>
/// Create a new CloudEvent instance.
/// </summary>
/// <param name="specVersion">CloudEvents specification version</param>
/// <param name="type">'type' of the CloudEvent</param>
/// <param name="source">'source' of the CloudEvent</param>
/// <param name="subject">'subject' of the CloudEvent</param>
/// <param name="id">'id' of the CloudEvent</param>
/// <param name="time">'time' of the CloudEvent</param>
/// <param name="extensions">Extensions to be added to this CloudEvents</param>
public CloudEvent(CloudEventsSpecVersion specVersion, string type, Uri source, string subject, string id = null, DateTime? time = null,
params ICloudEventExtension[] extensions) : this(specVersion, type, source, id, time, extensions)
{
Subject = subject;
}
/// <summary> /// <summary>
/// Create a new CloudEvent instance /// Create a new CloudEvent instance
/// </summary> /// </summary>
@ -68,15 +84,32 @@ namespace CloudNative.CloudEvents
} }
/// <summary> /// <summary>
/// CloudEvent 'contenttype' attribute. Content type of the 'data' attribute value. /// CloudEvent 'datacontenttype' attribute. Content type of the 'data' attribute value.
/// This attribute enables the data attribute to carry any type of content, whereby /// This attribute enables the data attribute to carry any type of content, whereby
/// format and encoding might differ from that of the chosen event format. /// format and encoding might differ from that of the chosen event format.
/// </summary> /// </summary>
/// <see cref="https://github.com/cloudevents/spec/blob/master/spec.md#contenttype"/> /// <see cref="https://github.com/cloudevents/spec/blob/master/spec.md#datacontenttype"/>
public ContentType DataContentType
{
get => attributes[CloudEventAttributes.DataContentTypeAttributeName(attributes.SpecVersion)] as ContentType;
set => attributes[CloudEventAttributes.DataContentTypeAttributeName(attributes.SpecVersion)] = value;
}
/// <summary>
/// CloudEvent 'datacontentencoding' attribute.
/// </summary>
/// <see cref="https://github.com/cloudevents/spec/blob/master/spec.md#datacontentencoding"/>
public string DataContentEncoding
{
get => attributes[CloudEventAttributes.DataContentEncodingAttributeName(attributes.SpecVersion)] as string;
set => attributes[CloudEventAttributes.DataContentEncodingAttributeName(attributes.SpecVersion)] = value;
}
[Obsolete("Cloud events 0.1 and 0.2 name replaced by 'DataContentType1'. Will be removed in an upcoming release.")]
public ContentType ContentType public ContentType ContentType
{ {
get => attributes[CloudEventAttributes.ContentTypeAttributeName(attributes.SpecVersion)] as ContentType; get => DataContentType;
set => attributes[CloudEventAttributes.ContentTypeAttributeName(attributes.SpecVersion)] = value; set => DataContentType = value;
} }
/// <summary> /// <summary>
@ -119,6 +152,16 @@ namespace CloudNative.CloudEvents
set => attributes[CloudEventAttributes.SchemaUrlAttributeName(attributes.SpecVersion)] = value; set => attributes[CloudEventAttributes.SchemaUrlAttributeName(attributes.SpecVersion)] = value;
} }
/// <summary>
/// CloudEvents 'subject' attribute.
/// </summary>
/// <see cref="https://github.com/cloudevents/spec/blob/master/spec.md#subject"/>
public string Subject
{
get => attributes[CloudEventAttributes.SubjectAttributeName(attributes.SpecVersion)] as string;
set => attributes[CloudEventAttributes.SubjectAttributeName(attributes.SpecVersion)] = value;
}
/// <summary> /// <summary>
/// CloudEvents 'source' attribute. This describes the event producer. Often this /// CloudEvents 'source' attribute. This describes the event producer. Often this
/// will include information such as the type of the event source, the /// will include information such as the type of the event source, the

View File

@ -26,7 +26,9 @@ namespace CloudNative.CloudEvents
{ {
this.extensions = extensions; this.extensions = extensions;
this.specVersion = specVersion; this.specVersion = specVersion;
dict[SpecVersionAttributeName(specVersion)] = specVersion == CloudEventsSpecVersion.V0_1 ? "0.1" : "0.2"; dict[SpecVersionAttributeName(specVersion)] =
specVersion == CloudEventsSpecVersion.V0_1 ? "0.1" :
specVersion == CloudEventsSpecVersion.V0_2 ? "0.2" : "0.3";
} }
int ICollection<KeyValuePair<string, object>>.Count => dict.Count; int ICollection<KeyValuePair<string, object>>.Count => dict.Count;
@ -43,9 +45,12 @@ namespace CloudNative.CloudEvents
{ {
object val; object val;
if (dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_1), out val) || if (dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_1), out val) ||
dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_2), out val)) dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_2), out val) ||
dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_3), out val))
{ {
return (val as string) == "0.1" ? CloudEventsSpecVersion.V0_1 : CloudEventsSpecVersion.V0_2; return (val as string) == "0.1" ? CloudEventsSpecVersion.V0_1 :
(val as string) == "0.2" ? CloudEventsSpecVersion.V0_2 :
CloudEventsSpecVersion.V0_3;
} }
return CloudEventsSpecVersion.Default; return CloudEventsSpecVersion.Default;
@ -61,18 +66,28 @@ namespace CloudNative.CloudEvents
return; return;
} }
} }
else if ( dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_2), out val)) else if (dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_2), out val))
{ {
if (value == CloudEventsSpecVersion.V0_2 && (val as string) == "0.2") if (value == CloudEventsSpecVersion.V0_2 && (val as string) == "0.2")
{ {
return; return;
} }
} }
else if (dict.TryGetValue(SpecVersionAttributeName(CloudEventsSpecVersion.V0_3), out val))
{
if (value == CloudEventsSpecVersion.V0_3 && (val as string) == "0.3")
{
return;
}
}
// transform to new version // transform to new version
var copy = new Dictionary<string, object>(dict); var copy = new Dictionary<string, object>(dict);
dict.Clear(); dict.Clear();
this[SpecVersionAttributeName(value)] = value == CloudEventsSpecVersion.V0_1 ? "0.1" : "0.2";
dict[SpecVersionAttributeName(value)] =
value == CloudEventsSpecVersion.V0_1 ? "0.1" :
value == CloudEventsSpecVersion.V0_2 ? "0.2" : "0.3";
foreach (var kv in copy) foreach (var kv in copy)
{ {
if (SpecVersionAttributeName(CloudEventsSpecVersion.V0_2).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase) || if (SpecVersionAttributeName(CloudEventsSpecVersion.V0_2).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase) ||
@ -80,9 +95,13 @@ namespace CloudNative.CloudEvents
{ {
continue; continue;
} }
if (ContentTypeAttributeName(currentSpecVersion).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase)) if (DataContentTypeAttributeName(currentSpecVersion).Equals(kv.Key))
{ {
this[ContentTypeAttributeName(value)] = kv.Value; dict[DataContentTypeAttributeName(value)] = kv.Value;
}
if (DataContentEncodingAttributeName(currentSpecVersion).Equals(kv.Key))
{
dict[DataContentEncodingAttributeName(value)] = kv.Value;
} }
else if (DataAttributeName(currentSpecVersion).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase)) else if (DataAttributeName(currentSpecVersion).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase))
{ {
@ -100,7 +119,11 @@ namespace CloudNative.CloudEvents
{ {
this[SourceAttributeName(value)] = kv.Value; this[SourceAttributeName(value)] = kv.Value;
} }
else if (TimeAttributeName(currentSpecVersion).Equals(kv.Key, StringComparison.InvariantCultureIgnoreCase)) else if (SubjectAttributeName(currentSpecVersion).Equals(kv.Key))
{
dict[SubjectAttributeName(value)] = kv.Value;
}
else if (TimeAttributeName(currentSpecVersion).Equals(kv.Key))
{ {
this[TimeAttributeName(value)] = kv.Value; this[TimeAttributeName(value)] = kv.Value;
} }
@ -133,9 +156,16 @@ namespace CloudNative.CloudEvents
} }
} }
public static string ContentTypeAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default) public static string DataContentTypeAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default)
{ {
return version == CloudEventsSpecVersion.V0_1 ? "contentType" : "contenttype"; return version == CloudEventsSpecVersion.V0_1 ? "contentType" :
version == CloudEventsSpecVersion.V0_2 ? "contenttype" :
"datacontenttype";
}
public static string DataContentEncodingAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default)
{
return "datacontentencoding";
} }
public static string DataAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default) public static string DataAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default)
@ -158,6 +188,11 @@ namespace CloudNative.CloudEvents
return "source"; return "source";
} }
public static string SubjectAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default)
{
return "subject";
}
public static string SpecVersionAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default) public static string SpecVersionAttributeName(CloudEventsSpecVersion version = CloudEventsSpecVersion.Default)
{ {
return version == CloudEventsSpecVersion.V0_1 ? "cloudEventsVersion" : "specversion"; return version == CloudEventsSpecVersion.V0_1 ? "cloudEventsVersion" : "specversion";
@ -297,7 +332,16 @@ namespace CloudNative.CloudEvents
throw new InvalidOperationException(Strings.ErrorSchemaUrlIsNotAUri); throw new InvalidOperationException(Strings.ErrorSchemaUrlIsNotAUri);
} }
else if (key.Equals(SchemaUrlAttributeName(this.SpecVersion), StringComparison.InvariantCultureIgnoreCase)) else if (key.Equals(SubjectAttributeName(this.SpecVersion)))
{
if (value is null || value is string)
{
return true;
}
throw new InvalidOperationException(Strings.ErrorSchemaUrlIsNotAUri);
}
else if (key.Equals(SchemaUrlAttributeName(this.SpecVersion)))
{ {
if (value is null || value is Uri) if (value is null || value is Uri)
{ {
@ -315,7 +359,7 @@ namespace CloudNative.CloudEvents
throw new InvalidOperationException(Strings.ErrorSchemaUrlIsNotAUri); throw new InvalidOperationException(Strings.ErrorSchemaUrlIsNotAUri);
} }
else if (key.Equals(ContentTypeAttributeName(this.SpecVersion), StringComparison.InvariantCultureIgnoreCase)) else if (key.Equals(DataContentTypeAttributeName(this.SpecVersion)))
{ {
if (value is null || value is ContentType) if (value is null || value is ContentType)
{ {
@ -337,7 +381,15 @@ namespace CloudNative.CloudEvents
throw new InvalidOperationException(Strings.ErrorContentTypeIsNotRFC2046); throw new InvalidOperationException(Strings.ErrorContentTypeIsNotRFC2046);
} }
else if (key.Equals(DataAttributeName(this.SpecVersion), StringComparison.InvariantCultureIgnoreCase)) else if (key.Equals(DataContentEncodingAttributeName(this.SpecVersion)))
{
if (value is null || value is string)
{
return true;
}
throw new InvalidOperationException(Strings.ErrorDataContentEncodingIsNotAString);
}
else if (key.Equals(DataAttributeName(this.SpecVersion)))
{ {
return true; return true;
} }

View File

@ -55,7 +55,7 @@ namespace CloudNative.CloudEvents
cloudEvent.Data, cloudEvent.Extensions.Values)); cloudEvent.Data, cloudEvent.Extensions.Values));
} }
Headers.ContentType = new MediaTypeHeaderValue(cloudEvent.ContentType?.MediaType); Headers.ContentType = new MediaTypeHeaderValue(cloudEvent.DataContentType?.MediaType);
MapHeaders(cloudEvent); MapHeaders(cloudEvent);
} }
@ -80,7 +80,7 @@ namespace CloudNative.CloudEvents
foreach (var attribute in cloudEvent.GetAttributes()) foreach (var attribute in cloudEvent.GetAttributes())
{ {
if (!(attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) || if (!(attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) ||
attribute.Key.Equals(CloudEventAttributes.ContentTypeAttributeName(cloudEvent.SpecVersion)))) attribute.Key.Equals(CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion))))
{ {
if (attribute.Value is string) if (attribute.Value is string)
{ {

View File

@ -8,6 +8,7 @@ namespace CloudNative.CloudEvents
{ {
V0_1, V0_1,
V0_2, V0_2,
Default = V0_2 V0_3,
Default = V0_3
} }
} }

View File

@ -45,7 +45,7 @@ namespace CloudNative.CloudEvents
} }
Stream stream = MapDataAttributeToStream(cloudEvent, formatter); Stream stream = MapDataAttributeToStream(cloudEvent, formatter);
httpListenerResponse.ContentType = cloudEvent.ContentType.ToString(); httpListenerResponse.ContentType = cloudEvent.DataContentType.ToString();
MapAttributesToListenerResponse(cloudEvent, httpListenerResponse); MapAttributesToListenerResponse(cloudEvent, httpListenerResponse);
return stream.CopyToAsync(httpListenerResponse.OutputStream); return stream.CopyToAsync(httpListenerResponse.OutputStream);
} }
@ -72,7 +72,7 @@ namespace CloudNative.CloudEvents
} }
Stream stream = MapDataAttributeToStream(cloudEvent, formatter); Stream stream = MapDataAttributeToStream(cloudEvent, formatter);
httpWebRequest.ContentType = cloudEvent.ContentType.ToString(); httpWebRequest.ContentType = cloudEvent.DataContentType.ToString();
MapAttributesToWebRequest(cloudEvent, httpWebRequest); MapAttributesToWebRequest(cloudEvent, httpWebRequest);
await stream.CopyToAsync(httpWebRequest.GetRequestStream()); await stream.CopyToAsync(httpWebRequest.GetRequestStream());
} }
@ -322,8 +322,8 @@ namespace CloudNative.CloudEvents
if (httpListenerRequest.Headers[SpecVersionHttpHeader2] != null) if (httpListenerRequest.Headers[SpecVersionHttpHeader2] != null)
{ {
version = httpListenerRequest.Headers[SpecVersionHttpHeader2] == "0.2" version = httpListenerRequest.Headers[SpecVersionHttpHeader2] == "0.2"
? CloudEventsSpecVersion.V0_2 ? CloudEventsSpecVersion.V0_2 : httpListenerRequest.Headers[SpecVersionHttpHeader2] == "0.3"
: CloudEventsSpecVersion.Default; ? CloudEventsSpecVersion.V0_3 : CloudEventsSpecVersion.Default;
} }
var cloudEvent = new CloudEvent(version, extensions); var cloudEvent = new CloudEvent(version, extensions);
@ -354,7 +354,7 @@ namespace CloudNative.CloudEvents
} }
} }
cloudEvent.ContentType = httpListenerRequest.ContentType != null cloudEvent.DataContentType = httpListenerRequest.ContentType != null
? new ContentType(httpListenerRequest.ContentType) ? new ContentType(httpListenerRequest.ContentType)
: null; : null;
cloudEvent.Data = httpListenerRequest.InputStream; cloudEvent.Data = httpListenerRequest.InputStream;
@ -456,7 +456,7 @@ namespace CloudNative.CloudEvents
foreach (var attribute in cloudEvent.GetAttributes()) foreach (var attribute in cloudEvent.GetAttributes())
{ {
if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) && if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) &&
!attribute.Key.Equals(CloudEventAttributes.ContentTypeAttributeName(cloudEvent.SpecVersion))) !attribute.Key.Equals(CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion)))
{ {
if (attribute.Value is string) if (attribute.Value is string)
{ {
@ -489,7 +489,7 @@ namespace CloudNative.CloudEvents
foreach (var attribute in cloudEvent.GetAttributes()) foreach (var attribute in cloudEvent.GetAttributes())
{ {
if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) && if (!attribute.Key.Equals(CloudEventAttributes.DataAttributeName(cloudEvent.SpecVersion)) &&
!attribute.Key.Equals(CloudEventAttributes.ContentTypeAttributeName(cloudEvent.SpecVersion))) !attribute.Key.Equals(CloudEventAttributes.DataContentTypeAttributeName(cloudEvent.SpecVersion)))
{ {
if (attribute.Value is string) if (attribute.Value is string)
{ {
@ -577,8 +577,8 @@ namespace CloudNative.CloudEvents
if (httpResponseMessage.Headers.Contains(SpecVersionHttpHeader2)) if (httpResponseMessage.Headers.Contains(SpecVersionHttpHeader2))
{ {
version = httpResponseMessage.Headers.GetValues(SpecVersionHttpHeader2).First() == "0.2" version = httpResponseMessage.Headers.GetValues(SpecVersionHttpHeader2).First() == "0.2"
? CloudEventsSpecVersion.V0_2 ? CloudEventsSpecVersion.V0_2 : httpResponseMessage.Headers.GetValues(SpecVersionHttpHeader2).First() == "0.3"
: CloudEventsSpecVersion.Default; ? CloudEventsSpecVersion.V0_3 : CloudEventsSpecVersion.Default;
} }
var cloudEvent = new CloudEvent(version, extensions); var cloudEvent = new CloudEvent(version, extensions);
@ -614,7 +614,7 @@ namespace CloudNative.CloudEvents
} }
} }
cloudEvent.ContentType = httpResponseMessage.Content?.Headers.ContentType != null cloudEvent.DataContentType = httpResponseMessage.Content.Headers.ContentType != null
? new ContentType(httpResponseMessage.Content.Headers.ContentType.ToString()) ? new ContentType(httpResponseMessage.Content.Headers.ContentType.ToString())
: null; : null;
cloudEvent.Data = httpResponseMessage.Content?.ReadAsStreamAsync().GetAwaiter().GetResult(); cloudEvent.Data = httpResponseMessage.Content?.ReadAsStreamAsync().GetAwaiter().GetResult();

View File

@ -58,16 +58,19 @@ namespace CloudNative.CloudEvents
specVersion = specVersion =
((string)jObject[CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_2)] == ((string)jObject[CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_2)] ==
"0.2") "0.2")
? CloudEventsSpecVersion.V0_2 ? CloudEventsSpecVersion.V0_2 :
: CloudEventsSpecVersion.Default; ((string)jObject[CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_3)] ==
"0.3")
? CloudEventsSpecVersion.V0_3 : CloudEventsSpecVersion.Default;
} }
var cloudEvent = new CloudEvent(specVersion, extensions); var cloudEvent = new CloudEvent(specVersion, extensions);
var attributes = cloudEvent.GetAttributes(); var attributes = cloudEvent.GetAttributes();
foreach (var keyValuePair in jObject) foreach (var keyValuePair in jObject)
{ {
if (keyValuePair.Key.Equals( if (keyValuePair.Key.Equals(CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_1)) ||
CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_1), StringComparison.InvariantCultureIgnoreCase) || keyValuePair.Key.Equals(CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_2)) ||
keyValuePair.Key.Equals(CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_2), StringComparison.InvariantCultureIgnoreCase)) keyValuePair.Key.Equals(CloudEventAttributes.SpecVersionAttributeName(CloudEventsSpecVersion.V0_3)))
{ {
continue; continue;
} }
@ -142,7 +145,7 @@ namespace CloudNative.CloudEvents
return new Uri(uri); return new Uri(uri);
} }
if (name.Equals(CloudEventAttributes.ContentTypeAttributeName(specVersion))) if (name.Equals(CloudEventAttributes.DataContentTypeAttributeName(specVersion)))
{ {
var s = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), typeof(string)) as string; var s = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(data), typeof(string)) as string;
return new ContentType(s); return new ContentType(s);

View File

@ -19,7 +19,7 @@ namespace CloudNative.CloudEvents {
// class via a tool like ResGen or Visual Studio. // class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen // To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project. // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Strings { internal class Strings {
@ -69,6 +69,15 @@ namespace CloudNative.CloudEvents {
} }
} }
/// <summary>
/// Looks up a localized string similar to The &apos;datacontentencoding&apos; field is not a string.
/// </summary>
internal static string ErrorDataContentEncodingIsNotAString {
get {
return ResourceManager.GetString("ErrorDataContentEncodingIsNotAString", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to The &apos;id&apos; attribute value must be a string. /// Looks up a localized string similar to The &apos;id&apos; attribute value must be a string.
/// </summary> /// </summary>
@ -132,6 +141,15 @@ namespace CloudNative.CloudEvents {
} }
} }
/// <summary>
/// Looks up a localized string similar to The &apos;subject&apos; attribute value must be a string.
/// </summary>
internal static string ErrorSubjectValueIsNotAString {
get {
return ResourceManager.GetString("ErrorSubjectValueIsNotAString", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to The &apos;time&apos; attribute value must be a valid ISO8601 timestamp expression. /// Looks up a localized string similar to The &apos;time&apos; attribute value must be a valid ISO8601 timestamp expression.
/// </summary> /// </summary>

View File

@ -120,6 +120,9 @@
<data name="ErrorContentTypeIsNotRFC2046" xml:space="preserve"> <data name="ErrorContentTypeIsNotRFC2046" xml:space="preserve">
<value>The 'contenttype' attribute value must be a content-type expression compliant with RFC2046</value> <value>The 'contenttype' attribute value must be a content-type expression compliant with RFC2046</value>
</data> </data>
<data name="ErrorDataContentEncodingIsNotAString" xml:space="preserve">
<value>The 'datacontentencoding' field is not a string</value>
</data>
<data name="ErrorIdValueIsNotAString" xml:space="preserve"> <data name="ErrorIdValueIsNotAString" xml:space="preserve">
<value>The 'id' attribute value must be a string</value> <value>The 'id' attribute value must be a string</value>
</data> </data>
@ -141,6 +144,9 @@
<data name="ErrorSpecVersionValueIsNotAString" xml:space="preserve"> <data name="ErrorSpecVersionValueIsNotAString" xml:space="preserve">
<value>The 'specversion' attribute value must be a string</value> <value>The 'specversion' attribute value must be a string</value>
</data> </data>
<data name="ErrorSubjectValueIsNotAString" xml:space="preserve">
<value>The 'subject' attribute value must be a string</value>
</data>
<data name="ErrorTimeValueIsNotATimestamp" xml:space="preserve"> <data name="ErrorTimeValueIsNotATimestamp" xml:space="preserve">
<value>The 'time' attribute value must be a valid ISO8601 timestamp expression</value> <value>The 'time' attribute value must be a valid ISO8601 timestamp expression</value>
</data> </data>

View File

@ -20,12 +20,14 @@ namespace CloudNative.CloudEvents.UnitTests
var jsonEventFormatter = new JsonEventFormatter(); var jsonEventFormatter = new JsonEventFormatter();
var cloudEvent = new CloudEvent("com.github.pull.create", var cloudEvent = new CloudEvent(CloudEventsSpecVersion.V0_3,
new Uri("https://github.com/cloudevents/spec/pull/123")) "com.github.pull.create",
source: new Uri("https://github.com/cloudevents/spec/pull"),
subject: "123")
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -41,13 +43,14 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.True(message1.IsCloudEvent()); Assert.True(message1.IsCloudEvent());
var receivedCloudEvent = message1.ToCloudEvent(); var receivedCloudEvent = message1.ToCloudEvent();
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull"), receivedCloudEvent.Source);
Assert.Equal("123", receivedCloudEvent.Subject);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();
@ -68,7 +71,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -84,13 +87,13 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.True(message1.IsCloudEvent()); Assert.True(message1.IsCloudEvent());
var receivedCloudEvent = message1.ToCloudEvent(); var receivedCloudEvent = message1.ToCloudEvent();
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();

View File

@ -18,7 +18,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -26,13 +26,13 @@ namespace CloudNative.CloudEvents.UnitTests
attrs["comexampleextension1"] = "value"; attrs["comexampleextension1"] = "value";
attrs["comexampleextension2"] = new { othervalue = 5 }; attrs["comexampleextension2"] = new { othervalue = 5 };
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
var attr = cloudEvent.GetAttributes(); var attr = cloudEvent.GetAttributes();
@ -49,7 +49,7 @@ namespace CloudNative.CloudEvents.UnitTests
"A234-1234-1234", "A234-1234-1234",
new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc)) new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc))
{ {
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -57,13 +57,13 @@ namespace CloudNative.CloudEvents.UnitTests
attrs["comexampleextension1"] = "value"; attrs["comexampleextension1"] = "value";
attrs["comexampleextension2"] = new { othervalue = 5 }; attrs["comexampleextension2"] = new { othervalue = 5 };
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
var attr = cloudEvent.GetAttributes(); var attr = cloudEvent.GetAttributes();
@ -80,7 +80,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -94,7 +94,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
var attr = cloudEvent.GetAttributes(); var attr = cloudEvent.GetAttributes();
@ -110,7 +110,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -126,7 +126,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
var attr = cloudEvent.GetAttributes(); var attr = cloudEvent.GetAttributes();
@ -156,17 +156,17 @@ namespace CloudNative.CloudEvents.UnitTests
} }
}) })
{ {
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
Assert.Equal("value", cloudEvent.Extension<ComExampleExtension1Extension>().ComExampleExtension1); Assert.Equal("value", cloudEvent.Extension<ComExampleExtension1Extension>().ComExampleExtension1);

View File

@ -14,39 +14,39 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
const string jsonDistTrace = const string jsonDistTrace =
"{\n" + "{\n" +
" \"specversion\" : \"0.2\",\n" + " \"specversion\" : \"0.3\",\n" +
" \"type\" : \"com.github.pull.create\",\n" + " \"type\" : \"com.github.pull.create\",\n" +
" \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" + " \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" +
" \"id\" : \"A234-1234-1234\",\n" + " \"id\" : \"A234-1234-1234\",\n" +
" \"time\" : \"2018-04-05T17:31:00Z\",\n" + " \"time\" : \"2018-04-05T17:31:00Z\",\n" +
" \"traceparent\" : \"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01\",\n" + " \"traceparent\" : \"00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01\",\n" +
" \"tracestate\" : \"rojo=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01,congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4=\",\n" + " \"tracestate\" : \"rojo=00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01,congo=lZWRzIHRoNhcm5hbCBwbGVhc3VyZS4=\",\n" +
" \"contenttype\" : \"text/plain\",\n" + " \"datacontenttype\" : \"text/plain\",\n" +
" \"data\" : \"test\"\n" + " \"data\" : \"test\"\n" +
"}"; "}";
const string jsonSequence = const string jsonSequence =
"{\n" + "{\n" +
" \"specversion\" : \"0.2\",\n" + " \"specversion\" : \"0.3\",\n" +
" \"type\" : \"com.github.pull.create\",\n" + " \"type\" : \"com.github.pull.create\",\n" +
" \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" + " \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" +
" \"id\" : \"A234-1234-1234\",\n" + " \"id\" : \"A234-1234-1234\",\n" +
" \"time\" : \"2018-04-05T17:31:00Z\",\n" + " \"time\" : \"2018-04-05T17:31:00Z\",\n" +
" \"sequencetype\" : \"Integer\",\n" + " \"sequencetype\" : \"Integer\",\n" +
" \"sequence\" : \"25\",\n" + " \"sequence\" : \"25\",\n" +
" \"contenttype\" : \"text/plain\",\n" + " \"datacontenttype\" : \"text/plain\",\n" +
" \"data\" : \"test\"\n" + " \"data\" : \"test\"\n" +
"}"; "}";
const string jsonSampledRate = const string jsonSampledRate =
"{\n" + "{\n" +
" \"specversion\" : \"0.2\",\n" + " \"specversion\" : \"0.3\",\n" +
" \"type\" : \"com.github.pull.create\",\n" + " \"type\" : \"com.github.pull.create\",\n" +
" \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" + " \"source\" : \"https://github.com/cloudevents/spec/pull/123\",\n" +
" \"id\" : \"A234-1234-1234\",\n" + " \"id\" : \"A234-1234-1234\",\n" +
" \"time\" : \"2018-04-05T17:31:00Z\",\n" + " \"time\" : \"2018-04-05T17:31:00Z\",\n" +
" \"sampledrate\" : \"1\",\n" + " \"sampledrate\" : \"1\",\n" +
" \"contenttype\" : \"text/plain\",\n" + " \"datacontenttype\" : \"text/plain\",\n" +
" \"data\" : \"test\"\n" + " \"data\" : \"test\"\n" +
"}"; "}";
@ -55,7 +55,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var jsonFormatter = new JsonEventFormatter(); var jsonFormatter = new JsonEventFormatter();
var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonDistTrace), new DistributedTracingExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonDistTrace), new DistributedTracingExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -74,7 +74,7 @@ namespace CloudNative.CloudEvents.UnitTests
var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType); var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType);
var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new DistributedTracingExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new DistributedTracingExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -90,7 +90,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var jsonFormatter = new JsonEventFormatter(); var jsonFormatter = new JsonEventFormatter();
var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSequence), new SequenceExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSequence), new SequenceExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -109,7 +109,7 @@ namespace CloudNative.CloudEvents.UnitTests
var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType); var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType);
var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new SequenceExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new SequenceExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -125,7 +125,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var jsonFormatter = new JsonEventFormatter(); var jsonFormatter = new JsonEventFormatter();
var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSequence), new IntegerSequenceExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSequence), new IntegerSequenceExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -143,7 +143,7 @@ namespace CloudNative.CloudEvents.UnitTests
var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType); var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType);
var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new IntegerSequenceExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new IntegerSequenceExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -158,7 +158,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var jsonFormatter = new JsonEventFormatter(); var jsonFormatter = new JsonEventFormatter();
var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSampledRate), new SamplingExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(Encoding.UTF8.GetBytes(jsonSampledRate), new SamplingExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
@ -176,7 +176,7 @@ namespace CloudNative.CloudEvents.UnitTests
var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType); var jsonData = jsonFormatter.EncodeStructuredEvent(cloudEvent1, out var contentType);
var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new SamplingExtension()); var cloudEvent = jsonFormatter.DecodeStructuredEvent(jsonData, new SamplingExtension());
Assert.Equal(CloudEventsSpecVersion.V0_2, cloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, cloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", cloudEvent.Type); Assert.Equal("com.github.pull.create", cloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), cloudEvent.Source);
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);

View File

@ -97,7 +97,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -127,13 +127,13 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal(HttpStatusCode.OK, result.StatusCode); Assert.Equal(HttpStatusCode.OK, result.StatusCode);
var receivedCloudEvent = result.ToCloudEvent(); var receivedCloudEvent = result.ToCloudEvent();
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
using (var sr = new StreamReader((Stream)receivedCloudEvent.Data)) using (var sr = new StreamReader((Stream)receivedCloudEvent.Data))
{ {
Assert.Equal("<much wow=\"xml\"/>", sr.ReadToEnd()); Assert.Equal("<much wow=\"xml\"/>", sr.ReadToEnd());
@ -152,7 +152,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -172,13 +172,13 @@ namespace CloudNative.CloudEvents.UnitTests
var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter()); var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
using (var sr = new StreamReader((Stream)receivedCloudEvent.Data)) using (var sr = new StreamReader((Stream)receivedCloudEvent.Data))
{ {
@ -223,7 +223,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -254,13 +254,13 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.True(result.IsCloudEvent()); Assert.True(result.IsCloudEvent());
var receivedCloudEvent = result.ToCloudEvent(); var receivedCloudEvent = result.ToCloudEvent();
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();
@ -276,7 +276,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -294,13 +294,13 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter()); var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();
@ -336,7 +336,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -356,13 +356,13 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter()); var receivedCloudEvent = context.Request.ToCloudEvent(new JsonEventFormatter());
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();

View File

@ -39,7 +39,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal(cloudEvent2.Source, cloudEvent.Source); Assert.Equal(cloudEvent2.Source, cloudEvent.Source);
Assert.Equal(cloudEvent2.Id, cloudEvent.Id); Assert.Equal(cloudEvent2.Id, cloudEvent.Id);
Assert.Equal(cloudEvent2.Time.Value.ToUniversalTime(), cloudEvent.Time.Value.ToUniversalTime()); Assert.Equal(cloudEvent2.Time.Value.ToUniversalTime(), cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(cloudEvent2.ContentType, cloudEvent.ContentType); Assert.Equal(cloudEvent2.DataContentType, cloudEvent.DataContentType);
Assert.Equal(cloudEvent2.Data, cloudEvent.Data); Assert.Equal(cloudEvent2.Data, cloudEvent.Data);
} }
@ -57,7 +57,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal(cloudEvent2.Source, cloudEvent.Source); Assert.Equal(cloudEvent2.Source, cloudEvent.Source);
Assert.Equal(cloudEvent2.Id, cloudEvent.Id); Assert.Equal(cloudEvent2.Id, cloudEvent.Id);
Assert.Equal(cloudEvent2.Time.Value.ToUniversalTime(), cloudEvent.Time.Value.ToUniversalTime()); Assert.Equal(cloudEvent2.Time.Value.ToUniversalTime(), cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(cloudEvent2.ContentType, cloudEvent.ContentType); Assert.Equal(cloudEvent2.DataContentType, cloudEvent.DataContentType);
Assert.Equal(cloudEvent2.Data, cloudEvent.Data); Assert.Equal(cloudEvent2.Data, cloudEvent.Data);
} }
@ -72,7 +72,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
var attr = cloudEvent.GetAttributes(); var attr = cloudEvent.GetAttributes();
@ -92,7 +92,7 @@ namespace CloudNative.CloudEvents.UnitTests
Assert.Equal("A234-1234-1234", cloudEvent.Id); Assert.Equal("A234-1234-1234", cloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
cloudEvent.Time.Value.ToUniversalTime()); cloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), cloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", cloudEvent.Data);
Assert.Equal("value", cloudEvent.Extension<ComExampleExtension1Extension>().ComExampleExtension1); Assert.Equal("value", cloudEvent.Extension<ComExampleExtension1Extension>().ComExampleExtension1);

View File

@ -47,7 +47,7 @@ namespace CloudNative.CloudEvents.UnitTests
{ {
Id = "A234-1234-1234", Id = "A234-1234-1234",
Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc), Time = new DateTime(2018, 4, 5, 17, 31, 0, DateTimeKind.Utc),
ContentType = new ContentType(MediaTypeNames.Text.Xml), DataContentType = new ContentType(MediaTypeNames.Text.Xml),
Data = "<much wow=\"xml\"/>" Data = "<much wow=\"xml\"/>"
}; };
@ -74,13 +74,13 @@ namespace CloudNative.CloudEvents.UnitTests
await client.PublishAsync(new MqttCloudEventMessage(cloudEvent, new JsonEventFormatter()) { Topic = "abc" }); await client.PublishAsync(new MqttCloudEventMessage(cloudEvent, new JsonEventFormatter()) { Topic = "abc" });
var receivedCloudEvent = await tcs.Task; var receivedCloudEvent = await tcs.Task;
Assert.Equal(CloudEventsSpecVersion.V0_2, receivedCloudEvent.SpecVersion); Assert.Equal(CloudEventsSpecVersion.Default, receivedCloudEvent.SpecVersion);
Assert.Equal("com.github.pull.create", receivedCloudEvent.Type); Assert.Equal("com.github.pull.create", receivedCloudEvent.Type);
Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source); Assert.Equal(new Uri("https://github.com/cloudevents/spec/pull/123"), receivedCloudEvent.Source);
Assert.Equal("A234-1234-1234", receivedCloudEvent.Id); Assert.Equal("A234-1234-1234", receivedCloudEvent.Id);
Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(), Assert.Equal(DateTime.Parse("2018-04-05T17:31:00Z").ToUniversalTime(),
receivedCloudEvent.Time.Value.ToUniversalTime()); receivedCloudEvent.Time.Value.ToUniversalTime());
Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.ContentType); Assert.Equal(new ContentType(MediaTypeNames.Text.Xml), receivedCloudEvent.DataContentType);
Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data); Assert.Equal("<much wow=\"xml\"/>", receivedCloudEvent.Data);
var attr = receivedCloudEvent.GetAttributes(); var attr = receivedCloudEvent.GetAttributes();