This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private DbSet<T> ToDbSet<T>(List<T> sourceList) where T : class | |
{ | |
var queryable = sourceList.AsQueryable(); | |
var dbSet = new Mock<DbSet<T>>(); | |
dbSet.As<IQueryable<T>>().Setup(m => m.Provider).Returns(queryable.Provider); | |
dbSet.As<IQueryable<T>>().Setup(m => m.Expression).Returns(queryable.Expression); | |
dbSet.As<IQueryable<T>>().Setup(m => m.ElementType).Returns(queryable.ElementType); | |
dbSet.As<IQueryable<T>>().Setup(m => m.GetEnumerator()).Returns(queryable.GetEnumerator()); | |
dbSet.Setup(d => d.Add(It.IsAny<T>())).Callback<T>(sourceList.Add); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
using Moq; | |
using System; | |
using System.Collections.Generic; | |
using System.Data.Entity; | |
using System.Linq; | |
using MyProject.Data; | |
using MyProject.Data.Models; | |
[TestClass()] |