Category Archives: C#

How to mock lazy initialization of objects in C# unit tests using Moq

I was unable to find it clearly documented how to use Moq with objects that are to be lazy initialized, so below are the steps I took to do so. Here is my class under test: public class MyClass { … Continue reading

Posted in C#, Moq | Tagged , | 2 Comments

C# – Copying HTTP request parameters in call to RedirectToAction

I have been learning C# over the past year and today I encountered a situation with Controller.RedirectToAction() that I took awhile to find a solution to so I wanted to write down my solution. In my case, I was in … Continue reading

Posted in C# | Tagged | Leave a comment

Unit Test Stubs – Returning different values on consecutive calls

I have been learning C# these past few months.  The other day I had to write a unit test in C# that would return different results on consecutive calls from a mocked method where the inputs were the same.  With … Continue reading

Posted in C#, Moq | Tagged , | Leave a comment