J'essaie de mélanger CallsBaseMethod et CallTo et il n'appelle pas celui que j'ai configuré. S'il vous plaît voir le code ci-dessous et mes commentaires. Existe-t-il un moyen de faire en sorte que cela fonctionne ou une approche différente avec FakeItEasy?FakeItEasy CallsBaseMethod imbriqué Faux CallTo n'est pas appelé
public LayoutManager(ICompanyManager companyManager)
{
this._companyManager = companyManager;
}
this.CompanyManagerFake = A.Fake<ICompanyManager>();
// using StructureMap, put this here to make the example more brief, in my code it's in a base class
ObjectFactory.Configure(registry =>
{
registry.For<ICompanyManager>().Use(this.CompanyManagerFake);
});
this._layoutManager = A.Fake<LayoutManager>();
var layouts = GetTestLayouts();
// I want to get the actual GetLayoutForUser method
A.CallTo(() => this._layoutManager.GetLayoutForUser(A<int>.Ignored)).CallsBaseMethod();
// I want to mock the data for the GetAll method (which is called in GetLayoutForUser)
A.CallTo(() => this._layoutManager.GetAll(A<string>.Ignored)).Returns(layouts.AsQueryable());
A.CallTo(() => this.CompanyManagerFake.GetAll(A<string>.Ignored)).Invokes(
call =>
{
// this doesn't get called from GetLayoutForUser, but is from the line below
var x = call.Arguments;
});
// I want to use .Returns(new List<Company>().AsQueryable()); instead of Invokes, but needed to set a breakpoint
// this hits the above Invokes as expected
var assignedCompanIds = this.CompanyManagerFake.GetAll()
.Where(c => c.UserProfiles.Any(up => up.UserId == 123)
|| c.UserProfiles1.Any(up => up.UserId == 123))
.Select(c => c.CompanyId);
// Act
var result = this._layoutManager.GetLayoutForUser(123);
// Assert
// something
Note: Je mets également cette question sur GitHub Cela semble similaire à this question, mais je ne peux pas le mettre ensemble. Alors quand je l'appelle
var assignedCompanyIds = this._companyManager.GetAll()
.Where(c => c.IsAssigned)
.Select(c => c.CompanyId).ToList();
Je reçois cette exception: méthode {X} a jeté exception: System.ArgumentException: Expression de type '' ne peut pas être utilisé pour le paramètre de type « System.Linq.IQueryable 1 [Société] Où [Société] (System.Linq.IQueryable 1[Company], System.Linq.Expressions.Expression
1 [System.Func`2 [Company, System.Boolean]]) '
J'éprouve actuellement ceci aussi bien. –
@Aligned, je passe un moment terrible après cette question. Avez-vous un exemple plus simple qui présente le problème? (Sinon, cela arrive-t-il toujours pour 1.23.0?) –
@BlairConrad J'ai ajouté un commentaire au problème de GitHub et l'ai fermé. Je ne serai pas en mesure de trouver le temps de faire mieux. Merci de l'avoir regardé. – Aligned