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

Entity Framework Core - Knowledge Base (KB)

23 results in tag: moq

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

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

Mocking DbContext in Entity Framework 6.1

I have found a number of examples that show (apparently) a clear working example of mocking DbContext with EF 6, however, none of them seem to work for me and I am not entirely sure why....This is my unit test code that sets up the mock;...var mockData = ...
c# entity-framework entity-framework-6 moq unit-testing
asked by ChrisBint

Is there a way to generically mock the DbSet.Find method with Moq?

I'm currently using an extension method to generically mock DbSets as a list:... public static DbSet<T> AsDbSet<T>(this List<T> sourceList) where T : class { var queryable = sourceList.AsQueryable(); var mockDbSet = new Mock<DbSet<T...
c# entity-framework entity-framework-6 generics moq
asked by C. Williamson

How to mock an async repository with Entity Framework Core

I'm trying to create a unit test for a class that calls into an async repository. I'm using ASP.NET Core and Entity Framework Core. My generic repository looks like this....public class EntityRepository<TEntity> : IEntityRepository<TEntity> where TEntit...
asp.net-core c# entity-framework-core moq unit-testing
asked by Jed Veatch

How could I Mock the FromSql() method?

I was wondering is there any way other than building a wrapper for mocking the ...FromSql...? I know this method is static, but since they added things like ...AddEntityFrameworkInMemoryDatabase... to entity framework core, I thought there might be a solu...
c# entity-framework-core moq unit-testing
asked by Hamid Mosalla

Converting IQueryable to implement IAsyncEnumerable

I have a query in a method:...private readonly IEntityReader<Customer> _reader; public async Task<IEnumerable<Customer>> HandleAsync(GetCustomer query) { var result = _reader.Query() .Include(customer => customer.Organization) .Where(...
c# entity-framework-core moq unit-testing
asked by janhartmann

Unit Test with Moq - Value can not be null

I'm using EF6. The generated code is something like:...public partial class MyDataContext : DbContext { public MyDataContext() : base("name=mydata") { } public virtual DbSet<Book> Books { get; set; } } ...Then I have a generic repository ...
c# entity-framework entity-framework-6 moq unit-testing
asked by notlkk

Using Moq with Entity Framework 6 - Mocking Include and Where

I'm trying to create some In-Memory ...dbContext... mocks using ...Moq... and using ...EntityFramework.Testing.Moq... extension methods:...https://github.com/scott-xu/EntityFramework.Testing...I'm hitting a brick wall when I'm trying to unit test my eager...
c# entity-framework entity-framework-6 moq unit-testing
asked by garfbradaz

Xunit - How to use Moq and EF Core for Identity Primary Key

I am trying to automate my UnitTesting with AutoMoq and Xunit for Inserting feature....But I keep getting that I cannot insert a value into the KeyColumn as the following. ...EnrolmentRecordID... is the IdentityColumn in my SQL db and its value is genera...
c# entity-framework-core moq xunit
asked by TTCG

Unit Test Save Changes failing

Frameworks....NETCoreApp 1.1 EF Core 1.1.1 Xunit 2.2.0 Moq 4.7.8 ...Controller Post Method..._yourRepository... is injected in the controllers constructor and is of type ...IYourRepository...[HttpPost(Name = "CreateMethod")] public async Task<IActionResul...
asp.net-core c# entity-framework-core moq xunit2
asked by GreenyMcDuff

How do I go about unit testing with Entity Framework and Moq?

I'm new to Moq, and wanting to use it like a backing store for data - but without touching the live database....My setup is as follows:...A UnitOfWork contains all repositories, and is used for data access throughout the application....A Repository repres...
c# entity-framework entity-framework-6 moq unit-testing
asked by Rhonage

Unit Testing with Moq sometimes fails on ToListAsync()

I'm fairly new to testing with moq and I'm having a strange issue (at least it seems strange to me), but I'm probably just not setting up the mock object correctly. I have a repository layer that uses EntityFrameworkCore to work with my DbContext. One par...
asp.net-core entity-framework-core linq moq unit-testing
asked by starx207

Replacing the value of Setup with Moq

I'm mocking a ...DbContext... and its ...DbSet...s ...as described here.... ...I'd like to create a utility method for creating my mock ...DbContext...s, which sets up each of the context's ...DbSet...s to return an empty list by default (otherwise I get ...
c# entity-framework entity-framework-6 moq
asked by Ben Rubin

How do I mock AddAsync?

I'm writing unit test. For testing the method below, ...public async Task<Guid> CreateWebJobStatus(string blobId, Guid loggedInUserId, string loggedInUserEmail) { Guid webJobStatusId = Guid.NewGuid(); WebJobStatus newWebJobStatus = new WebJobSta...
c# entity-framework-core moq unit-testing xunit
asked by Jason Hao

Moq and Entity Framework Core do not really work with asynchronous methods?

I'm trying to create a test repository using Moq with EF Core, using its asynchronous methods (like ...AddAsync... and ...SaveChangesAsync...), but I have not had the slightest success ......I've found many and many blog posts (including questions here), ...
.net-core c# entity-framework-core mocking moq
asked by GustavoAdolfo

Moq and setting up DB Context

I have an Entity Framework DB Context file. I am trying to setup a Moq framework in NUnit. Currently receiving error below for Moq Nunit test. How would I setup the DBContext, and add items to a Product Table?..."No database provider has been configured f...
asp.net-core c# entity-framework-core moq nunit
asked by user10503656

Expression<Func<T, bool>> is not working as expected in mock setup

This is the method I want to test:...public async Task<List<Lesson>> GetProfessionalLessonsByTutorIdAsync(long tutorId) { return await _unitOfWork.Repository<Lesson>().GetEntities(l => l.TeacherId == tutorId && l.LessonTypeId == 1) .A...
c# entity-framework-core moq unit-testing
asked by TanvirArjel

Mocking EF core dbcontext and dbset

I am using ASP.NET Core 2.2, EF Core and MOQ. When I run the test I am getting this error:...Message: System.NotSupportedException : Invalid setup on a non-virtual (overridable in VB) member: x => x.Movies...What I am doing wrong?...public class MovieRepo...
asp.net-core c# entity-framework-core moq unit-testing
asked by MarcosF8

How to Mock Entity Framework Core Change Tracking

I have a Mocked Context Setup like this....// Creates a working Fake Db Set of FakeClass Type var fakeDbSet = Mockings.CreateDbSetMock(fakeData); var fakeContext = new Mock<FakeContext>(); fakeContext.Setup(c => c.FakeData).Returns(fakeDbSet); ..
c# entity-framework-core mocking moq unit-testing
asked by Zalhera

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
Get monthly updates by subscribing to our newsletter!
SUBSCRIBE!