public void Avro2Json_ConvertFileContainingHeaderOnly_NoExceptionIsThrown() { //Arrange //Act var resultJson = AvroConvert.Avro2Json(_headerOnlyAvroBytes); //Assert Assert.Equal(@"""""", resultJson); }
private string ToJsonViaAvro <T>(T data, TypeSchema schema) { byte[] result; using (MemoryStream resultStream = new MemoryStream()) { using (var writer = new Encoder(schema, resultStream, CodecType.Null)) { writer.Append(data); } result = resultStream.ToArray(); } var avro2Json = AvroConvert.Avro2Json(result, schema.ToString()); return(avro2Json); }
public void Avro2Json_ConvertDouble_ProducedDesiredJson() { //Arrange var doubleTestObject = 21.34; var expectedJson = JsonConvert.SerializeObject(doubleTestObject); var avroSerialized = AvroConvert.Serialize(doubleTestObject); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertNull_ProducedDesiredJson() { //Arrange string nullTestObject = null; var expectedJson = JsonConvert.SerializeObject(nullTestObject); var avroSerialized = AvroConvert.Serialize(nullTestObject); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertInt_ProducedDesiredJson() { //Arrange var @int = 2137; var expectedJson = JsonConvert.SerializeObject(@int); var avroSerialized = AvroConvert.Serialize(@int); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertString_ProducedDesiredJson() { //Arrange var @string = "I am the serialization string"; var expectedJson = JsonConvert.SerializeObject(@string); var avroSerialized = AvroConvert.Serialize(@string); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertArray_ProducedDesiredJson() { //Arrange var arrayTestObject = new int[] { 2, 1, 3, 7, 453, 1, 6, }; var expectedJson = JsonConvert.SerializeObject(arrayTestObject); var avroSerialized = AvroConvert.Serialize(arrayTestObject); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertDateTime_ProducedDesiredJson() { //Arrange var testObject = new DateTime(2022, 06, 13, 2, 0, 0, DateTimeKind.Utc); var expectedJson = JsonConvert.SerializeObject(testObject); var avroSerialized = AvroConvert.Serialize(testObject); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertDouble_ProducedDesiredJson() { //Arrange var doubleTestObject = 21.34; var expectedJson = JsonConvert.SerializeObject(doubleTestObject); var schema = AvroConvert.GenerateSchema(doubleTestObject.GetType()); var avroSerialized = AvroConvert.SerializeHeadless(doubleTestObject, schema); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized, schema); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertNull_ProducedDesiredJson() { //Arrange string nullTestObject = null; var expectedJson = JsonConvert.SerializeObject(nullTestObject); var schema = AvroConvert.GenerateSchema(nullTestObject?.GetType()); var avroSerialized = AvroConvert.SerializeHeadless(nullTestObject, schema); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized, schema); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertInt_ProducedDesiredJson() { //Arrange var @int = 2137; var expectedJson = JsonConvert.SerializeObject(@int); var schema = AvroConvert.GenerateSchema(@int.GetType()); var avroSerialized = AvroConvert.SerializeHeadless(@int, schema); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized, schema); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertString_ProducedDesiredJson() { //Arrange var @string = "I am the serialization string"; var expectedJson = JsonConvert.SerializeObject(@string); var schema = AvroConvert.GenerateSchema(@string.GetType()); var avroSerialized = AvroConvert.SerializeHeadless(@string, schema); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized, schema); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertArray_ProducedDesiredJson() { //Arrange var arrayTestObject = new int[] { 2, 1, 3, 7, 453, 1, 6, }; var expectedJson = JsonConvert.SerializeObject(arrayTestObject); var schema = AvroConvert.GenerateSchema(arrayTestObject.GetType()); var avroSerialized = AvroConvert.SerializeHeadless(arrayTestObject, schema); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized, schema); //Assert Assert.Equal(expectedJson, resultJson); }
public void Avro2Json_ConvertComplexType_ProducedDesiredJson() { //Arrange var user = new User(); user.favorite_color = "blue"; user.favorite_number = 2137; user.name = "red"; var expectedJson = JsonConvert.SerializeObject(user); var avroSerialized = AvroConvert.Serialize(user); //Act var resultJson = AvroConvert.Avro2Json(avroSerialized); //Assert Assert.Equal(expectedJson, resultJson); }
public void GivenDateTimeProperty_WhenUsingSchemaWithTimeAsTimestampMicroseconds_ThenShouldWork() { //Arrange var toSerialize = new ClassWithDateTime { ArriveBy = DateTime.UtcNow }; //Act var schema = Schema.Create(toSerialize); // Change schema logical type from timestamp-millis to timestamp-micros (a bit hacky) var schemaJson = schema.ToString().Replace(LogicalTypeSchema.LogicalTypeEnum.TimestampMilliseconds, LogicalTypeSchema.LogicalTypeEnum.TimestampMicroseconds); var microsecondsSchema = new JsonSchemaBuilder().BuildSchema(schemaJson); byte[] result; using (MemoryStream resultStream = new MemoryStream()) { using (var writer = new Encoder(microsecondsSchema, resultStream, CodecType.Null)) { writer.Append(toSerialize); } result = resultStream.ToArray(); } var avro2Json = AvroConvert.Avro2Json(result, microsecondsSchema.ToString()); var deserialized = JsonConvert.DeserializeObject <ClassWithDateTime>(avro2Json); //Assert Assert.NotNull(result); Assert.NotNull(deserialized); Assert.Equal(toSerialize.ArriveBy.Millisecond, deserialized.ArriveBy.Millisecond); Assert.Equal(toSerialize.ArriveBy.Second, deserialized.ArriveBy.Second); Assert.Equal(toSerialize.ArriveBy.Minute, deserialized.ArriveBy.Minute); Assert.Equal(toSerialize.ArriveBy.Hour, deserialized.ArriveBy.Hour); Assert.Equal(toSerialize.ArriveBy.Day, deserialized.ArriveBy.Day); Assert.Equal(toSerialize.ArriveBy.Month, deserialized.ArriveBy.Month); Assert.Equal(toSerialize.ArriveBy.Year, deserialized.ArriveBy.Year); }