File tree Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Expand file tree Collapse file tree 4 files changed +35
-1
lines changed Original file line number Diff line number Diff line change
1
+ namespace NTestDataBuilder . Tests . Entities
2
+ {
3
+ public class Company
4
+ {
5
+ protected Company ( ) { }
6
+
7
+ public Company ( string name , int employeeCount )
8
+ {
9
+ Name = name ;
10
+ EmployeeCount = employeeCount ;
11
+ }
12
+
13
+ public virtual string Name { get ; private set ; }
14
+ public int EmployeeCount { get ; private set ; }
15
+ }
16
+ }
Original file line number Diff line number Diff line change 54
54
<Compile Include =" Builders\ProxyAlteringCustomerBuilder.cs" />
55
55
<Compile Include =" BuildTests.cs" />
56
56
<Compile Include =" CreateListTests.cs" />
57
+ <Compile Include =" Entities\Company.cs" />
57
58
<Compile Include =" Entities\Customer.cs" />
58
59
<Compile Include =" GetOrDefaultTests.cs" />
59
60
<Compile Include =" GetSetTests.cs" />
Original file line number Diff line number Diff line change @@ -59,5 +59,21 @@ public void GivenClassToProxyWithMultiplePropertyValues_WhenBuildingProxy_Return
59
59
Assert . That ( proxy . LastName , Is . EqualTo ( "LastName" ) ) ;
60
60
Assert . That ( proxy . YearJoined , Is . EqualTo ( 1 ) ) ;
61
61
}
62
+
63
+ [ Test ]
64
+ public void GivenClassWithSomeVirtualProperties_WhenBuildingProxy_ThenOnlyVirtualMembersAreProxied ( )
65
+ {
66
+ var proxyBuilder = new ProxyBuilder < Company > ( new Dictionary < string , object > ( )
67
+ {
68
+ { "Name" , "Vandelay Industries" } ,
69
+ { "EmployeeCount" , 100 }
70
+ } ) ;
71
+
72
+ var proxy = proxyBuilder . Build ( ) ;
73
+
74
+ Assert . That ( proxy . Name , Is . EqualTo ( "Vandelay Industries" ) ) ;
75
+ Assert . That ( proxy . EmployeeCount , Is . EqualTo ( 0 ) ) ;
76
+ }
62
77
}
63
78
}
79
+
Original file line number Diff line number Diff line change @@ -32,7 +32,8 @@ public T Build()
32
32
var properties = typeof ( T ) . GetProperties ( BindingFlags . Public | BindingFlags . Instance ) ;
33
33
foreach ( var property in properties . Where ( property => _properties . ContainsKey ( property . Name ) ) )
34
34
{
35
- property . GetValue ( proxy , null ) . Returns ( _properties [ property . Name ] ) ;
35
+ if ( property . GetGetMethod ( ) . IsVirtual )
36
+ property . GetValue ( proxy , null ) . Returns ( _properties [ property . Name ] ) ;
36
37
}
37
38
38
39
return proxy ;
You can’t perform that action at this time.
0 commit comments