Path: redb-route/tests/redb.Route.Tests.DataFormats/AvroDataFormatTests.cs Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages. License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route Page: https://redbase.app/src/dev-2026-12-06/redb-route/tests/redb.Route.Tests.DataFormats/AvroDataFormatTests.cs ---- using redb.Route.Core; using redb.Route.DataFormats.Avro; using redb.Route.TestKit; namespace redb.Route.Tests.DataFormats; public class AvroDataFormatTests { private static readonly OrderRow Sample = new() { Id = 7, Customer = "acme", Amount = 12.5m }; [Fact] public void RoundTrip_SchemaBuiltFromClrType() { var format = new AvroDataFormat(); var bytes = format.Serialize(Sample); var back = format.Deserialize(bytes); bytes.Should().NotBeEmpty(); back.Should().Be(Sample); format.SchemaFor(typeof(OrderRow)).Should().BeOfType(); } [Fact] public void RoundTrip_List() { var format = new AvroDataFormat(); var list = new List { Sample, new() { Id = 8, Customer = "b", Amount = 1m } }; format.Deserialize>(format.Serialize(list)).Should().Equal(list); } [Fact] public void ExplicitSchema_IsUsed() { const string schema = """ {"type":"record","name":"OrderRow","fields":[ {"name":"Id","type":"int"}, {"name":"Customer","type":"string"}, {"name":"Amount","type":{"type":"bytes","logicalType":"decimal","precision":29,"scale":14}} ]} """; var format = new AvroDataFormat(new AvroDataFormatOptions { Schema = schema }); format.Deserialize(format.Serialize(Sample)).Should().Be(Sample); format.SchemaFor(typeof(OrderRow)).Should().BeOfType().Which.Name.Should().Be("OrderRow"); } [Fact] public void ConfluentWireFormat_FramesAndUnframes() { var format = new AvroDataFormat(new AvroDataFormatOptions { ConfluentWireFormat = true, SchemaId = 7 }); var framed = format.Serialize(Sample); framed.Take(5).Should().Equal(0, 0, 0, 0, 7); format.Deserialize(framed).Should().Be(Sample); var act = () => format.Deserialize([1, 2, 3, 4, 5, 6]); act.Should().Throw().WithMessage("Avro data format:*wire format*"); } [Fact] public void Garbage_FailsNamingTheFormat() { var act = () => new AvroDataFormat().Deserialize([0xFF]); act.Should().Throw().WithMessage("Avro data format:*"); } [Fact] public async Task Dsl_And_Registry() { await using var ctx = new RouteContext(); ctx.AddAvroDataFormat(); ctx.AddRoutes(b => { b.From("direct://sugar").MarshalAvro().To("mock://wire").UnmarshalAvro(); b.From("direct://named").Marshal("application/avro").Unmarshal("avro/binary"); }); await ctx.Start(); (await ctx.RequestBody("direct://sugar", Sample)).Should().Be(Sample); (await ctx.RequestBody("direct://named", Sample)).Should().Be(Sample); ctx.Mock("mock://wire").ReceivedExchanges[0].In.ContentType.Should().Be("application/avro"); } }