Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the Get method missing from MoqMockingKernel?

Tags:

c#

moq

ninject

I'm using MoqMockingKernel following the example from the wiki but the Get() method is missing. My simplified code:

using Moq;
using Ninject.MockingKernel.Moq;

namespace Store.Web.Tests.Controllers
{
    [TestClass]
    public class PeopleControllerTests
    {
        private MoqMockingKernel _mockingKernel;        

        [TestInitialize]
        public void SetUp()
        {
            _mockingKernel = new MoqMockingKernel();            
        }

        [TestMethod]
        public void AddAnotherPersonAddsAnotherPerson()
        {
            // There is no Get method on _mockingKernel
            var peopleController = _mockingKernel.Get<PeopleController>();                      
        }
    }
}

What am I doing wrong here? It has GetHashCode(), GetMock(), GetModules(), and GetType() but no Get().

like image 952
Mike B Avatar asked Mar 19 '23 11:03

Mike B


1 Answers

Finally figured it out. Get() is an extension method that lives in the Ninject.ResolutionExtensions class. Adding using Ninject; solved the problem. None of the examples show which namespaces you need to use which is frustrating.

like image 81
Mike B Avatar answered May 01 '23 10:05

Mike B