Ejemplo n.º 1
0
        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>();
        }
Ejemplo n.º 2
0
        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>();
        }
Ejemplo n.º 3
0
        public void TestNoDataFiles(string fileName)
        {
            var json = File.ReadAllText($@"./V02Tests/samples/none/{fileName}");
            var evnt = CloudEventV0_2.Deserialize(json);

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

            newEvnt.Should().BeOfType <CloudEventV0_2>();
            newEvnt.Should().NotBeOfType <JsonCloudEventV0_2>();
            newEvnt.Should().NotBeOfType <BinaryCloudEventV0_2>();
            newEvnt.Should().NotBeOfType <StringCloudEventV0_2>();
        }
Ejemplo n.º 4
0
        public void TestStringFilesV02(string fileName)
        {
            var json = File.ReadAllText($@"./V02Tests/samples/string/{fileName}");
            var evnt = CloudEventV0_2.Deserialize(json);

            var            json2   = JsonConvert.SerializeObject(evnt);
            CloudEventV0_2 newEvnt = JsonConvert.DeserializeObject <CloudEventV0_2>(json2);

            newEvnt.Should().BeOfType <StringCloudEventV0_2>();
        }