Skip to content

Problem FakeItEasy Ninject WebServer #38

@elkami

Description

@elkami

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions