Hi,
After migrating from 2010 Q1 to 2011 Q2, I am facing an issue with Mock.Create<T>() :
I Have a default constructor which is declared after an overloaded constructor (in which i have checks for invalid values).
When I use Mock.Create<T>(), the first constructor is called (not the default one). Thus, I Get an exception from my checks that I didn't have before. Instead I Want Mock.Create<T>() use my default constructor for mocking my type.
Here is a code that describe the problem (I am using MsTests) :
Link for sources : http://www.fileserve.com/file/9MFQj6v/JustMockTestProject1.rar
After migrating from 2010 Q1 to 2011 Q2, I am facing an issue with Mock.Create<T>() :
I Have a default constructor which is declared after an overloaded constructor (in which i have checks for invalid values).
When I use Mock.Create<T>(), the first constructor is called (not the default one). Thus, I Get an exception from my checks that I didn't have before. Instead I Want Mock.Create<T>() use my default constructor for mocking my type.
Here is a code that describe the problem (I am using MsTests) :
public class ClassToMock { public int Member { get; set; } public ClassToMock(int member) { // Performs some checks if (member <= 0) throw new ArgumentException("Member must be positive"); Member = member; } public ClassToMock() { } } public class ClassToMock2 { public int Member { get; set; } public ClassToMock2() { } public ClassToMock2(int member) { // Performs some checks if (member <= 0) throw new ArgumentException("Member must be positive"); Member = member; } }[TestMethod] public void TestMethod1() { var classToMock = Mock.Create<ClassToMock>(); => Throws ArgumentException Assert.IsNotNull(classToMock); } [TestMethod] public void TestMethod2() { var classToMock2 = Mock.Create<ClassToMock2>(); Assert.IsNotNull(classToMock2); }Thanks for your help.
Link for sources : http://www.fileserve.com/file/9MFQj6v/JustMockTestProject1.rar