Home > Enterprise >  How can I fake an extension method? (System.Collections.Generic.CollectionExtensions.GetValueOrDefau
How can I fake an extension method? (System.Collections.Generic.CollectionExtensions.GetValueOrDefau

Time:07-22

Functions I want to fake

As shown in the image, I want to fake extension method (seen in Specflow's ScenarioContext class) : public bool TryGetValue<TValue>(string key, out TValue value)

I've created fakes for the System.Collection assembly (which contains the IDictionary extension method), but I do not understand how to fake a function which has parameters. I do know how to fake for a parameterless function such as the File.IO.ReadAllLines() function :

            using (ShimsContext.Create())
            {
            System.IO.ShimFile.ReadAllLines = m => new string[]{};
            ....

Can I get help understanding how to mock this extension method: System.Collections.Generic.CollectionExtensions.GetValueOrDefault

... I honestly tried looking for examples, but the only ones I could find were parameterless functions or getters.

CodePudding user response:

I would assume you are talking about console output

  • Related