Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 01 2016 16:24
    jeremymeng synchronize #617
  • Apr 01 2016 14:28
    blairconrad commented #490
  • Apr 01 2016 11:07
    blairconrad commented #629
  • Mar 31 2016 14:14
    PascalK starred FakeItEasy/FakeItEasy
  • Mar 31 2016 13:00
    blairconrad commented #490
  • Mar 31 2016 12:48
    drauch commented #490
  • Mar 31 2016 10:57
    blairconrad commented #617
  • Mar 31 2016 10:52
    adamralph commented #617
  • Mar 31 2016 10:42
    blairconrad commented #617
  • Mar 31 2016 10:41
    blairconrad commented #617
  • Mar 31 2016 10:29
    adamralph commented #617
  • Mar 31 2016 09:27
    adamralph commented #637
  • Mar 31 2016 08:29
    cecilphillip commented #637
  • Mar 31 2016 06:27
    M-Zuber commented #637
  • Mar 31 2016 06:25
    thecodejunkie commented #637
  • Mar 31 2016 06:25
    adamralph commented #637
  • Mar 31 2016 06:24
    adamralph commented #637
  • Mar 31 2016 06:13
    adamralph labeled #637
  • Mar 31 2016 06:13
    adamralph labeled #637
  • Mar 31 2016 06:13
    adamralph assigned #637
Blair Conrad
@blairconrad
(As did I, with my first suggestion! And I'm... moderately experienced with FakeItEasy.)
Nicolas Bourbaki
@b0urb4k1
I think it is cool though to golf out solution this way.
Blair Conrad
@blairconrad
:+1:
:golf:
Blair Conrad
@blairconrad
FakeItEasy 7.1.0 is out. Includes improvements to events API and expanded capabilities for generating collections of Fakes (thanks to @PiotrKlecha).
https://twitter.com/fakeiteasyfx/status/1401848550724706312
sathishgai
@sathishgai:matrix.org
[m]
Hi i am quite new to FakeItEasy, Now i am facing some issue , some objects are dynamically faking as output two fake objects calculation but output fakeobject i want to set some property whilke faking it, please suggest me solution
Blair Conrad
@blairconrad
Hi, @sathishgai:matrix.org. I'd be happy to try to help, but I think I'm going to need a little more detail. Can you expand on what you're trying to do and what's not working? Sample code always helps, even if it's just the API, with an explanation of what you're trying to test.
sathishgai
@sathishgai:matrix.org
[m]
I have one public method for which i am writing UT and inside there is private method which calculate something and return one property as faked automatically and which will be passed to other private method while processing we are applying lock to that but it is throwing exception as can't apply lock to faked object
Blair Conrad
@blairconrad
I'm sorry, @sathishgai:matrix.org , this is just not enough for me to provide any sort of concrete recommendation.
It sounds like the problem is there's a Fake that you're trying to lock on and it's throwing. Can you provide the exception output?
In general, if a Fake is not behaving as you'd like, I would recommend either configuring the Fake beforehand or having your tests not use a Fake, if that's applicable. If the Fake is automatically created as the return value of some other method or property, then you may have to first configure the method or property that provides it to provide a different Fake.
sathishgai
@sathishgai:matrix.org
[m]
@blairconrad: could you please provide a sample to configure the private method return type as proper fake object to lock it
Blair Conrad
@blairconrad

I had understood that the private method was part of your system under test, and therefore not on a Fake. If it's on a class that's the base type of a Fake, I'm afraid you cannot configure the method. As noted in What can be faked, only certain methods can be configured.

How is your method creating the "property as faked automatically"? Without seeing some code, and ideally your failures, I'm really working blind here, and don't think I'm going to be able to help you.

Ming
@mingweihe
Hi fakeiteasy, I got an issue which is CallTo not working correctly for 6 parameters. Is anyone having the same issue, or knows how to solve it?
Thomas Levesque
@thomaslevesque
Hi @mingweihe, sorry you're having trouble. Could you please share some code? There's no limit for the number of parameters you can use
Ming
@mingweihe
Hi @thomaslevesque , thank you for replying my message, I just did a test for fakeiteasy using the simplest code segment, seems that fakeiteasy has no issue, something may happen to my code evironment.
Thomas Levesque
@thomaslevesque
Hi @mingweihe, glad you were able to solve it!
orgg92
@orgg92

Hey all, trying to mock a call to a dbcontext (need a .Count to return 0/1) and seem to be getting this error:
The DbContextOptions passed to the AppContextContextProxy constructor must be a DbContextOptions<AppContextContextProxy>.
And in my code I'm faking it like:
var fakeDbContext = A.Fake<AppContext>();

Just wondering what the correct way around this is? (I can't seem to find any docs in such a scenario)

Blair Conrad
@blairconrad
Hi, @orgg92. Sorry you're having difficulties. I'm not an EF person (this is Entity Framework, right), so will need some more context. Can you paste more of your code, and the exact error, including stack trace?
orgg92
@orgg92

Yeah, this is for EF. I have a feeling I may need to create a service to put the context inside of and then fake the service instead, though reading a blog post online it appears the author did manage to get it working and basically looks the same as mine
The stack trace is the following:
Message:
FakeItEasy.Core.FakeCreationException :
Failed to create fake of type Project_API.Data.App_PortalContext:

  Below is a list of reasons for failure per attempted constructor:
    Constructor with signature (Microsoft.EntityFrameworkCore.DbContextOptions`1[Project_API.Data.App_PortalContext]) failed:
      No constructor matches the passed arguments for constructor.
      An exception of type System.InvalidOperationException was caught during this call. Its message was:
      The DbContextOptions passed to the App_PortalContextProxy constructor must be a DbContextOptions<App_PortalContextProxy>. When registering multiple DbContext types, make sure that the constructor for each context type has a DbContextOptions<TContext> parameter rather than a non-generic DbContextOptions parameter.
         at Microsoft.EntityFrameworkCore.DbContext..ctor(DbContextOptions options)
         at Project_API.Data.App_PortalContext..ctor(DbContextOptions`1 options) in C:\Users\\source\repos\Project-API\\Data\App_PortalContext.cs:line 14
         at Castle.Proxies.App_PortalContextProxy..ctor(IInterceptor[] , DbContextOptions`1 options)

Stack Trace:
FailedCreationResult.get_Result() line 82
FakeAndDummyManager.CreateFake(Type typeOfFake, Action`1 optionsBuilder, LoopDetectingResolutionContext resolutionContext) line 42
FakeAndDummyManager.CreateFake(Type typeOfFake, LoopDetectingResolutionContext resolutionContext) line 28
A.FakeT line 31
UnitTest1.ProcessObjectTest() line 54
<>c.<ThrowAsync>b__140_0(Object state)

Blair Conrad
@blairconrad
Thanks. Reading. So you're faking a DbContextOptions<App_PortalContext>?
orgg92
@orgg92
Correct :) I assume this is due to the constructors for the DbContexts taking one parameter like: "public App_PortalContext(DbContextOptions<App_PortalContext> options)
: base(options)" though not sure how to inject this into the faked context
Blair Conrad
@blairconrad
Ooops. I think I mistaked. You're running A.Fake<App_PortalContext>()?
orgg92
@orgg92
Oh yeah, sorry, i read that wrong also ha
Blair Conrad
@blairconrad
That has one constructor of form (DbContextOptions<App_PortalContext>)?
orgg92
@orgg92
Correct, it seems to be the standard constructor for all DbContexts
Blair Conrad
@blairconrad
App_PortalContext is probably your class? And it calls the base's constructor, passing in the DbContextOptions that it receives?
orgg92
@orgg92
Yeah, I mean, I don't ever actually pass in any options so that may be for the code first stuff but I'm not sure, just the same format i've always used, was considering making an overload that takes no parameters but not sure that's a fix and more of a hack haha
Blair Conrad
@blairconrad

I'm worrying that DbContext is performing an exact comparison against the type of the argument, and it's not happy with a Fake DbContextOptions....

Or. What's the signature of your App_PortalContext constructor?

orgg92
@orgg92
Like this...? App_PortalContext.App_POrtalContext(DbContextOptions<App_PortalContext> options)
Blair Conrad
@blairconrad
Oh. That's exactly what I thought it would be, but was afraid it wasn't.
Okay. Experiment time. Do you need to fake the options? Could you pass in real options using WithArgumentsForConstructor?
Alternative experiment: can you debug into the base class's constructor and see the line that's throwing the exception?
Blair Conrad
@blairconrad
Either of these would help verify the "the constructor wants the exact type for the options" theory, rather than accepting a derived type.
orgg92
@orgg92
Hmm, i don't think the options need to be faked but in all honesty I am not sure where they come from considering i never actually add them myself - i kinda assumed they were automatically generated. In a service with DI you typically just use the contexts without any parameter at all (so you'd do private readonly AppContext _appContext or whatever) and that doesn't seem to cause any issues
Blair Conrad
@blairconrad

I think you just expanded our scope. Was there a DI mentioned before? I think we can ignore that for now.
Let's assume that real empty options are fine. Can you try using them? Something like

A.Fake<App_PortalContext>(options => options.WithArgumentsForConstructor(new DbContextOptions<App_PortalContext>()))

?

orgg92
@orgg92
Hm, getting the red squiggles - "Argument 1: cannot convert from 'Microsoft.EntityFrameworkCore.DbContextOptions<Project_API.Data.App_PortalContext>' to 'System.Collections.Generic.IEnumerable<object?>'
Blair Conrad
@blairconrad

strange... is the constructor signature not

App_PortalContext.App_POrtalContext(DbContextOptions<App_PortalContext> options)

from above?

orgg92
@orgg92
I just double checked and yeah inside the class that is correct
Blair Conrad
@blairconrad
Then I do not know who wants the IEnumerable<object?>.
orgg92
@orgg92
Yeah i'm pretty confused, the options parameter never seem to be required when you use or instantiate the context anywhere either
Blair Conrad
@blairconrad

the options parameter never seem to be required

Does your class have more than one constructor overload?
The more you can show me, the easier it is to help....

orgg92
@orgg92
And nope, there is just one constructor which seems to be the standard one for contexts
My context class is like this one here https://www.tektutorialshub.com/entity-framework-core/ef-core-dbcontext/ (minus the overrides for OnConfiguring and OnModelCreating)
Ah wait... so it seems the options are the ones set in the Startup config when registering the context itself
orgg92
@orgg92
However i suppose i don't need to even have the options as it's faked and won't be doing any calls to the server
Blair Conrad
@blairconrad
But you only have one constructor, right? It requires options.
Sorry, between not knowing EF and not seeing any code, I'm working in the dark here.
orgg92
@orgg92
There isn't much else to show that i feel is useful, the class is the same as I linked and i am trying to instantiate the same way i would typically to use the context
I may have to go back and try put inside a service and see if that makes a difference as i won't be directly faking the context
Blair Conrad
@blairconrad
I hope it works out for you. If anything turns up that you think we can help with, do come back.