Search code examples
c#automockingmachine.fakes

How to tell Machine.Fake to satisfy a dependency with a given type


Suppose I have a context that is configured similar to:

Establish context = () =>
    {
        ...

        IFileProcesser processer = new FileProcesser();

        The<IFileProcesser>()
            .WhenToldTo(x => x.Read(Param<Stream>.IsAnything))
            .Return<Stream>(processer.Read);

        ...
    };

Is there a better way to tell Machine.Fakes to not fake IFileProcesser and use the implementation of FileProcesser?


Solution

  • You can use the Configure method for this.

    Establish context = () =>
    {
        Configure(x => x.For<IFileProcesser>().Use<FileProcesser>());
    };
    

    If something is registered that way (there're several overloads of Use) it has precedence over the auto mocking capabilities.

    HTH