Пример #1
0
        public void BinaryEvent_ContainsData_Success(string data)
        {
            BinaryCloudEvent evnt = CloudEvent.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), Encoding.UTF8.GetBytes(data));

            evnt.Should().NotBeNull();
            evnt.Should().BeOfType <BinaryCloudEvent>();

            var jobj = JObject.FromObject(evnt);

            // Can explicitly deserialize to binary
            BinaryCloudEvent evnt2 = jobj.ToObject <BinaryCloudEvent>();

            evnt2.Should().NotBeNull();
            evnt2.Data.Should().NotBeNull();

            // Without a type provided this should deserialize to a binary event
            var evnt3 = CloudEvent.Deserialize(jobj.ToString());

            evnt3.Should().NotBeNull();
            evnt3.Should().BeOfType <BinaryCloudEvent>();

            CloudEvent evnt4 = JsonConvert.DeserializeObject <CloudEvent>(jobj.ToString());

            evnt4.Should().NotBeNull();
            evnt4.Should().BeOfType <BinaryCloudEvent>();
        }
Пример #2
0
        public void BinaryEvent_NoData_Success()
        {
            BinaryCloudEvent evnt = CloudEvent.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), (byte[])null);

            evnt.Should().NotBeNull();
            evnt.Should().BeOfType <BinaryCloudEvent>();

            CloudEvent newEvnt = JsonConvert.DeserializeObject <CloudEvent>(JsonConvert.SerializeObject(evnt));

            newEvnt.Should().NotBeNull();
            newEvnt.Should().BeOfType <CloudEvent>();

            var jobj = JObject.FromObject(newEvnt);

            // Can explicitly deserialize to binary even without data present
            BinaryCloudEvent evnt2 = jobj.ToObject <BinaryCloudEvent>();

            evnt2.Should().NotBeNull();
            evnt2.Data.Should().BeNull();

            // Without a type provided this should deserialize to a generic event
            var evnt3 = CloudEvent.Deserialize(jobj.ToString());

            evnt3.Should().NotBeNull();
            evnt3.Should().BeOfType <CloudEvent>();
        }
Пример #3
0
        public void BinaryEvent_LargeData_Success(string fileName, string dataContentType)
        {
            var data = File.ReadAllBytes($@"./V10Tests/samples/binary/{fileName}");
            BinaryCloudEvent evnt = CloudEvent.CreateCloudEvent("test", new Uri("/", UriKind.RelativeOrAbsolute), data, dataContentType, null);

            evnt.Should().NotBeNull();
            evnt.Should().BeOfType <BinaryCloudEvent>();
            evnt.DataContentType.Should().Be(dataContentType);

            evnt.Data.Length.Should().Be(data.Length);

            var json = JsonConvert.SerializeObject(evnt, Formatting.Indented);
        }