All Projects → romantitov → Mockqueryable

romantitov / Mockqueryable

Licence: mit
Moking Entity Framework Core operations such ToListAsync, FirstOrDefaultAsync etc

Projects that are alternatives of or similar to Mockqueryable

Efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
Stars: ✭ 10,838 (+3756.94%)
Mutual labels:  entity-framework, dotnet-standard, dotnet-framework, dotnet-core
Tweetinvi
Tweetinvi, an intuitive Twitter C# library for the REST and Stream API. It supports .NET, .NETCore, UAP (Xamarin)...
Stars: ✭ 812 (+188.97%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core, netcore
Entityframeworkcore.cacheable
EntityFrameworkCore second level cache
Stars: ✭ 138 (-50.89%)
Mutual labels:  entity-framework, dotnet-standard, dotnet-framework, dotnet-core
Theraot
Backporting .NET and more: LINQ expressions in .net 2.0 - nuget Theraot.Core available.
Stars: ✭ 112 (-60.14%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Linqtotwitter
LINQ Provider for the Twitter API (C# Twitter Library)
Stars: ✭ 401 (+42.7%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Raft.net
Implementation of RAFT distributed consensus algorithm among TCP Peers on .NET / .NETStandard / .NETCore / dotnet
Stars: ✭ 112 (-60.14%)
Mutual labels:  dotnet-standard, dotnet-core, netcore
Minion
Background job system for .NET applications
Stars: ✭ 94 (-66.55%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Dotnet Etcd
A C# .NET (dotnet) GRPC client for etcd v3 +
Stars: ✭ 157 (-44.13%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Colore
A powerful C# library for Razer Chroma's SDK
Stars: ✭ 121 (-56.94%)
Mutual labels:  dotnet-standard, dotnet-core, netcore
Capstone.NET
.NET Core and .NET Framework binding for the Capstone Disassembly Framework
Stars: ✭ 108 (-61.57%)
Mutual labels:  netcore, dotnet-standard, dotnet-framework
Awesome Cms Core
Awesome CMS Core is an open source CMS built using ASP.Net Core & ReactJS with module seperation concern in mind and provide lastest trend of technology like .Net Core, React, Webpack, SASS, Background Job, Message Queue.
Stars: ✭ 352 (+25.27%)
Mutual labels:  automapper, dotnet-standard, dotnet-core
Dnczeus
DncZeus 是一个基于ASP.NET Core 3 + Vue.js(iview-admin) 的前后端分离的通用后台权限(页面访问、操作按钮控制)管理系统框架。后端使用.NET Core 3 + Entity Framework Core构建,UI则是目前流行的基于Vue.js的iView(iview-admin)。项目实现了前后端的动态权限管理和控制以及基于JWT的用户令牌认证机制,让前后端的交互更流畅。码云镜像:https://gitee.com/rector/DncZeus 。演示地址(demo):
Stars: ✭ 1,104 (+292.88%)
Mutual labels:  entity-framework, dotnet-core, netcore
Appmetrics
App Metrics is an open-source and cross-platform .NET library used to record and report metrics within an application.
Stars: ✭ 1,986 (+606.76%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Sharpsnmplib
Sharp SNMP Library- Open Source SNMP for .NET and Mono
Stars: ✭ 247 (-12.1%)
Mutual labels:  dotnet-standard, dotnet-framework, dotnet-core
Etl.net
Mass processing data with a complete ETL for .net developers
Stars: ✭ 129 (-54.09%)
Mutual labels:  entity-framework, dotnet-standard, dotnet-core
Entityframework Extensions
Entity Framework Bulk Operations | Improve Entity Framework performance with Bulk SaveChanges, Insert, update, delete and merge for SQL Server, SQL Azure, SQL Compact, MySQL and SQLite.
Stars: ✭ 215 (-23.49%)
Mutual labels:  entity-framework, dotnet-standard, dotnet-core
Beef
Business Entity Execution Framework
Stars: ✭ 95 (-66.19%)
Mutual labels:  nunit, entity-framework
EFSqlTranslator
A standalone linq to sql translator that can be used with EF and Dapper.
Stars: ✭ 51 (-81.85%)
Mutual labels:  entity-framework, netcore
NeoClient
🦉 Lightweight OGM for Neo4j which support transactions and BOLT protocol.
Stars: ✭ 21 (-92.53%)
Mutual labels:  dotnet-standard, dotnet-framework
colorify
Colorify - C# .Net Console Library with Text Format: colors, alignment and lot more [ Win+Mac+Linux ]
Stars: ✭ 49 (-82.56%)
Mutual labels:  dotnet-standard, dotnet-framework

MockQueryable

Build status Build status Build Status Downloads Downloads Downloads

Build history

Extensions for mocking Entity Framework Core (EFCore) operations such ToListAsync, FirstOrDefaultAsync etc. by Moq, NSubstitute or FakeItEasy When writing tests for your application it is often desirable to avoid hitting the database. The extensions allow you to achieve this by creating a context – with behavior defined by your tests – that makes use of in-memory data.

When should I use it?

If you have something similar to the following code:

var query = _userRepository.GetQueryable();

await query.AnyAsync(x =>...)
await query.FirstOrDefaultAsync(x =>...)
query.CountAsync(x => ...)
query.ToListAsync()
//etc.

and you want to cover it by unit tests

How do I get started?

//1 - create a List<T> with test items
var users = new List<UserEntity>()
{
  new UserEntity{LastName = "ExistLastName", DateOfBirth = DateTime.Parse("01/20/2012")},
  ...
};

//2 - build mock by extension
var mock = users.AsQueryable().BuildMock();

//3 - setup the mock as Queryable for Moq
_userRepository.Setup(x => x.GetQueryable()).Returns(mock.Object);

//3 - setup the mock as Queryable for NSubstitute
_userRepository.GetQueryable().Returns(mock);

//3 - setup the mock as Queryable for FakeItEasy
A.CallTo(() => userRepository.GetQueryable()).Returns(mock);

Do you prefer DbSet?

//2 - build mock by extension
var mock = users.AsQueryable().BuildMockDbSet();

//3 - setup DbSet for Moq
var userRepository = new TestDbSetRepository(mock.Object);

//3 - setup DbSet for NSubstitute or FakeItEasy
var userRepository = new TestDbSetRepository(mock);

Do you use DbQuery?

//2 - build mock by extension
var mock = users.AsQueryable().BuildMockDbQuery();

//3 - setup the mock as Queryable for Moq
_userRepository.Setup(x => x.GetQueryable()).Returns(mock.Object);

//3 - setup the mock as Queryable for NSubstitute
_userRepository.GetQueryable().Returns(mock);

//3 - setup the mock as Queryable for FakeItEasy
A.CallTo(() => userRepository.GetQueryable()).Returns(mock);

Check out the sample project

Where can I get it?

First, install NuGet.

If you are using Moq - then, install MockQueryable.Moq from the package manager console:

PM> Install-Package MockQueryable.Moq

If you are using NSubstitute - then, install MockQueryable.NSubstitute from the package manager console:

PM> Install-Package MockQueryable.NSubstitute

If you are using FakeItEasy - then, install MockQueryable.FakeItEasy from the package manager console:

PM> Install-Package MockQueryable.FakeItEasy

Can I use it with my favorite mock framework?

You can install MockQueryable.EntityFrameworkCore from the package manager console:

PM> Install-Package MockQueryable.EntityFrameworkCore

Downloads

or even MockQueryable.Core

PM> Install-Package MockQueryable.Core

Downloads

Then make own extension for your favorite mock framework

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].