Search code examples
c#unit-testingmoqmoq-3

My Moq mock isn't being accepted in my method under test


When I create my moq mock and try to pass it into my class constructor I get this message: Argument type Moq.Mock<...mockIAppCache> is not assingable to paramter type 'IAppCache'. I included the library and I can find the reference to Mock() ok. Am I missing something here?

    [TestMethod]
    public void SomeTestMethod()
    {
        var mockIAppCache = new Mock<IAppCache>();
        var mockISeries = new Mock<ISeries>();

        ReportFR2 report = new ReportFR2(SeriesKey.FR2, mockIAppCache);
        DateTime resolvedDate = report.ResolveDate(mockISeries, DateTime.Now);

        //Assert.AreEqual("something", "something");

    }

Solution

  • I believe you need to pass the mock like this:

    ReportFR2 report = new ReportFR2(SeriesKey.FR2, mockIAppCache.Object);