Question

I'm new to Microsoft Moles. I tried to create instance for the stub class generated by Moles, and when I debug it calls the actaul class constructor which I don't need. how to achieve this in Moles. Provided a sample code below for better understanding

public class BaseClass
{
    public BaseClass()
    {
        MarkNew();
    }

    protected void MarkNew()
    {
        this.State = ObjectState.New;
        MarkChild();
    }

    protected virtual void MarkChild()
    {
    }

    public ObjectState State { get; private set; }
}

public class DerivedClass : BaseClass
{
    public DerivedClass() : base()
    {
    }

    public string FileName { get; set; }
    public string Value { get; set; }
}

[PexMethod]
[HostType("Moles")]
public void ReadContentTest(string content)
{
    // Arrange.
    SDerivedClass derivedObject = new SDerivedClass();
    derivedObject.FileName = "test.txt";
    var fs = new SIFileSystem();
    fs.ReadAllTextString = delegate(string fileName)
    {
        PexAssert.AreEqual(derivedObject.FileName, fileName);
        return content;
    };

    // Act.
    var test = new TestReaderWithStubs(fs);
    test.ReadContent(derivedObject);

    // Assert.
    PexAssert.IsTrue(content == derivedObject.Value);
}

Thanks in advance Regards Siva

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top