@@ -29,21 +29,40 @@ protected string[] InheritedArrayInput2
2929
3030 public class ExpressionExtensionsTests : BaseClass
3131 {
32+ private class ContainerType
33+ {
34+ public int Target { get ; set ; }
35+
36+ public string Target2 { get ; set ; }
37+
38+ public ContainerType SubContainer { get ; set ; }
39+
40+ public override string ToString ( )
41+ {
42+ return Target2 ;
43+ }
44+ }
45+
3246 class ClassUnderTest
3347 {
3448 public void MethodWithoutArguments ( )
3549 {
36-
50+
3751 }
3852
3953 public void MethodWithInputs ( int input1 , string input2 )
4054 {
41-
55+
4256 }
4357
4458 public void MethodWithArrayInputs ( int [ ] input1 , string [ ] input2 )
4559 {
46-
60+
61+ }
62+
63+ public void MethodWithInputs ( ContainerType subContainer )
64+ {
65+
4766 }
4867 }
4968
@@ -89,18 +108,22 @@ string GetInput2(string someInput)
89108 return someInput + " Input 2" ;
90109 }
91110
111+ ContainerType container = new ContainerType ( ) ;
112+
92113 [ Test ]
93114 public void NoArguments ( )
94115 {
95116 var arguments = GetArguments ( x => x . MethodWithoutArguments ( ) , new ClassUnderTest ( ) ) ;
96117 Assert . That ( arguments . Length , Is . EqualTo ( 0 ) ) ;
97118 }
98119
99- void AssertReturnedArguments ( object [ ] arguments , object expectedArg1 , object expectedArg2 )
120+ void AssertReturnedArguments ( object [ ] arguments , params object [ ] expectedArgs )
100121 {
101- Assert . That ( arguments . Length , Is . EqualTo ( 2 ) ) ;
102- Assert . That ( arguments [ 0 ] , Is . EqualTo ( expectedArg1 ) ) ;
103- Assert . That ( arguments [ 1 ] , Is . EqualTo ( expectedArg2 ) ) ;
122+ Assert . That ( arguments . Length , Is . EqualTo ( expectedArgs . Length ) ) ;
123+ for ( int i = 0 ; i < expectedArgs . Length ; i ++ )
124+ {
125+ Assert . That ( arguments [ i ] , Is . EqualTo ( expectedArgs [ i ] ) ) ;
126+ }
104127 }
105128
106129 [ Test ]
@@ -132,14 +155,14 @@ public void InputArgumentsProvidedUsingProperty()
132155 var arguments = GetArguments ( x => x . MethodWithInputs ( Input1 , Input2 ) , new ClassUnderTest ( ) ) ;
133156 AssertReturnedArguments ( arguments , Input1 , Input2 ) ;
134157 }
135-
158+
136159 [ Test ]
137160 public void InputArgumentsProvidedUsingInheritedFields ( )
138161 {
139162 var arguments = GetArguments ( x => x . MethodWithInputs ( InheritedInput1 , InheritedInput2 ) , new ClassUnderTest ( ) ) ;
140163 AssertReturnedArguments ( arguments , InheritedInput1 , InheritedInput2 ) ;
141164 }
142-
165+
143166 [ Test ]
144167 public void InputArgumentsProvidedUsingMethodCallDoesNotThrow ( )
145168 {
@@ -150,14 +173,14 @@ public void InputArgumentsProvidedUsingMethodCallDoesNotThrow()
150173 public void ArrayInputsArgumentsProvidedInline ( )
151174 {
152175 var arguments = GetArguments ( x => x . MethodWithArrayInputs ( new [ ] { 1 , 2 } , new [ ] { "3" , "4" } ) , new ClassUnderTest ( ) ) ;
153- AssertReturnedArguments ( arguments , new [ ] { 1 , 2 } , new [ ] { "3" , "4" } ) ;
176+ AssertReturnedArguments ( arguments , new [ ] { 1 , 2 } , new [ ] { "3" , "4" } ) ;
154177 }
155178
156179 [ Test ]
157180 public void ArrayInputArgumentsProvidedUsingVariables ( )
158181 {
159- var input1 = new [ ] { 1 , 2 } ;
160- var input2 = new [ ] { "3" , "4" } ;
182+ var input1 = new [ ] { 1 , 2 } ;
183+ var input2 = new [ ] { "3" , "4" } ;
161184 var arguments = GetArguments ( x => x . MethodWithArrayInputs ( input1 , input2 ) , new ClassUnderTest ( ) ) ;
162185 AssertReturnedArguments ( arguments , input1 , input2 ) ;
163186 }
@@ -176,6 +199,33 @@ public void ArrayInputArgumentsProvidedUsingProperty()
176199 AssertReturnedArguments ( arguments , ArrayInput1 , ArrayInput2 ) ;
177200 }
178201
202+ [ Test ]
203+ public void ComplexArgument ( )
204+ {
205+ container . Target = 1 ;
206+ container . SubContainer = new ContainerType { Target2 = "Foo" } ;
207+
208+ var arguments = GetArguments ( x => x . MethodWithInputs ( container . Target , container . SubContainer . Target2 ) , new ClassUnderTest ( ) ) ;
209+ AssertReturnedArguments ( arguments , 1 , "Foo" ) ;
210+ }
211+
212+ [ Test ]
213+ public void ComplexArgument2 ( )
214+ {
215+ container . SubContainer = new ContainerType { Target2 = "Foo" } ;
216+
217+ var arguments = GetArguments ( x => x . MethodWithInputs ( container . SubContainer ) , new ClassUnderTest ( ) ) ;
218+ AssertReturnedArguments ( arguments , container . SubContainer ) ;
219+ }
220+
221+ [ Test ]
222+ public void ComplexArgumentWhenContainerIsNull ( )
223+ {
224+ ContainerType nullContainer = null ;
225+ var arguments = GetArguments ( x => x . MethodWithInputs ( nullContainer . SubContainer ) , new ClassUnderTest ( ) ) ;
226+ AssertReturnedArguments ( arguments , new object [ ] { null } ) ;
227+ }
228+
179229 [ Test ]
180230 public void ArrayInputArgumentsProvidedUsingInheritedProperty ( )
181231 {
0 commit comments