It’s just a few helper extensions for using Moq with Unity that cut down on the noise in tests. My friend Keith came up with it, I just happen to blog about it first. Here it is:
12345678910111213141516171819202122232425
publicstaticclassMoqExtensions{publicstaticMock<T>RegisterMock<T>(thisIUnityContainercontainer)whereT:class{varmock=newMock<T>();container.RegisterInstance<Mock<T>>(mock);container.RegisterInstance<T>(mock.Object);returnmock;}/// <summary>/// Use this to add additional setups for a mock that is already registered/// </summary>publicstaticMock<T>ConfigureMockFor<T>(thisIUnityContainercontainer)whereT:class{returncontainer.Resolve<Mock<T>>();}publicstaticvoidVerifyMockFor<T>(thisIUnityContainercontainer)whereT:class{container.Resolve<Mock<T>>().VerifyAll();}}