0
votes

Currently I am trying to mock the Text() method from Excel's Comment interface in C# with moq. MSDN link to Text()

My problem is, that I have to call it with no parameters because I just want to read the content. When calling Text() like this: mockComment.Setup(m => m.Text()).Returns("test comment") the following error is shown:

An expression tree may not contain a call or invocation that uses optional arguments

How can I call Text() so that moq can mock this method?

I am aware of this question link but my problem is that i do not have parameters to pass.

1

1 Answers

2
votes

CLR does not support calling methods with optional arguments either when the arguments are not provided explicitly, since for IL-compiled code the C# compiler inserts the default values at compile time.

Refer this, as it states that the underlying expression tree API does not support optional arguments.