-
Mocking a generic method (that uses TResult) with Microsoft Moles
Situation There is a generic method that uses TResult which you want to mock using Microsoft Moles. Problem You can’t just assign a delegate like on a non-generic method. Solution Create a delegate that behaves like the mocked method should. Define the concrete expected parameter types. Instantiate a new MolesDelegates.Func with the corresponding type-parameters and…
-
Using Microsoft Moles and dynamics (DLR)
Situation You want to use the ‘dynamic’ type in your unit-test. Problem An InvalidOperationException that says ‘Dynamic operations can only be performed in homogenous AppDomain.’ is thrown. Solution Changed the attribute ‘enabled’ of the node ‘legacyCasPolicy’ to ‘false’ in the following configuration file: C:Program Files (x86)Microsoft Visual Studio 10.0Common7IDEPrivateAssembliesMicrosoft.Moles.VsHost.x86.exe.config Sources http://weblogs.asp.net/mjarguello/archive/2011/04/26/using-moles-with-dlr.aspx http://www.cameronfletcher.com/post/InvalidOperationException-Dynamic-operations-can-only-be-performed-in-homogenous-AppDomain.aspx http://social.msdn.microsoft.com/Forums/en/pex/thread/0a931fc1-9049-482a-bf2d-5499ccf65b82 http://stackoverflow.com/questions/4230909/odd-exception-in-mvc-3-project
-
MessageBox in a unit-test
Situation You want to unit-test a method which uses a MessageBox. Problem The MessageBox will pop up and stop the execution of all tests until the user chooses an action (e.g. presses “OK”). Solution One way around this issue is mocking the MessageBox class to just return the expected DialogResult, which can be done using…