Search This Blog

Friday, March 11, 2016

Mock Assembly Unit Test C#

C# > Unit tests > Mock Assembly 

If you try to mock

var mock = new Mock<Assembly>();

You will get this error:

The type System.Reflection.Assembly implements ISerializable, but failed to provide a deserialization constructor

Solution

Mock _Assembly interface instead of Assembly class.


var mock = new Mock<_Assembly>();
mock.Setup(w => w.GetTypes()).Throws(new Exception());