1
+ using NUnit . Framework ;
2
+
3
+ namespace Rocks . IntegrationTests ;
4
+
5
+ public interface IService < T , TReturn >
6
+ {
7
+ TReturn Service ( T data ) ;
8
+ }
9
+
10
+ public static class OpenGenericsTests
11
+ {
12
+ [ Test ]
13
+ [ RockCreate ( typeof ( IService < , > ) ) ]
14
+ public static void CreateWithIntAndString ( )
15
+ {
16
+ var intStringExpectations = new IServiceCreateExpectations < int , string > ( ) ;
17
+ intStringExpectations . Methods . Service ( 3 ) . ReturnValue ( "three" ) ;
18
+
19
+ var intStringMock = intStringExpectations . Instance ( ) ;
20
+ Assert . That ( intStringMock . Service ( 3 ) , Is . EqualTo ( "three" ) ) ;
21
+ intStringExpectations . Verify ( ) ;
22
+ }
23
+
24
+ [ Test ]
25
+ [ RockCreate ( typeof ( IService < , > ) ) ]
26
+ public static void CreateWithStringAndInt ( )
27
+ {
28
+ var stringIntExpectations = new IServiceCreateExpectations < string , int > ( ) ;
29
+ stringIntExpectations . Methods . Service ( "four" ) . ReturnValue ( 4 ) ;
30
+
31
+ var stringIntMock = stringIntExpectations . Instance ( ) ;
32
+ Assert . That ( stringIntMock . Service ( "four" ) , Is . EqualTo ( 4 ) ) ;
33
+ stringIntExpectations . Verify ( ) ;
34
+ }
35
+
36
+ [ Test ]
37
+ [ RockMake ( typeof ( IService < , > ) ) ]
38
+ public static void MakeWithIntAndString ( )
39
+ {
40
+ var intStringMake = new IServiceMakeExpectations < int , string > ( ) . Instance ( ) ;
41
+ Assert . That ( intStringMake . Service ( 3 ) , Is . Null ) ;
42
+ }
43
+
44
+ [ Test ]
45
+ [ RockMake ( typeof ( IService < , > ) ) ]
46
+ public static void MakeWithStringAndInt ( )
47
+ {
48
+ var intStringMake = new IServiceMakeExpectations < string , int > ( ) . Instance ( ) ;
49
+ Assert . That ( intStringMake . Service ( "four" ) , Is . EqualTo ( 0 ) ) ;
50
+ }
51
+ }
0 commit comments