public void Given_ClassType_When_Executed_Should_ReturnResult() { var data = "hello world"; var ev = new AnotherFakeEvent(); ev.EventType = "com.example.someevent"; ev.CloudEventsVersion = "0.1"; ev.Source = (new Uri("http://localhost")).ToString(); ev.EventId = Guid.NewGuid().ToString(); ev.Data = data; var mi = typeof(CloudEventContent <string>).GetMethod("IsStructuredCloudEventContentType", BindingFlags.IgnoreCase | BindingFlags.Static | BindingFlags.NonPublic); ev.ContentType = "application/json"; var result = mi.Invoke(null, new[] { ev }); ((bool)result).Should().BeTrue(); ev.ContentType = "application/cloudevents+json"; result = mi.Invoke(null, new[] { ev }); ((bool)result).Should().BeTrue(); ev.ContentType = "text/plain"; result = mi.Invoke(null, new[] { ev }); ((bool)result).Should().BeFalse(); }
public void Given_Parameter_When_Instantiated_Should_ThrowException() { var ce = new AnotherFakeEvent(); ce.ContentType = "text/plain"; Action action = () => new StructuredCloudEventContent <string>(ce); action.Should().Throw <InvalidContentTypeException>(); }
public void Given_Parameter_When_Instantiated_Should_ThrowException() { var data = "hello world"; var ce = new AnotherFakeEvent(); Action action = () => new BinaryCloudEventContent <string>(ce); action.Should().Throw <InvalidOperationException>(); ce.ContentType = "application/json"; ce.Data = data; action = () => new BinaryCloudEventContent <string>(ce); action.Should().Throw <InvalidContentTypeException>(); }
public void Given_CloudEvent_Should_Return_BinaryCloudEventContent() { var contentType = "text/plain"; var data = "hello world"; var ce = new AnotherFakeEvent(); ce.EventType = "com.example.someevent"; ce.CloudEventsVersion = "0.1"; ce.Source = (new Uri("http://localhost")).ToString(); ce.EventId = Guid.NewGuid().ToString(); ce.ContentType = contentType; ce.Data = data; var content = CloudEventContentFactory.Create(ce); content.Should().BeOfType <BinaryCloudEventContent <string> >(); }
public void Given_CloudEvent_When_Instantiated_Should_HaveProperty() { var data = "hello world"; var ev = new AnotherFakeEvent(); ev.EventType = "com.example.someevent"; ev.CloudEventsVersion = "0.1"; ev.Source = (new Uri("http://localhost")).ToString(); ev.EventId = Guid.NewGuid().ToString(); ev.Data = data; var content = new FakeCloudEventContent <string>(ev); var pi = typeof(FakeCloudEventContent <string>).GetProperty("CloudEvent", BindingFlags.IgnoreCase | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetProperty); pi.GetValue(content).Should().NotBeNull(); pi.GetValue(content).Should().Be(ev); }
public async Task Given_Parameter_When_Instantiated_Should_HaveContent() { var contentType = "text/plain"; var data = "hello world"; var ce = new AnotherFakeEvent(); ce.EventType = "com.example.someevent"; ce.Source = (new Uri("http://localhost")).ToString(); ce.EventId = Guid.NewGuid().ToString(); ce.ContentType = contentType; ce.Data = data; var content = new BinaryCloudEventContent <string>(ce); var result = await content.ReadAsStringAsync().ConfigureAwait(false); result.Should().Be(data); }
public void Given_Parameter_When_Instantiated_Should_HaveContentType() { var contentType = "text/plain"; var charset = "utf-8"; var data = "hello world"; var ce = new AnotherFakeEvent(); ce.EventType = "com.example.someevent"; ce.Source = (new Uri("http://localhost")).ToString(); ce.EventId = Guid.NewGuid().ToString(); ce.ContentType = contentType; ce.Data = data; var content = new BinaryCloudEventContent <string>(ce); content.Headers.ContentType.MediaType.Should().Be(contentType); content.Headers.ContentType.CharSet.Should().Be(charset); }
public void Given_CloudEvent_When_Instantiated_Should_HaveExtensionHeaders() { var data = "hello world"; var ev = new AnotherFakeEvent(); ev.EventType = "com.example.someevent"; ev.CloudEventsVersion = "0.1"; ev.Source = (new Uri("http://localhost")).ToString(); ev.EventId = Guid.NewGuid().ToString(); ev.Data = data; ev.Extensions = new Dictionary <string, object>() { { "key1", "value1" } }; var content = new FakeCloudEventContent <string>(ev); content.Headers.Should().Contain(p => p.Key.Equals("CE-X-key1", StringComparison.CurrentCultureIgnoreCase)); }
public void Given_CloudEvent_When_Instantiated_Should_HaveHeaders() { var data = "hello world"; var ev = new AnotherFakeEvent(); ev.EventType = "com.example.someevent"; ev.CloudEventsVersion = "0.1"; ev.Source = (new Uri("http://localhost")).ToString(); ev.EventId = Guid.NewGuid().ToString(); ev.Data = data; var content = new FakeCloudEventContent <string>(ev); content.Headers.Should().Contain(p => p.Key.Equals("CE-EventType", StringComparison.CurrentCultureIgnoreCase)); content.Headers.Should().Contain(p => p.Key.Equals("CE-CloudEventsVersion", StringComparison.CurrentCultureIgnoreCase)); content.Headers.Should().Contain(p => p.Key.Equals("CE-Source", StringComparison.CurrentCultureIgnoreCase)); content.Headers.Should().Contain(p => p.Key.Equals("CE-EventID", StringComparison.CurrentCultureIgnoreCase)); content.Headers.Should().NotContain(p => p.Key.StartsWith("CE-X-", StringComparison.CurrentCultureIgnoreCase)); }