/// <summary> /// Creates a new instance of the <see cref="CloudEvent{T}"/> class. /// </summary> /// <typeparam name="T">Type of data.</typeparam> /// <param name="contentType">Content type.</param> /// <param name="data">Event data.</param> /// <param name="cloudEventsVersion"><see cref="CloudEventsVersion"/> value.</param> /// <returns>Returns the <see cref="CloudEvent{T}"/> instance created.</returns> public static CloudEvent <T> Create <T>(string contentType, T data, string cloudEventsVersion = CloudEventsVersion.Version01) { if (IsJson(contentType)) { var objectEventised = new ObjectEvent <T>(cloudEventsVersion) { ContentType = contentType, Data = data }; return(objectEventised); } if (ContentTypeValidator.IsText(contentType)) { var stringified = data as string; var stringEventised = new StringEvent(cloudEventsVersion) { ContentType = contentType, Data = stringified }; return(stringEventised as CloudEvent <T>); } var binarified = data as byte[]; var binaryEventised = new BinaryEvent(cloudEventsVersion) { ContentType = contentType, Data = binarified }; return(binaryEventised as CloudEvent <T>); }
public void Given_Type_Should_IsText_ReturnValue() { var result = ContentTypeValidator.IsText("lorem ipsum"); result.Should().BeFalse(); result = ContentTypeValidator.IsText("text/plain"); result.Should().BeTrue(); }
/// <inheritdoc /> protected override bool IsValidDataType(string data) { if (ContentTypeValidator.ImpliesJson(this.ContentType)) { return(false); } if (ContentTypeValidator.IsText(this.ContentType)) { return(true); } return(false); }