Last active
December 11, 2017 21:02
-
-
Save janosorcsik/03878ef371e44c83faee3d8aa79c68b6 to your computer and use it in GitHub Desktop.
Fake Context
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 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