Coder Social home page Coder Social logo

ninject.mockingkernel's Introduction

Ninject.MockingKernel

Build status codecov NuGet Version NuGet Downloads

This extension provides integration between Ninject and Moq/NSubstitute/FakeItEasy, creating a "lightweight" auto-mocking container.

Getting started

In your tests, you should use the MockingKernel instead of the StandardKernel. It adds the following features to Ninject:

  1. The following syntax will bind a service to the mocked object of a Mock<T>.
Bind<IService>().ToMock();

You can add additional interfaces to the mock:

Bind<IService>().ToMock(typeof(IInterface1), typeof(IInterface2));
  1. If you request a service that has no binding, instead of creating an implicit self-binding, the MockingKernel will create an instance of Mock<T> and return the mocked object associated with it.

  2. A Reset() method is available, which clears the Ninject cache of any activated instances, regardless of whether they remain in scope. You can call this method after each test to ensure that instances are reactivated, without having to dispose and re-initialize the kernel each time.

Hat tip to Scott Reynolds for the idea, and to Sean Chambers for dogfooding.

Documentation

https://github.com/ninject/Ninject.MockingKernel/wiki

ninject.mockingkernel's People

Contributors

aloker avatar bnordli avatar iappert avatar remogloor avatar scott-xu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ninject.mockingkernel's Issues

Update NuGet package

The current NuGet package (2.2.0.6) does not work well with .NET 4.0.
Ninject.MockingKernel.Moq.MoqMockProvider.Create(IContext context) throws System.TypeAccessException because of the new security transparency model introduced in .NET 4.0.
This is already fixed in the source (by applying the [System.Security.SecuritySafeCritical] attribute).

Workaround: Build Ninject.MockingKernel yourself.

Proposed fix: Update package in the NuGet gallary.

More information: https://groups.google.com/d/msg/ninject/xInlcd2b1l8/TwIAbkzHhWUJ

Problem FakeItEasy Ninject WebServer

on a unit test [TestClass] i try to use Ninject and module fakeiteasy but the fakeiteasy dont respect singleton or current object, always create new (different hashcode) on a HttpServer local unit test calling internal with HttpClient, and creating fake object on [TestMethod] things like MustHaveHappend Always fail but another object created and its called.

[TestInitialize]
kernel <-- fakeiteasy (standarkernel load fakeiteasymodule)
kernel.bind.ToMock().InSingletonScope();
config.DependencyResolver = new NinjectResolver(kernel);
HttpServer _server = new HttpServer(config);
//using Effort too but out of scope here

[TestMethod]
client = new HttpClient(_server);
request = new HttpRequestMessage(); //uri, headers, method, etc
obj = kernel.Get();
A.Call.obj ... DoesNothing(); //try with and without
using(response =client.SendAsync(request).Result)
{
A.Call ... MustHaveHappend <-- fail
}

if i debug and check HashCode when code execute de Controller on the webapi (project on same solution) [run on the same process, same thread i think (checked on Thread window] and on unittest method check hashcode and they are different objects.

System.InvalidOperationException: Error loading Ninject component IMockProviderCallbackProvider

When I call kernel.Get, it throws the following exception: System.InvalidOperationException: Error loading Ninject component IMockProviderCallbackProvider:

System.InvalidOperationException: Error loading Ninject component IMockProviderCallbackProvider
No such component has been registered in the kernel's component container.

Suggestions:
  1) If you have created a custom subclass for KernelBase, ensure that you have properly
     implemented the AddComponents() method.
  2) Ensure that you have not removed the component from the container via a call to RemoveAll().
  3) Ensure you have not accidentally created more than one kernel.
at Ninject.Components.ComponentContainer.Get(Type component) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Components\ComponentContainer.cs: line 131
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray(IEnumerable`1 source)
at Ninject.Components.ComponentContainer.CreateNewInstance(Type component, Type implementation) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Components\ComponentContainer.cs: line 173
at Ninject.Components.ComponentContainer.ResolveInstance(Type component, Type implementation) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Components\ComponentContainer.cs: line 167
at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate)
at Ninject.KernelBase.HandleMissingBinding(IRequest request) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs: line 493
at Ninject.KernelBase.Resolve(IRequest request) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\KernelBase.cs: line 338
at Ninject.Planning.Targets.Target`1.GetValue(Type service, IContext parent) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Planning\Targets\Target.cs: line 179
at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
at System.Linq.Enumerable.ToArray(IEnumerable`1 source)
at Ninject.Activation.Providers.StandardProvider.Create(IContext context) in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Providers\StandardProvider.cs: line 81
at Ninject.Activation.Context.Resolve() in c:\Projects\Ninject\Maintenance2.2\ninject\src\Ninject\Activation\Context.cs: line 157
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.<CastIterator>d__b1`1.MoveNext()
at System.Linq.Enumerable.Single(IEnumerable`1 source)
at Qbies.Tests.UnitTests.Domain.Achievements.given_a_first_order_achievement..ctor() in FirstOrder.cs: line 41
at Qbies.Tests.UnitTests.Domain.Achievements.and_applying_it..ctor() in FirstOrder.cs: line 51 

I guess it has something to do with the fact that I am using a later version of Ninject than the one that the MockingKernel is build against.

I tried building your source against the latest Ninject version, but then I get a compilation error:

Error   1   'Ninject.Syntax.IBindingToSyntax<T>' does not contain a definition for 'BindingConfiguration' and no extension method 'BindingConfiguration' accepting a first argument of type 'Ninject.Syntax.IBindingToSyntax<T>' could be found (are you missing a using directive or an assembly reference?)   C:\Users\Sipke\Downloads\ninject-ninject.mockingkernel-3.0.0-rc2-0-g097c8ec\ninject-ninject.mockingkernel-097c8ec\src\Ninject.MockingKernel\ExtensionsForBindingSyntax.cs   39  48  Ninject.MockingKernel

MoqKernel.GetMock<T> throws ArgumentException when T is Func<...>

There is the following example:

  1. Interface
    public interface ICustomInterface { ... }

  2. Class
    public class CustomObject
    {
    public CustomObject(Func< ICustomInterface > factoryFunc) { ... }
    }

  3. Test
    [SetUp]
    public void TestInitialize()
    {
    Mock<Func< ICustomInterface >> factoryFuncMock =
    MoqMockingKernel.GetMock<Func< ICustomInterface >>(); <-- ArgumentException
    factoryFuncMock.Setup(...).Returns(...);
    }

As I understand, the exception is thrown because Mock.Get< T >(T) waits for Func< ICustomInterface >, but MoqMockingKernel.Get<Func< ICustomInterface >> returns a FunctionFactory<> type instead of Func<>

This case is helpful when we try to inject Func< ... > with several generic types and then we want to check that Func was called with correct arguments
Example:
Mock<Func<bool, ICustomInterface>> factoryFuncMock = MoqMockingKernel.GetMock<Func<bool, ICustomInterface>>();
factoryFuncMock.Setup(factoryFunc => factoryFunc(true)).Returns(...);

Test passes with StandardKernel, but Fails With MockingKernel

In the following example the test passes when using StandardKernel and fails with MoqMockingKernel
namespace ClassLibrary4
{
using Ninject;
using Ninject.MockingKernel.Moq;
using System;
using Xunit;

    public class Foo
    {
        public Foo([Target1]Bar bar1, [Target2]Bar bar2)
        {
            this.bar1 = bar1;
            this.bar2 = bar2;
        }

        public Bar bar1 { get; private set; }
        public Bar bar2 { get; private set; }
    }

    public class Bar
    {
        public Bar(IZed zed) { this.zed = zed; }
        public IZed zed { get; private set; }
    }

    public interface IZed { }

    public class Zed1 : IZed { }

    public class Zed2 : IZed { }

    public class Target1 : Attribute { }
    public class Target2 : Attribute { }

    public class Tests
    {
        [Fact]
        public void Pass()
        {
            var kernel = new StandardKernel();
            kernel.Bind<IZed>().To<Zed1>().WhenAnyAncestorMatches(r => r.Request.Target?.IsDefined(typeof(Target1), true) ?? false);
            kernel.Bind<IZed>().To<Zed2>().WhenAnyAncestorMatches(r => r.Request.Target?.IsDefined(typeof(Target2), true) ?? false);

            var foo = kernel.Get<Foo>();
            Assert.IsType<Zed1>(foo.bar1.zed);
            Assert.IsType<Zed2>(foo.bar2.zed);
        }

        [Fact]
        public void Fail()
        {
            var kernel = new MoqMockingKernel();
            kernel.Bind<IZed>().To<Zed1>().WhenAnyAncestorMatches(r => r.Request.Target?.IsDefined(typeof(Target1), true) ?? false);
            kernel.Bind<IZed>().To<Zed2>().WhenAnyAncestorMatches(r => r.Request.Target?.IsDefined(typeof(Target2), true) ?? false);

            var foo = kernel.Get<Foo>();
            Assert.IsType<Zed1>(foo.bar1.zed);
            Assert.IsType<Zed2>(foo.bar2.zed);
        }
    }
}

NSubstituteMockingKernel + .NET 4.5

I updated one of our solutions today to the latest version of Ninject and its various ancillary libraries (Ninject.Extensions.Factory, Ninject.MockingKernel and so on), but I can't seem to use the latest version of the NSubstituteMockingKernel.

All of the Ninject Nuget packages appear to work on .NET 4.5 except the Ninject.MockingKernel.NSubstitute package (which appears to require .NET 4.6). I assume I still have to install this package, because I can't find any reference to the NSubstituteMockingKernel in the base Ninject.MockingKernel package, or to any module that would enable the NSubstitute mocks in

NSubstitute doesnt require .NET 4.6 so I'm not sure why the mocking kernel would.

Cannot find kernel Get<T> method

Hello all

I've installed Ninject.MockingKernel.NSubstitute v3.2.20 via Nuget, and all its related dependencies of course. I cannot seem to proceed on the very first basic step: getting an instance of class under test.

var kernel = new NSubstituteMockingKernel();

MyClassUnderTest component = kernel.Get<MyClassUnderTest>();

Get method is not defined. I've also checked (closed) issue #14 , without any luck. I've checked source code here on Github, in this project and in Ninject project, but I could not understand where Get is defined. Is that some extension method or what?

Thanks a lot

Could Not Load Type 'Ninject.MockingKernel.AdditionalInterfaceParameter'

I just installed Ninject.MockingKernel.FakeItEasy 3.2.2 stable and I have the following simple test

        [TestMethod]
        public void TestMethod2()
        {
            using (FakeItEasyMockingKernel kernel = new FakeItEasyMockingKernel())
            {
                var cs = kernel.Get<CustomerService>();
                A.CallTo(() => cs.CreateAsync(CancellationToken.None, "a", "b", "c"))
                   .Returns(new Customer("Adam", "Bob", "Custard"));
                   ...
            }
        }

When to code tries to execute the kernel.Get<>() I get the following error:

Could not load type 'Ninject.MockingKernel.AdditionalInterfaceParameter' from assembly
'Ninject.MockingKernel, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7'.

I've opened up the Object Browser for Nigject.MockingKernel and sure enough the Ninject.MockingKernel.AdditionalInterfaceParameter is missing from ...\packages\Ninject.MockingKernel.3.2.0.0\lib\net45-full\Ninject.MockingKernel.dll

I've looked in the source code and found the file here.

Also, I noticed that the documentation stated to use ```kernel.GetMock<>() but the function is also missing or the documentation is out dated.

Am I missing something?

One last thing; the documentation for class FakeItEasyMockingKernel state "Mocking kernel for NSubstitute" I think it should read "Mocking kernel for FakeItEasy".

Is able mocking a concrete class?

I've tried this:

//Setup Mocks
Mock<Core.Configuration.ICoreConfiguration> mockedConfiguration = this.IoCKernel.GetMock<Core.Configuration.ICoreConfiguration>();
mockedConfiguration.Setup(c => c.UserIdentities).Returns(configurationUsers);

Mock<Core.Kernel> kernel = this.IoCKernel.GetMock<Core.Kernel>();  <<<<

on <<<<< it throws an System.ArgumentException with this message:

Object instance was not created by Moq.

The stack trace is:

   at Moq.Mock.Get[T](T mocked)
   at Ninject.MockingKernel.Moq.MoqMockingKernel.GetMock[T]()
   at Tests.Kernel.Users.Moq.UsersManagementTests.InitializationWithUsersTest() in D:\projects\living\clients\NetCore\Tests.Kernel\Users\UsersTestsMoq.cs:line 41

Which is the difference between MockingKernel.Get<T> and MockingKernel.GetMock()?

Singleton ScopeCallback breaks testing

MockingKernel always instantiates its objects as singletons. This breaks testing, because it preserves state between tests. In addition, Ninject will behave differently in tests than in "production".

Func<T> is not auto-resolved

public interface IDependency
{
    bool DoDependencyStuff();
}

public class FuncClass
{
    private Func<IDependency> _dependencyFactory;

    public FuncClass(Func<IDependency> dependencyFactory)
    {
        _dependencyFactory = dependencyFactory;
    }

    public bool DoStuff()
    {
        return _dependencyFactory().DoDependencyStuff();
    }
}

[TestFixture]
public class FuncClassFixture
{
    [Test]
    public void When_FuncDependency_CanBeResolved()
    {
        var kernel = new MoqMockingKernel();

        // uncommenting the below line will make this test pass, but shouldn't the MockingKernel handle it for me?
        // kernel.Bind<Func<IDependency>>()
        //  .ToMethod(c => () => kernel.GetMock<IDependency>().Object);

        var subject = kernel.Get<FuncClass>();

        var result = subject.DoStuff();
    }
}

Here is the exception that is thrown

Error activating IntPtr
No matching bindings are available, and the type is not self-bindable.
Activation path:
3) Injection of dependency IntPtr into parameter method of constructor of type Func{IDependency}
2) Injection of dependency Func{IDependency} into parameter dependencyFactory of constructor of type FuncClass

  1. Request for FuncClass

Dependency problems getting MockingKernel working

The MockingKernel looks very promising, but I'm having problems getting a version working with Moq on .Net 4.0----I'm using the Ninject.MockingKernel-2.2.0.0-release-net-4.0.zip download from git but it is has a hard dependency on a particular version of Moq:

System.IO.FileLoadException : Could not load file or assembly 'Moq, Version=4.0.812.4, Culture=neutral, PublicKeyToken=69f491c39445e920' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

So I checked the source out from git, and downloaded these to compile with it as per the HowToBuild.txt instructions:

Ninject.Extensions.NamedScope-2.2.0.0-release-net-4.0.zip
Ninject.Extensions.ContextPreservation-2.2.0.0-release-net-4.0.zip
Ninject-2.2.1.0-release-net-4.0.zip

I run UnzipDependencies.cmd but it deletes the version of Ninject.dll in lib (is it supposed to do that?), and indeed when I run ninject I received errors saying Ninject could not be found:

[msbuild] C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Ninject". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\Visual Studio 2010\Projects\ninject.mockingkernel\src\Ninject.MockingKernel\Ninject.MockingKernel.csproj]

I opened the project in Visual Studio 2010 and upgraded to .Net 4.0 and fixed the dependencies there, but I'm now getting the following error:

Error   1   'Ninject.Syntax.IBindingToSyntax<T>' does not contain a definition for 'BindingConfiguration' and no extension method 'BindingConfiguration' accepting a first argument of type 'Ninject.Syntax.IBindingToSyntax<T>' could be found (are you missing a using directive or an assembly reference?)   C:\Visual Studio 2010\Projects\ninject.mockingkernel\src\Ninject.MockingKernel\ExtensionsForBindingSyntax.cs    (line 39)

I assume it has a dependency on a different version of Ninject. At that point I started to wonder if recompiling was indeed the best route to go---it looks like something's out of date. Any advice on how to continue?

I'd much rather just download a precompiled version that will not introduce a hard dependency on an old Moq version (I'm using the current-release version of Moq: v4.0.20926).

Thanks!

-Mike

Unable to bind generic list

This seemed to be possible in 3.2.0.0 but now it seems to always return an empty list when binding a generic list.

Here's an example:
public class Bunny
{
public string Name { get; set; }
}

[TestFixture]
public class BunnyTestFixture
{
    private MoqMockingKernel kernel;

    public BunnyTestFixture()
    {
        kernel = new MoqMockingKernel();
        kernel.Bind<List<Bunny>>().ToMethod(c => BunnyTestFixture.BuildMyBunnyArmy());
    }

    private static List<Bunny> BuildMyBunnyArmy()
    {
        return new List<Bunny>
        {
            new Bunny {Name = "Bugs"},
            new Bunny {Name = "Calvin"},
            new Bunny {Name = "Carter"},
            new Bunny {Name = "Dora"}
        };
    }

    [Test]
    public void TestKernelBinding()
    {
        var bunnyArmy = kernel.Get<List<Bunny>>();

        Assert.IsTrue(bunnyArmy.Count > 0);
    }
}

sourcecode example contains an error

[SetUp]
public void SetUp()
{
this.kernel.Reset();
this.kernel.Bind().To();
}

If you do it like this ninject will throw an error which states "multiple bindings are available. make sure you declared your bindings only once".

This happens when you run more than one testcase, because SetUp method will be called before EVERY test.

Best Regards
Robert Schadt

MockingKernel and Received throws an NotASubstituteException

I'm using NSubstituteMockingKernel in order to build all my dependencies of my library classes. I've been struggling to solve a trouble for a week and I'm really exhausted. I need some help.

This is my class:

class Core : ICoreService, ICore {
    private ICoreConfiguration configuration;

    Core(ICoreconfiguration configuration) {
        this.configuration = configuration;
    }

    override ICoreService.ParentMethod() {   //ICoreService implementation
        foreach (Item item in this.configuration.Items)
            this.ChildMethod();
    }
    virtual ChildMethod() {
      //do something
    }
}

ICoreService is:

interface ICoreService {
    void ParentMethod();
}

ICore is:

interface ICore {
    ICoreConfiguration Configuration { get; }
}

ICoreConfiguration is:

interface ICoreConfiguration {
    IEnumerable<Item> Items { get; }
}

My test is:

[TestFixture]
public class UsersManagementTests
{
    private readonly NSubstituteMockingKernel IoCKernel;

    public UsersManagementTests()
    {
        this.IoCKernel = new NSubstituteMockingKernel();
    }

    [SetUp]
    public void SetUp()
    {
        this.IoCKernel.Reset();
    }

    [Test(Description = "Configured Users are well loaded on Kernel")]
    public void InitializationWithUsersTest()
    {
        //Setup Data
        Item item = Item.Create("item1");
        IEnumerable<Item> items = new List<Item>() { item };

        //Setup Mocks
        this.IoCKernel
            .Get<ICoreConfiguration>()
            .Items
                .Returns(items);
        Core core = this.IoCKernel.Get<Core>();

        //Act
        kernel.ParentMethod();

        //Assert
        IEnumerable<NSubstitute.Core.ICall> calls = kernel.ReceivedCalls(); // ((((((1))))))
        kernel.Received(1).ChildMethod();                                                    // ((((((2))))))
    }
}

When ((((((1)))))) or ((((((2)))))) are reached, I'm getting this NSubstitute.Exceptions.NotASubstituteException exception message now on last line:

NSubstitute extension methods like .Received() can only be called on objects created using Substitute.For() and related methods.

As you can see I'm trying to test ChildMethod method is reached once at least. ChildMethod must be called according to my Core.Kernel implementation.

I will really appreciate some help.

Thanks.

There are no tests for this code

After downloading the code, I wanted to see either proof that it works or examples of how it's used. Since there are no UnitTests, I couldn't answer either of these questions.

Using with nsubstitute ?

HI there,

I looked at the example on the wiki but the nsubstitute doesn't seem to work.

I have tried the following, any ideas ?

this.kernel = new NSubstituteMockingKernel();

var summaryService = this.kernel.GetMock(); // GetMock not available Anybody using it ?

Thanks

problem with automocking named interfaces

Hello Team,

automocking will fail if interfaces are decorated with the ninject named attribute.
I don't know if this is by design or a bug. (Interestingly i haven't found anyone complaining about it except me ...)
But in my opinion it would be much better if named attributes are ignored by the mocking kernel and automocked as well because the stub or mock can be configured anyway and it would be much easier if they get automocked like the rest.

I already have a working solution but i am by far no expert for ninject internals and so my solution feels a bit "unnatural". I can share it if you like though.
My idea was to create new bindings (by using IMissingBindingResolver) and manipulate their metadata so an exact match with the named attribute is generated. This way automocking works as if no named attribute is used.

Best Regards and keep up the extremly good work!
Robert Schadt

Update NSubstitute to current version

The current version of NSubstitute is 1.5.0.0, but Ninject.MockingKernel.NSubstitute still uses 1.3.x.

BTW, is there any reason for limiting the NSubstitute version upwards to the next minor version? Has it got a history of breaking changes?

Incorrect version dependency for Ninject.MockingKernel.Moq NuGet package

Ninject.MockingKernel.Moq 3.2.2.0 appears to depend on Ninject.MockingKernel version 3.2.2.0 or above, but when downloading the former from NuGet Ninject.MockingKernel version 3.2.0.0 is installed. This may cause the following error: System.TypeLoadException : Could not load type 'Ninject.MockingKernel.AdditionalInterfaceParameter' from assembly 'Ninject.MockingKernel, Version=3.2.0.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7'.

As far as I can tell AdditionalInterfaceParameter isn't available in Ninject.MockingKernel 3.2.0.0. Upgrading to 3.2.2.0 fixes the issue.

"Simple" example?

I have a question on the "simple" example. Maybe it is just me but the example doesn't seem to clarify usage for me. I need just the basic setup for a test. The way I understand it is

  1. Create an instance of MockingKernel()
  2. The kernal will "automatically" mock all interfaces. I can get a specific instance of a mock implementation using the method GetMock() on the kernel.
  3. Change the methods of the mocked interface implementations to return what is needed for testing.

I am unclear as to what the role of Reset() is and why in the example the interface is bound to the instance twice (once in the constructor and once via GetMock()).

Thank you.

Setup a mocked injected object

I've configured a MockingKernel in order to mock a dependency:

[TestFixture]
public class TestsFixture
{
    private NSubstituteMockingKernel IoCKernel;

    public UsersTests()
    {
        this.IoCKernel = new NSubstituteMockingKernel();
    }

    [SetUp]
    public void SetUp()
    {
        this.IoCKernel.Reset();
    }

    [Test]
    public void AddUserTest()
    {
        var mock = this.IoCKernel.Bind<Core.Configuration.ICoreConfiguration>().ToMock();
        mock.Setup( <<<<<<< How to substitute methods of this mocked objects??????
            m =>
            m.UserIdentities
                .Returns(new List<UserIdentity>() {new UserIdentity("user1")}
        );

        Core.Kernel coreKernel = this.IoCKernel.Get<Core.Kernel>();
    }
}

According to this documentation I need to call a Setup method in order to substitute methods. Nevertheless, Setup method is not available.

Any ideas?

NSubstitute is on a current version of 1.8.1

I would like to use both Ninject.MockingKernel and NSubstitute version 1.8.1.
Currently the NSubstitute extension for Ninject.MockingKernel is not compatible with NSubstitute version 1.8.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.