c# - How can I fake a DbSet<T> using FakeItEasy when the classes are internal? -
I am using unit framework 6 and want to test some of my business logic code unit. After Microsoft's examples of doing so, they are MOQ
:
var mockSet = new mock & lt; DbSet & lt; Blog & gt; & Gt; Using the following (), provide the following examples; Var moccontx = new fake & lt; Blogging Contex & gt; (); Mokkontext. Setup (m => m.blogs). Return (masket object); Var Service = New BlogService (mockContext.Object);
I'm using FakeItEasy
instead of MOQ, and I expected that this would be just as simple, although
FakeItEasy complains that this can not make a duplicate for me using
DbSet
the following:
on fakeDbSet = A.Fake & LT ; DbSet & LT; InstalledProduct & gt; & Gt; ();
I have an exception as follows:
FakeItEasy.Core.FakeCreationException: In the form of "TN.Prs.Persistence.LicenseContext" Failed
Below is a list of reasons for Constructor failure: No Constructor Logic Fail: A usable default constructor type was found on TN.Prs.Persistence.LicenseContext. An exception was caught during this call. Its message was: Access denied: 'TN.Pers.Presence License Contact ' FakeItEasy.Core.DefaultExceptionThrower.ThrowFailed Manage Propose Reciprocated Concecutters with Type (Type Type Effect, String ReasonFileerFunctioned Constructor, IEImreable
1On resolved Concecutters) on FakeItEasy. CreationkFakeObjectCreatorkTryCreateFakeWithDummyArgumentsForConstructor (type typeOfFake, fakeOptions fakeOptions, IDummyValueCreationSession session string failReasonForDefaultConstructor, Boolean throwOnFailure) to (type typeOfFake, fakeOptions fakeOptions, IDummyValueCreationSession session, Boolean throwOnFailure) on FakeItEasy.Creation.DefaultFakeAndDummyManager.CreateFake FakeItEasy.Creation.FakeObjectCreator.CreateFake (Type typeOfFake, FakeOptions option) at FakeItEasy.Creation.DefaultFakeCreatorFacade.CreateFake [T] (action
1 option) at F.I.E.E.FakeT on TN.Prs.RegistrationServices.Specifications.when_activating_a_produ ct_from_a_valid_digitally_signed_activation_key. & Lt; .
>
DynamicProxyGenAssembly2 As appropriate as InternalsVisibleTo , when I make the sections public, everything works, but I really do not want to reveal these sections publicly I appreciate any suggestions. Here is my reference class:
Internal category licensed: DBCOntax {public license (public)} Public virtual dbet & lt; InstalledProduct & gt; Managed products {get; Set; }}
The problem is resolved!
Before I joined the International Visible Attributes, the fake ITC complained and told me to add those features and I was happy to see that this requires the correct code in the error message. I also commented to any of my colleagues, " now THAT is what I call an error message! ". Feature was suggested:
[assembly: InternalsVisibleTo ( "DynamicProxyGenAssembly2, PublicKey = 0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")]
Unfortunately it does not work and I The 'Access denied' error may be that the public key is not correct, but since my assemblies are not strong-nominated, Removing the public key with some things.
Eventually I will have strong names, I have Legislative Assemblies, so I have to solve this public key problem eventually, but I know that this should not be an obstacle to do this.
Comments
Post a Comment