I have a similar issue to these threads:
http://www.telerik.com/community/forums/justmock/general-discussions/mock-initialize.aspx
http://www.telerik.com/community/forums/justmock/general-discussions/mocks-failing-to-work-correctly-in-large-test-runs.aspx
My issue is with extension methods. I have an extension method for a list called RandomItem. As you could guess, it returns a random item from the list. Now I have a unit test on a function that uses the extension method. So I mock that extension method in the unit test so that I can determine what item comes back so I can verify the expectation. I can run that test by itself all day long and the mock works.
However, I have another set of tests that actually test the logic of the extension method. When these run with it then the mock on the extension method fails. Generally I would use something like Mock.Initialize or Mock.Partial but it wont even let me do something like this:
because it is a static class. So I tried this stuff:
But it still fails. Any ideas?
http://www.telerik.com/community/forums/justmock/general-discussions/mock-initialize.aspx
http://www.telerik.com/community/forums/justmock/general-discussions/mocks-failing-to-work-correctly-in-large-test-runs.aspx
My issue is with extension methods. I have an extension method for a list called RandomItem. As you could guess, it returns a random item from the list. Now I have a unit test on a function that uses the extension method. So I mock that extension method in the unit test so that I can determine what item comes back so I can verify the expectation. I can run that test by itself all day long and the mock works.
However, I have another set of tests that actually test the logic of the extension method. When these run with it then the mock on the extension method fails. Generally I would use something like Mock.Initialize or Mock.Partial but it wont even let me do something like this:
Mock.Initialize<List<ListExtensions>>()
Mock.SetupStatic(
typeof
(ListExtensions));
Mock.Partial<List<IDataItem>>().For(x => x.RandomItem());
But it still fails. Any ideas?