Skip to content

Testability of HandleBasicDeliver in IAsyncBasicConsumer #1630

@Tornhoof

Description

@Tornhoof

Is your feature request related to a problem? Please describe.

Currently the method is defined as following:
HandleBasicDeliver in IAsynBasicConsumer is defined as following

Task HandleBasicDeliver(string consumerTag,
ulong deliveryTag,
bool redelivered,
string exchange,
string routingKey,
ReadOnlyBasicProperties properties,
ReadOnlyMemory<byte> body);

Passing in ReadOnlyBasicProperties directly and not the interface ReadOnlyBasicProperties makes it hard to test in Unit Tests via mocks, the type is sealed and has no easy constructors.

I have a rather large suit of mocked tests of my derived types of DefaultAsyncBasicConsumer et. al.

Describe the solution you'd like

It would be nice if the method is either using the interface or ReadOnlyBasicProperties gets a constructor in the other direction from BasicProperties, just like the other way round.

Describe alternatives you've considered

I'm currently using the wireformatting directly to create the type:

        public static ReadOnlyBasicProperties FromBasicProperties(this BasicProperties basicProperties)
        {
            var writeable = (IAmqpWriteable)basicProperties;
            var bufferLength = writeable.GetRequiredBufferSize();
            var array = new byte[bufferLength];
            var length = writeable.WriteTo(array);
            var span = array.AsSpan(0, length);
            var readOnlyBasicProperties = new ReadOnlyBasicProperties(span);
            return readOnlyBasicProperties;
        }

This works but kinda feelds like a crutch.

Additional context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions