Esempio n. 1
0
        public void TestStringFiles(string fileName)
        {
            var json = File.ReadAllText($@"./V01Tests/samples/string/{fileName}");
            var evnt = CloudEventV0_1.Deserialize(json);

            Assert.IsType <StringCloudEventV0_1>(evnt);
        }
Esempio n. 2
0
        public void TestBinaryFiles(string fileName)
        {
            var json = File.ReadAllText($@".\v01\samples\binary\{fileName}");
            var evnt = CloudEventV0_1.Deserialize(json);

            Assert.IsType <BinaryCloudEventV0_1>(evnt);
        }
Esempio n. 3
0
        public void Test1()
        {
            StringCloudEventV0_1 evnt = CloudEventV0_1.CreateCloudEvent("test", "1.0", new Uri("http://localhost"), "FooBar");
            var json      = JToken.FromObject(evnt);
            var eventTime = json["eventTime"].ToString();

            Assert.Matches(this.rfc399Regex, eventTime);
        }
Esempio n. 4
0
        public void TestNoDataFiles(string fileName)
        {
            var json = File.ReadAllText($@"./V01Tests/samples/none/{fileName}");
            var evnt = CloudEventV0_1.Deserialize(json);

            Assert.IsType <CloudEventV0_1>(evnt);
            Assert.IsNotType <JsonCloudEventV0_1>(evnt);
            Assert.IsNotType <BinaryCloudEventV0_1>(evnt);
            Assert.IsNotType <StringCloudEventV0_1>(evnt);
        }
Esempio n. 5
0
        public static void ValidateCloudEvent(CloudEventV0_1 cloudEvent)
        {
            if (string.IsNullOrWhiteSpace(cloudEvent.EventType))
            {
                throw new Exception("The eventType property is required and cannot be null or empty.");
            }

            if (cloudEvent.EventTypeVersion != null && string.IsNullOrWhiteSpace(cloudEvent.EventType))
            {
                throw new Exception("The eventTypeVersion property must have a value if supplied.");
            }

            if (string.IsNullOrWhiteSpace(cloudEvent.CloudEventsVersion))
            {
                throw new Exception("The cloudEventsVersion property is required and cannot be null or empty.");
            }

            if (cloudEvent.Source == null)
            {
                throw new Exception("The source property is required.");
            }

            if (string.IsNullOrWhiteSpace(cloudEvent.EventId))
            {
                throw new Exception("The eventId property is required and cannot be null or empty.");
            }

            if (cloudEvent.ContentType != null && string.IsNullOrWhiteSpace(cloudEvent.ContentType))
            {
                throw new Exception("The contentType property must have a value if supplied.");
            }

            if (cloudEvent.Extensions != null && cloudEvent.Extensions.HasValues == false)
            {
                throw new Exception("The extensions property must have a value if supplied.");
            }
        }