public void TestStringFiles(string fileName) { var json = File.ReadAllText($@"./V01Tests/samples/string/{fileName}"); var evnt = CloudEventV0_1.Deserialize(json); Assert.IsType <StringCloudEventV0_1>(evnt); }
public void TestBinaryFiles(string fileName) { var json = File.ReadAllText($@".\v01\samples\binary\{fileName}"); var evnt = CloudEventV0_1.Deserialize(json); Assert.IsType <BinaryCloudEventV0_1>(evnt); }
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); }
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); }
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."); } }