public void DecodeByteArray() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data_base64"] = SampleBinaryDataBase64; obj["datacontenttype"] = "application/binary"; var cloudEvent = DecodeStructuredModeMessage(obj); Assert.Equal(SampleBinaryData, cloudEvent.Data); }
public void DecodeTextBinary() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data_base64"] = Convert.ToBase64String(Encoding.UTF8.GetBytes("some text")); obj["datacontenttype"] = TextBinaryContentType; var cloudEvent = DecodeStructuredModeMessage(obj); Assert.Equal("some text", cloudEvent.Data); }
public void DecodePlainText() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data"] = "some text"; obj["datacontenttype"] = "text/plain"; var cloudEvent = DecodeStructuredModeMessage(obj); Assert.Equal("some text", cloudEvent.Data); }
public void DecodeGuid() { Guid guid = Guid.NewGuid(); var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data"] = GuidPrefix + Convert.ToBase64String(guid.ToByteArray()); obj["datacontenttype"] = GuidContentType; var cloudEvent = DecodeStructuredModeMessage(obj); Assert.Equal(guid, cloudEvent.Data); }
public void DecodeStructuredMode_Base64Data() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data_base64"] = Convert.ToBase64String(Encoding.UTF8.GetBytes("{}")); byte[] bytes = Encoding.UTF8.GetBytes(obj.ToString()); var formatter = CreateFormatter <AttributedModel>(); Assert.Throws <ArgumentException>(() => formatter.DecodeStructuredModeMessage(bytes, null, null)); }
public void DecodeStructuredMode_NoData() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); byte[] bytes = Encoding.UTF8.GetBytes(obj.ToString()); var formatter = CreateFormatter <AttributedModel>(); var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, null, null); Assert.Null(cloudEvent.Data); }
public void DecodeStructuredMode_ContentTypeIgnored() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data"] = new JObject { [AttributedModel.JsonPropertyName] = "test" }; byte[] bytes = Encoding.UTF8.GetBytes(obj.ToString()); var formatter = CreateFormatter <AttributedModel>(); var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, new ContentType("text/plain"), null); var model = (AttributedModel)cloudEvent.Data !; Assert.Equal("test", model.AttributedProperty); }
public void DecodeStructuredMode() { var obj = JsonEventFormatterTest.CreateMinimalValidJObject(); obj["data"] = new JObject { [AttributedModel.JsonPropertyName] = "test" }; byte[] bytes = Encoding.UTF8.GetBytes(obj.ToString()); var formatter = CloudEventFormatterAttribute.CreateFormatter(typeof(AttributedModel)); var cloudEvent = formatter.DecodeStructuredModeMessage(bytes, null, null); var model = (AttributedModel)cloudEvent.Data; Assert.Equal("test", model.AttributedProperty); }