Where
, because it's an extension method, so it's static.
gatheredFramesProfiles
is a collection: it's not very common to fake a collection, because configuring its behavior is cumbersome. You're usually better off using a real collection whose content you control.
IQueryable
, you can also use a collection and use AsQueryable
to convert the collection to an IQueryable
A.CallTo(() => config["myAppSettingsKey"]).Returns("FakeItEasy is Cool")
?
I'm not sure what "config wasn't there" means. I don't think you mean config
the variable...
There should be no problem if there isn't a preconfigured value for "myAppSettingsKey". You'd just be telling the fake "if someone calls the this
method with the argument "myAppSettingsKey", return "FakeitEay is Cool"". (I don't know why I uppercased Cool)
IConfiguration
), and it worked perfectly...
namespace FakeItEasyQuestions
{
using System;
using FakeItEasy;
public class Program
{
static void Main(string[] args)
{
Test();
System.Console.Out.WriteLine("Test passed!");
}
public static void Test()
{
var config = A.Fake<IConfiguration>();
A.CallTo(() => config["myAppSettingsKey"]).Returns("FakeItEasy is Cool");
var result = config["myAppSettingsKey"];
if (result != "FakeItEasy is Cool") {
throw new Exception(result);
}
}
public interface IConfiguration {
string this[string key] { get; set; }
}
}
}
7.0.0-beta.1 is out. Come and get it.
Hi, @eternaleap. This is a perfectly acceptable place to ask!
Alternatives are at the StackOverflow FakeItEasy tag or you could create an issue at the FakeItEasy repository, but here is good. Let's continue.
Your code is a little terse, so there are some details I have to guess at. It might be better to include more, and or/describe exactly what happens, but your second approach sounds good to me. I would've written this code myself:
A.CallTo(() => fake.Insert(A<TypeOfP>._).ReturnsLazily((TypeOfP p) => p));
Where TypeOfP
is of course the type of the argument. This is exactly the approach described at Return Values Calculated at Call Time
If this is not working for you, the first thing I'd do is make sure you're configuring the right method. Are you using the correct type in the argument list? Is there an overload of Insert
that takes more (or fewer) parameters that you're actually calling in the production code, so the one-parameter version (that takes a TypeOfP
) isn't actually being called? Sometimes this is easy to check visually, or sometimes it can help to debug into the code.
If you're able to supply more of your test and production code, or at least method signatures, we might be able to help, if you're still stuck.