Skip to content

Instantly share code, notes, and snippets.

@janosorcsik
Last active December 11, 2017 21:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janosorcsik/03878ef371e44c83faee3d8aa79c68b6 to your computer and use it in GitHub Desktop.
Save janosorcsik/03878ef371e44c83faee3d8aa79c68b6 to your computer and use it in GitHub Desktop.
Fake Context
using System;
using System.Data.Entity;
using System.Linq;
using System.Reflection;
using Entities.HQ;
using Repositories.Contexts;
namespace TestUtils
{
public class FakeHQContext : IHQContext
{
public FakeHQContext()
{
HQCodes = new FakeHQCodesSet();
}
public IDbSet<HQCodes> HQCodes { get; set; }
public Database Database
{
get { return null; }
}
public IDbSet<T> Set<T>() where T : class
{
foreach (PropertyInfo property in typeof (FakeHQContext).GetProperties())
{
if (property.PropertyType == typeof (IDbSet<T>))
{
return property.GetValue(this, null) as IDbSet<T>;
}
}
throw new Exception("Type collection not found");
}
public void SaveChanges()
{
// do nothing
}
}
public class FakeHQCodesSet : FakeDbSet<HQCodes>
{
public override HQCodes Find(params object[] keyValues)
{
return this.SingleOrDefault(e => e.CodeId == (long) keyValues.Single());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment