That is because the way C# behaves in this situation, you need to use
new[]{null} insteadOn Tue, Jul 21, 2009 at 1:50 AM, Alexey Diyan <[email protected]>wrote: > > Hi, > > I am using Rhino.Mocks 3.5, assembly version is 3.5.0.1337. > Try to mock class with constructor which has one parameter. > When I pass one null-value into method MockRepository.GenerateMock<T> > (params object[]) I have got following exception: > "MissingMethodException: Can't find a constructor with matching > arguments" > > When I cast this null-value to actual type everything works fine. > When I pass two or more null-values (without any type casting) > everything works fine. > > > > You can cut and paste unit tests below: > > public class CtorWithOneParam > { > private string _first; > > public CtorWithOneParam(string first) > { > _first = first; > } > > public virtual string FooMethod() > { > return _first; > } > } > > public class CtorWithTwoParams > { > private string _first; > private string _second; > > public CtorWithTwoParams(string first, string second) > { > _first = first; > _second = second; > } > > public virtual string FooMethod() > { > return _first + _second; > } > } > > public class CtorWithThreeParams > { > private string _first; > private string _second; > private string _third; > > public CtorWithThreeParams(string first, string second, string > third) > { > _first = first; > _second = second; > _third = third; > } > > public virtual string FooMethod() > { > return _first + _second + _third; > } > } > > [TestFixture] > public class TestClassMocking > { > [Test] > public void TestCtorWithOneParamWhichEqualsToNull() // Failed > test > { > var result = > MockRepository.GenerateMock<CtorWithOneParam>(null); > Assert.IsNotNull(result); > } > > [Test] > public void TestCtorWithOneParamWhichHasKnownTypeEqualsToNull() > { > var result = > MockRepository.GenerateMock<CtorWithOneParam>((string) > null); > Assert.IsNotNull(result); > } > > [Test] > public void TestCtorWithOneParamWhichHasKnownType() > { > var result = > MockRepository.GenerateMock<CtorWithOneParam> > (string.Empty); > Assert.IsNotNull(result); > } > > [Test] > public void TestCtorWithTwoParams() > { > var result = > MockRepository.GenerateMock<CtorWithTwoParams>(null, > null); > Assert.IsNotNull(result); > } > > [Test] > public void TestCtorWithThreeParams() > { > var result = > MockRepository.GenerateMock<CtorWithThreeParams>(null, > null, null); > Assert.IsNotNull(result); > } > } > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/RhinoMocks?hl=en -~----------~----~----~----~------~----~------~--~---
