Hi I am having the below interfaces and their implementation. Now, I wanted to unit test the Send() method which will actually push the message into a queue.
Since I am new to MoQ, not sure how to get it done.
public interface IAdapter
{
IChannel UseQueue(QueueDetail queueDetail);
}
public interface IChannel
{
void Send(string key, byte[] message);
}
public class AdapternServiceBus : IAdapter
{
readonly IConnection connection;
readonly IModel channel;
public AdapternServiceBus(IConnection connection, IModel channel)
{
this.connection = connection;
this.channel = channel;
}
public IChannel BindAndUseQueue(QueueDetail queueDetail)
{
// Logic of creating and binding queue
return new ServiceBusChannel(this, queueDetail.QueueName);
}
public IModel GetChannel()
{
return channel;
}
}
public class ServiceBusChannel : IChannel
{
readonly string containerName;
IModel channel;
public ServiceBusChannel(AdapternServiceBus adapter, string containerName)
{
this.containerName = containerName;
channel = adapter.GetChannel();
}
public void Send(string key, byte[] message)
{
// Publish the message
channel.BasicPublish(exchangeName, key, null, message);
}
}
Here through factory, we decide which type of framework we need to connect and within the factory, we open a connection which passed on to the next class, so that it can be consumed to create and bind queues.
Implementation of IChannel is the main class which will be used to actually talk with the queue and topics.