public void BinaryEvent_ContainsData_Success(string data) { BinaryCloudEventV0_2 evnt = CloudEventV0_2.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), Encoding.UTF8.GetBytes(data)); evnt.Should().NotBeNull(); evnt.Should().BeOfType <BinaryCloudEventV0_2>(); var jobj = JObject.FromObject(evnt); // Can explicitly deserialize to binary BinaryCloudEventV0_2 evnt2 = jobj.ToObject <BinaryCloudEventV0_2>(); evnt2.Should().NotBeNull(); evnt2.Data.Should().NotBeNull(); // Without a type provided this should deserialize to a binary event var evnt3 = CloudEventV0_2.Deserialize(jobj.ToString()); evnt3.Should().NotBeNull(); evnt3.Should().BeOfType <BinaryCloudEventV0_2>(); CloudEventV0_2 evnt4 = JsonConvert.DeserializeObject <CloudEventV0_2>(jobj.ToString()); evnt4.Should().NotBeNull(); evnt4.Should().BeOfType <BinaryCloudEventV0_2>(); }
public void BinaryEvent_NoData_Success() { BinaryCloudEventV0_2 evnt = CloudEventV0_2.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), (byte[])null); evnt.Should().NotBeNull(); evnt.Should().BeOfType <BinaryCloudEventV0_2>(); var jobj = JObject.FromObject(evnt); // Can explicitly deserialize to binary even without data present BinaryCloudEventV0_2 evnt2 = jobj.ToObject <BinaryCloudEventV0_2>(); evnt2.Should().NotBeNull(); evnt2.Data.Should().BeNull(); // Without a type provided this should deserialize to a generic event var evnt3 = CloudEventV0_2.Deserialize(jobj.ToString()); evnt3.Should().NotBeNull(); evnt3.Should().BeOfType <CloudEventV0_2>(); CloudEventV0_2 evnt4 = JsonConvert.DeserializeObject <CloudEventV0_2>(jobj.ToString()); evnt4.Should().NotBeNull(); evnt4.Should().BeOfType <CloudEventV0_2>(); }
public void BinaryEvent_LargeData_Success(string fileName, string contentType) { var data = File.ReadAllBytes($@"./V02Tests/samples/binary/{fileName}"); BinaryCloudEventV0_2 evnt = CloudEventV0_2.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), data, contentType, null); evnt.Should().NotBeNull(); evnt.Should().BeOfType <BinaryCloudEventV0_2>(); evnt.ContentType.Should().Be(contentType); evnt.Data.Length.Should().Be(data.Length); var json = JsonConvert.SerializeObject(evnt, Formatting.Indented); }