Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem FakeItEasy Ninject WebServer #38

Open
elkami opened this issue Jul 25, 2019 · 1 comment
Open

Problem FakeItEasy Ninject WebServer #38

elkami opened this issue Jul 25, 2019 · 1 comment

Comments

@elkami
Copy link

elkami commented Jul 25, 2019

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.

@blairconrad
Copy link

For what it's worth, I did a little analysis over at FakeItEasy/FakeItEasy#1597 (comment), but the only library I understand even a little bit in all this is FakeItEasy, so I may be off-base. Highlights follow


In NinjectResolver, I see

public IDependencyScope BeginScope()
{
    return new NinjectScope(_kernel.BeginBlock());
}

I thought that maybe making the new NinjectScope might interfere, and indeed if you remove the .BeginBlock, your original test passes - the same ISomething is used in the test and by the controller.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants