Created
August 20, 2013 02:49
-
-
Save choudeshell/6276595 to your computer and use it in GitHub Desktop.
Type 'Castle.Proxies.IRepository`1Proxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is attempting to implement an inaccessible interface.
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
public class DynamoMock | |
{ | |
public static Mock Mock(Type type) | |
{ | |
var mock = typeof(Mock<>).MakeGenericType(type).GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); | |
return (Mock) mock; | |
} | |
public static Mock Mock(Type type, Type type2) | |
{ | |
var mockType = type.MakeGenericType(type2); | |
var mock = typeof(Mock<>).MakeGenericType(mockType).GetConstructor(Type.EmptyTypes).Invoke(new object[] { }); | |
return (Mock)mock; | |
} | |
public static object CreateInstance(Type type, params object[] args) | |
{ | |
return Activator.CreateInstance(type, args); | |
} | |
public static object CreateInstance(Type type, Type type2, params object[] args) | |
{ | |
var endType = type.MakeGenericType(type2); | |
return Activator.CreateInstance(endType, args); | |
} | |
} | |
public class ManagerTest | |
{ | |
[Fact] | |
public void Blah() | |
{ | |
dynamic o = new {ownerID = 1024}; | |
dynamic fakeEntityList = DynamoMock.CreateInstance(typeof(List<>), o.GetType()); | |
fakeEntityList.Add(o); | |
var fakeRepo = DynamoMock.Mock(typeof(IRepository<>), o.GetType()); | |
var t = fakeRepo.Object; <-------EXCEPTION HERE | |
//fakeRepo.SetReturnsDefault(fakeEntityList.AsQueryable); | |
dynamic manager = DynamoMock.CreateInstance(typeof(Manager<>), o.GetType(), fakeRepo.Object); | |
Assert.Throws<Exception>(() => { manager.All(); }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment