Search code examples
c#moles

Cannot assign to <method name> because it is a method group: Error (Using Moles framework)


These two lines of code give me the error as mentioned in the title. I am trying to define a stub for TestClass

var stubTestClass = new StubsTutorial.Moles.STestClass();
stubTestClass.WriteStuff = () => "Moled in static class!";

And this is how the function WriteStuff() is defined

public class TestClass {
  public string WriteStuff() {
    return "Stuff written in main class.";
  }
}

I am not sure where I am going wrong. And direction would help me.


Solution

  • From a tutorial I found:

    Each mole type is named by prepending an “M” to its name and placing it into a .Moles namespace.

    So maybe your line

    var stubTestClass = new StubsTutorial.Moles.STestClass();
    

    should be changed to

    var moleTestClass = new StubsTutorial.Moles.MTestClass();
    

    though I have no experience with Microsoft Moles.