zzz projects Entity Framework 6 EF 6
Home EF Core Articles Knowledge Base Online Examples
  • Home
  • EF Core
  • Articles
  • Knowledge Base
  • Online Examples

Entity Framework 6 - Knowledge Base (KB)

35 results in tag: moq

With Moq, unit test the EF Repository pattern.

I decided to start writing unit tests in our application. It uses Entity Framework with a repository pattern....Now I want to start testing logic classes which are using the repositories. I provide a simple example here....Three of my methods in the class...
entity-framework moq repository-pattern unit-testing
asked by John

Why DbContext doesn't implement IDbContext interface?

Why there is no ...IDbContext... interface in the Entity Framework? Wouldn't it be easier to test things if there was an existing interface with methods like SaveChanges() etc. from which you could derive your custom database context interface?...public i...
entity-framework mocking moq testing unit-testing
asked by Grief Coder

How to use Moq with Entity Framework IDbSet Count() etc. methods

I'm trying to use ...Moq... to make some tests for Entity Framework Code First classes. I'm very new to Moq and mocking techniques and I wonder if it's possible to easily do a test that I will describe below. I searched through the web for some solutions,...
asp.net-mvc entity-framework moq unit-testing
asked by Episodex

Mocking Database transactions?

I have a pair of tables with a parent/child relationship - incident and incidentDetails. I have a viewmodel that contains information from both of these tables. And I have a business layer method that is passed an instance of the viewmodel that needs to ...
asp.net-mvc-4 c# entity-framework moq unit-testing
asked by Jeff Dege

How to mock Entity Framework 6 Async methods?

I am new in mocking. I want to mock up my base repository which is depend on Entity Framework 6 DbContext But I fail. I searched in Google a lot but did not get any sufficient result. At last I got an example at ...testing with async queries... and try to...
.net c# entity-framework moq unit-testing
asked by Hasanuzzaman

Mocking new Microsoft Entity Framework Identity UserManager and RoleManager

Has anyone come up with a successful mocking solution for ...UserManager... and ...RoleManager...? I have been beating my head against a wall all day. All I want to do is mock the objects to use an in memory collection rather than hitting the Entity Frame...
asp.net-identity c# entity-framework moq unit-testing
asked by Dale Alleshouse

How do I use Moq and DbFunctions in unit tests to prevent a NotSupportedException?

I'm currently attempting to run some unit tests on a query that is running through the Entity Framework. The query itself runs without any issues on the live version, but the unit tests are always failing....I've narrowed this down to my usage of DbFuncti...
c# entity-framework moq unit-testing
asked by Lyise

Mock DbContext.set<T>.Add() EF6

I have the following classes (where PilsnerContext is a DbContext class):...public abstract class ServiceBase<T> : IService<T> where T: class, IEntity { protected readonly PilsnerContext Context; protected ServiceBase(PilsnerContext context) ...
.net c# entity-framework moq unit-testing
asked by ferflores

Cannot get DbSet.Find to work with Moq (Using the Entity-Framework)

For some reason this code keeps failing. Anyone that can tell me why:... var activeLoans = new List<ActiveLoan> { new ActiveLoan{ ID = 1, CaseType = "STL", LoanCode = 0 }, ...
c# entity-framework moq
asked by Peter Poulsen

EF6 DbSet<T> returns null in Moq

I have a typical Repository Pattern setup in my application with a ...DbContext... (EF6):...public class MyDbContext : EFContext<MyDbContext> { public MyDbContext () { } public virtual DbSet<CartItem> Cart { get; set; } ...and a repository:...pu...
c# entity-framework entity-framework-6 moq unit-testing
asked by Stephen Collins

How to Moq Entity Framework SqlQuery calls

I've been able to mock ...DbSet...'s from entity framework with Moq using this ...link.......However, I would now like to know how I could mock the call to SqlQuery. Not sure if this is possible or how as it relies on the mocked db context knowing what "q...
c# dbcontext entity-framework moq
asked by David

Unit Testing Generic Repository "Find" Method - MSTest, Moq, EF6

I'm fairly new to Unit Testing and Moq, but I'm attempting to setup unit tests for a generic repository using Moq and MSTest. I'm sure there's plenty of things I'm potentially doing incorrectly, but I could really use help with testing the expression base...
asp.net-mvc-4 c# entity-framework-6 moq unit-testing
asked by wahwahwah

Using Test Doubles with DbEntityEntry and DbPropertyEntry

I am using the new Test Doubles in EF6 as outlined ...here from MSDN... . VS2013 with Moq & nUnit. All was good until I had to do something like this: ...var myFoo = context.Foos.Find(id);...and then:...myFoo.Name = "Bar";...and then :...context.Entry(my...
dbcontext entity-framework-6 moq testing
asked by Lorne Redmond

Using Moq with EntityFramework graphdiff

I have just added GraphDiff in an existing Entity Framework solution which is utilizing Moq framework for testing. All my tests that are using Moq in insert and update methods are now failing since method ..._context.UpdateGraph... throws following except...
entity-framework graphdiff moq
asked by vipasane

EF6 - Cannot Mock Return Value for ObjectResult<T> for Unit Test

I have code similar to this in a method that I'm trying to unit test:...return _context.usp_get_Some_Data(someStringParam).FirstOrDefault(); ...The stored proc call return type:...ObjectResult<usp_get_Some_Data_Result>. ...In my unit test, I'm trying to ...
c# entity-framework-6 mocking moq unit-testing
asked by dgavian

Mocking Entity Framework 6 ObjectResult with Moq

How can I mock the Entity Framework 6 ObjectResult with Moq so that I can unit test my code that relies on an EF database connection?...Having read numerous questions and answers along these lines, and gleaned many nuggets from what I've read, I've implem...
c# entity-framework entity-framework-6 entity-framework-6.1 moq
asked by Jim Speaker

How can you perform the same tests as Effort using only Moq?

Presently, I have setup a lot of tests including data access layer and business logic layer tests using Effort (see ...https://effort.codeplex.com/...). We have already been using Moq in our unit tests, and my boss would like to keep things simple, so he...
c# effort entity-framework-6 moq unit-testing
asked by user8128167

Mocking DbSet<T> inline

I am using ....NET4.5..., ...EF6..., and ...Moq... for unit testing. I am trying to mock up some Db data for test. I have an example how to do this with declaring ...mockset as variable and then using mocks....public static class TestExtensionMethods { ...
c# dbset entity-framework-6 moq unit-testing
asked by Matas Vaitkevicius

Moq: How to retrieve ID of mocked object

I have successfully created a mocked ...Person... object and I am now trying to use my ...AddChild()... method to add a child to the object via its' Id. My test looks like this:...public class PersonManagerMockTest { private static Guid personGuid; ...
c# entity-framework-6 mocking moq unit-testing
asked by Aaron LWG

How to mock up dbcontext?

I am using Entity Framework 7 in .net core 1.0 rc2. Here is the class....public class ApplicationDbContext : DbContext { public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { } public DbSet<Blog> Bl...
c# entity-framework moq unit-testing
asked by user1108948

Page 1 of 2
  • 1
  • 2
  • »

Prime Library

Performance

  • Entity Framework Extensions
  • Entity Framework Classic
  • Bulk Operations
  • Dapper Plus

Expression Evaluator

  • C# Eval Expression
  • SQL Eval Function
More Projects...

Related

  • EF Extensions Online Benchmark
  • WIN an EF Extensions license
  • EF6 BatchSaveChanges for only $79
Save your entities 20× faster with EF Extensions
SaveChanges vs BulkSaveChanges

EF Extensions
Try for free now
Get monthly updates by subscribing to our newsletter!
SUBSCRIBE!