I am trying to find a way to test some code I have that will query an azure storage queue. For now, I have been asked to create my own local in memory queue class that simulates the upstream Azure queue. At this point, I'm trying to see if I can create a sample message in a fake queue so the callee of my class has some data to work with.
So I'm trying to do something like this:
using Azure.Storage.Queues.Models;
namespace Widgets.Tests.Queues
{
public class InMemoryAzureMessageQueue : IAzureQueueClient
{
public string DequeueMessage(QueueMessage message)
{
throw new System.NotImplementedException();
}
public QueueMessage[] GetMessages()
{
//pseudocode
QueueMessage qm = new QueueMessage();
QueueMessage[] listqm = new QueueMessage[];
qm.messageID = xxx;
qm.messageBody = "hello";
listqm.add(qm);
return listqm;
}
public bool HasMesssages()
{
return true;
}
}
}
When I try to create "qm" I'm getting the following error message: 'QueueMessage' does not contain a constructor that takes 0 arguments
What I've Tried So Far:
I have tried to "go to defintion" while clicking on QueueMessage just to see what the constructor looks like. But when I do, I get an error saying that there is no definition found.
The description of the class says this:
The object returned in the QueueMessageList array when calling Get Messages on a Queue.
Maybe I can't just create a message like this?
I'm really green at .NET and all things Azure. Any tips would be appreciated.
The QueueMessage
class does not contain an accessible constructor. You can however build a message using the QueuesModelFactory
, which was designed for mocking these messages:
public QueueMessage[] GetMessages()
{
QueueMessage qm = QueuesModelFactory.QueueMessage(
messageId: "xxx",
popReceipt: "",
messageText: "hello",
dequeueCount: 0);
QueueMessage[] listqm = new QueueMessage[1];
listqm[0] = qm;
return listqm;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.