Pregunta

I'm new to this, so doubtlessly I'm doing something silly.

I am trying to create a mock object:

mockCurrencyConversion = mocks.NewMock<ICurrencyConversion>();

and getting this error:

The non-generic method 'NMock2.Mockery.NewMock(System.Type)' cannot be used with type arguments

ICurrencyConversion:

public interface ICurrencyConversion
{
    decimal convertCurrency(string fromCurrency, string toCurrency, decimal amount);

    int addNumbers(int i, int j);

    decimal getRate(CurrencyRateResponse rates, string fromCurrency);

    CurrencyRateResponse getCurrencyRates();

    HttpWebRequest GetWebRequest(string formattedUri);
}

My Test Code:

[TestFixture]
public class WhygoTest
{
    private Mockery mocks;
    private ICurrencyConversion mockCurrencyConversion;

    [SetUp]
    public void SetUp()
    {
        mocks = new Mockery();
        mockCurrencyConversion = mocks.NewMock<ICurrencyConversion>();

    }

    [Test]
    public void MyAddTest()
    {
        var cc = new CurrencyConversion();

        Assert.AreEqual(cc.addNumbers(1, 2), 3);
    }
}
¿Fue útil?

Solución

Use the NewMock() method with the type as an argument:

mockCurrencyConversion = 
    (ICurrencyConversion) mocks.NewMock(typeof(ICurrencyConversion));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top