public void EncodeBinaryModeData_NoData() { var cloudEvent = new CloudEvent().PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); Assert.Empty(formatter.EncodeBinaryModeEventData(cloudEvent).ToArray()); }
public void EncodeBinaryModeData_String_NonTextContentType() { var cloudEvent = new CloudEvent { Data = "text", DataContentType = "application/json" }.PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); Assert.Throws <ArgumentException>(() => formatter.EncodeBinaryModeEventData(cloudEvent)); }
public void EncodeBinaryModeData_ArbitraryObject() { var cloudEvent = new CloudEvent { Data = new object(), DataContentType = "application/octet-stream" }.PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); // See summary documentation for ProtobufEventFormatter for the reasoning for this Assert.Throws <ArgumentException>(() => formatter.EncodeBinaryModeEventData(cloudEvent)); }
public void EncodeBinaryModeData_Bytes() { var cloudEvent = new CloudEvent { Data = SampleBinaryData }.PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); var result = formatter.EncodeBinaryModeEventData(cloudEvent); Assert.Equal(SampleBinaryData, result.ToArray()); }
public void EncodeBinaryModeData_ProtoMessage() { var cloudEvent = new CloudEvent { Data = new PayloadData1 { Name = "fail" }, DataContentType = "application/protobuf" }.PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); // See summary documentation for ProtobufEventFormatter for the reasoning for this Assert.Throws <ArgumentException>(() => formatter.EncodeBinaryModeEventData(cloudEvent)); }
public void EncodeBinaryModeData_String_TextContentType(string charset) { string text = "caf\u00e9"; // Valid in both UTF-8 and ISO-8859-1, but with different representations var encoding = charset is null ? Encoding.UTF8 : Encoding.GetEncoding(charset); string contentType = charset is null ? "text/plain" : $"text/plain; charset={charset}"; var cloudEvent = new CloudEvent { Data = text, DataContentType = contentType }.PopulateRequiredAttributes(); var formatter = new ProtobufEventFormatter(); var result = formatter.EncodeBinaryModeEventData(cloudEvent); Assert.Equal(encoding.GetBytes(text), result.ToArray()); }