public void Parse_ValidTimestamp_ParsesDateTimeOffset(SampleTimestamp testCase) { DateTimeOffset actual; Assert.True(MatchExtensions.TryParseTimestamp(testCase.RawTimestamp, out actual)); Assert.Equal(testCase.ExpectedDateTimeOffset, actual); }
public void ConvertFromProto_V1Attributes() { var proto = new V1.CloudEvent { SpecVersion = "1.0", Type = "test-type", Id = "test-id", TextData = "text", Source = "//event-source", Attributes = { { "datacontenttype", StringAttribute("text/plain") }, { "dataschema", UriAttribute("https://data-schema") }, { "subject", StringAttribute("event-subject") }, { "time", TimestampAttribute(SampleTimestamp) } } }; var cloudEvent = new ProtobufEventFormatter().ConvertFromProto(proto, null); Assert.Equal(CloudEventsSpecVersion.V1_0, cloudEvent.SpecVersion); Assert.Equal("test-type", cloudEvent.Type); Assert.Equal("test-id", cloudEvent.Id); Assert.Equal("text/plain", cloudEvent.DataContentType); Assert.Equal(new Uri("https://data-schema"), cloudEvent.DataSchema); Assert.Equal("event-subject", cloudEvent.Subject); Assert.Equal(new Uri("//event-source", UriKind.RelativeOrAbsolute), cloudEvent.Source); // The protobuf timestamp loses the offset information, but is still the correct instant. AssertTimestampsEqual(SampleTimestamp.ToUniversalTime(), cloudEvent.Time); }
public void ConvertFromProto_AllAttributeTypes() { var proto = CreateMinimalCloudEventProto(); proto.Attributes.Add("binary", BinaryAttribute(SampleBinaryData)); proto.Attributes.Add("boolean", BooleanAttribute(true)); proto.Attributes.Add("integer", IntegerAttribute(10)); proto.Attributes.Add("string", StringAttribute("text")); proto.Attributes.Add("timestamp", TimestampAttribute(SampleTimestamp)); proto.Attributes.Add("uri", UriAttribute(SampleUriText)); proto.Attributes.Add("urireference", UriRefAttribute(SampleUriReferenceText)); var cloudEvent = new ProtobufEventFormatter().ConvertFromProto(proto, null); Assert.Equal(SampleBinaryData, cloudEvent["binary"]); Assert.True((bool)cloudEvent["boolean"] !); Assert.Equal(10, cloudEvent["integer"]); Assert.Equal("text", cloudEvent["string"]); // The protobuf timestamp loses the offset information, but is still the correct instant. AssertTimestampsEqual(SampleTimestamp.ToUniversalTime(), (DateTimeOffset)cloudEvent["timestamp"] !); Assert.Equal(SampleUri, cloudEvent["uri"]); Assert.Equal(SampleUriReference, cloudEvent["urireference"]); }