0

I'm trying to write some tests but I'm not sure how to handle the arguments for setting up my moq mock. Can anyone suggest how I can complete this line of code correctly? Many thanks,

My moq code line

enter image description here

The parameter is of type shown below for the Returns(...) which I'm not sure how to handle.

Parameter intellisense

enter image description here

The method is shown below that I'm trying to moq out.

The method definition

public static async Task<CommandResult> SendSupportAsync(this IBus bus, Command command, bool withLogging = true)

UPDATE

I've tried the suggestion, I've added the mocked object and set up the return but the compiler gives the following error:

An expression tree may not contain a call or invocation that uses optional arguments
James Radford
  • 1,815
  • 4
  • 25
  • 40
  • I did not know MOQ mocked out static methods. I thought you would have to get a testing tool such as TypedMock or the one from Telerik. – TYY Mar 12 '14 at 12:07

1 Answers1

0

If you want to mock the return value, then you can create a mock for it

var resultMock = new Mock<Task<CommandResult>>();

then setup your mock object, and you return it like

bus.Setup(x=>c.SendSupportAsync(new TagCommand(ID, MID))).Returns(resultMock.object);

If you do not want to mock the result, then you can create an instance and return it like

bus.Setup(x=>c.SendSupportAsync(new TagCommand(ID, MID))).Returns(objCommandResult);
Suresh Kumar Veluswamy
  • 4,193
  • 2
  • 20
  • 35