@@ -9,6 +9,24 @@ namespace SharpRepository.Tests.Integration.Spikes
99 [ TestFixture ]
1010 public class ConventionSpikes
1111 {
12+ [ Test ]
13+ public void Changed_Default_Suffix_To_Key_Should_Work ( )
14+ {
15+ var origSuffix = DefaultRepositoryConventions . PrimaryKeySuffix ;
16+
17+ DefaultRepositoryConventions . PrimaryKeySuffix = "Key" ;
18+ var repository = new InMemoryRepository < ConventionTestItem1 > ( ) ;
19+
20+ var item = new ConventionTestItem1 ( ) { Name = "Test1" } ;
21+ repository . Add ( item ) ;
22+
23+ // The PK should have been found and updated so it's not zero anymore
24+ item . ConventionTestItem1Key . ShouldNotEqual ( 0 ) ;
25+
26+ // reset convention to the default orig for the rest of the tests
27+ DefaultRepositoryConventions . PrimaryKeySuffix = origSuffix ;
28+ }
29+
1230 [ Test ]
1331 public void Changed_Convention_To_Key_Should_Work ( )
1432 {
@@ -17,10 +35,11 @@ public void Changed_Convention_To_Key_Should_Work()
1735 DefaultRepositoryConventions . GetPrimaryKeyName = type => type . Name + "Key" ;
1836 var repository = new InMemoryRepository < ConventionTestItem1 > ( ) ;
1937
20- var testItem1 = new ConventionTestItem1 ( ) { Name = "Test1" } ;
21- repository . Add ( testItem1 ) ;
38+ var item = new ConventionTestItem1 ( ) { Name = "Test1" } ;
39+ repository . Add ( item ) ;
2240
23- testItem1 . ConventionTestItem1Key . ShouldNotEqual ( 0 ) ;
41+ // The PK should have been found and updated so it's not zero anymore
42+ item . ConventionTestItem1Key . ShouldNotEqual ( 0 ) ;
2443
2544 // reset convention to the default orig for the rest of the tests
2645 DefaultRepositoryConventions . GetPrimaryKeyName = origConvention ;
@@ -32,10 +51,11 @@ public void Changed_Convention_To_Key_Should_Work_Just_Key_Property()
3251 var repository = new InMemoryRepository < ConventionTestItem2 > ( ) ;
3352 repository . Conventions . GetPrimaryKeyName = _ => "Key" ;
3453
35- var testItem1 = new ConventionTestItem2 ( ) { Name = "Test1" } ;
36- repository . Add ( testItem1 ) ;
54+ var item = new ConventionTestItem2 ( ) { Name = "Test1" } ;
55+ repository . Add ( item ) ;
3756
38- testItem1 . Key . ShouldNotEqual ( 0 ) ;
57+ // The PK should have been found and updated so it's not zero anymore
58+ item . Key . ShouldNotEqual ( 0 ) ;
3959 }
4060
4161 [ Test ]
@@ -44,10 +64,11 @@ public void Changed_Convention_To_SomeRandomPrimaryKeyProperty_Should_Work()
4464 var repository = new InMemoryRepository < ConventionTestItem3 > ( ) ;
4565 repository . Conventions . GetPrimaryKeyName = _ => "SomeRandomPrimaryKeyProperty" ;
4666
47- var testItem1 = new ConventionTestItem3 ( ) { Name = "Test1" } ;
48- repository . Add ( testItem1 ) ;
67+ var item = new ConventionTestItem3 ( ) { Name = "Test1" } ;
68+ repository . Add ( item ) ;
4969
50- testItem1 . SomeRandomPrimaryKeyProperty . ShouldNotEqual ( 0 ) ;
70+ // The PK should have been found and updated so it's not zero anymore
71+ item . SomeRandomPrimaryKeyProperty . ShouldNotEqual ( 0 ) ;
5172 }
5273 }
5374}
0 commit comments