1+ using System ;
2+ using CoreHelpers . WindowsAzure . Storage . Table . Attributes ;
3+ using CoreHelpers . WindowsAzure . Storage . Table . Serialization ;
4+ using CoreHelpers . WindowsAzure . Storage . Table . Tests . Extensions ;
5+ using CoreHelpers . WindowsAzure . Storage . Table . Tests . Models ;
6+
7+ namespace CoreHelpers . WindowsAzure . Storage . Table . Tests
8+ {
9+ [ Storable ( Tablename = "VirtualRowKeyNone" ) ]
10+ [ VirtualRowKey ( "{{RK}}" ) ]
11+ public class VirtualRowKeyNone
12+ {
13+ [ PartitionKey ]
14+ public string PK { get ; set ; } = String . Empty ;
15+
16+ public string RK { get ; set ; } = String . Empty ;
17+ }
18+
19+ [ Storable ( Tablename = "VirtualRowKeyNone" ) ]
20+ [ VirtualRowKey ( "{{RK}}-{{RK2}}" ) ]
21+ public class VirtualRowKeyCombinedNone : VirtualRowKeyNone
22+ {
23+ public string RK2 { get ; set ; } = String . Empty ;
24+ }
25+
26+ [ Storable ( Tablename = "VirtualRowKeyNone" ) ]
27+ [ VirtualRowKey ( "{{RK}}" , nVirtualValueEncoding . Base64 ) ]
28+ public class VirtualRowKeyBase64 : VirtualRowKeyNone
29+ { }
30+
31+ [ Storable ( Tablename = "VirtualRowKeyNone" ) ]
32+ [ VirtualRowKey ( "{{RK}}" , nVirtualValueEncoding . Sha256 ) ]
33+ public class VirtualRowKeySha256 : VirtualRowKeyNone
34+ { }
35+
36+ public class ITS24VirtualRowKey
37+ {
38+ private readonly IStorageContext _rootContext ;
39+
40+ public ITS24VirtualRowKey ( IStorageContext context )
41+ {
42+ _rootContext = context ;
43+ }
44+
45+ [ Fact ]
46+ public void VerifyVirtualRowKeyNoneEncoding ( )
47+ {
48+ using ( var scp = _rootContext . CreateChildContext ( ) )
49+ {
50+ // set the tablename context
51+ scp . SetTableContext ( ) ;
52+
53+ // configure the entity mapper
54+ scp . AddAttributeMapper < VirtualRowKeyNone > ( ) ;
55+
56+ // check the entity
57+ var entity = TableEntityDynamic . ToEntity < VirtualRowKeyNone > ( new VirtualRowKeyNone ( ) { PK = "P01" , RK = "R01" } , scp ) ;
58+ Assert . Equal ( "R01" , entity . RowKey ) ;
59+ }
60+ }
61+
62+ [ Fact ]
63+ public void VerifyVirtualRowKeyNoneEncodingCombined ( )
64+ {
65+ using ( var scp = _rootContext . CreateChildContext ( ) )
66+ {
67+ // set the tablename context
68+ scp . SetTableContext ( ) ;
69+
70+ // configure the entity mapper
71+ scp . AddAttributeMapper < VirtualRowKeyCombinedNone > ( ) ;
72+
73+ // check the entity
74+ var entity = TableEntityDynamic . ToEntity < VirtualRowKeyCombinedNone > ( new VirtualRowKeyCombinedNone ( ) { PK = "P01" , RK = "R01" , RK2 = "CMB" } , scp ) ;
75+ Assert . Equal ( "R01-CMB" , entity . RowKey ) ;
76+ }
77+ }
78+
79+ [ Fact ]
80+ public void VerifyVirtualRowKeyBase64Encoding ( )
81+ {
82+ using ( var scp = _rootContext . CreateChildContext ( ) )
83+ {
84+ // set the tablename context
85+ scp . SetTableContext ( ) ;
86+
87+ // configure the entity mapper
88+ scp . AddAttributeMapper < VirtualRowKeyBase64 > ( ) ;
89+
90+ // check the entity
91+ var entity = TableEntityDynamic . ToEntity < VirtualRowKeyBase64 > ( new VirtualRowKeyBase64 ( ) { PK = "P01" , RK = "R01" } , scp ) ;
92+ Assert . Equal ( "UjAx" , entity . RowKey ) ;
93+ }
94+ }
95+
96+ [ Fact ]
97+ public void VerifyVirtualRowKeySha256Encoding ( )
98+ {
99+ using ( var scp = _rootContext . CreateChildContext ( ) )
100+ {
101+ // set the tablename context
102+ scp . SetTableContext ( ) ;
103+
104+ // configure the entity mapper
105+ scp . AddAttributeMapper < VirtualRowKeySha256 > ( ) ;
106+
107+ // check the entity
108+ var entity = TableEntityDynamic . ToEntity < VirtualRowKeySha256 > ( new VirtualRowKeySha256 ( ) { PK = "P01" , RK = "R01" } , scp ) ;
109+ Assert . Equal ( "e0a64b0b6d837fa4edc328ab9ddea0e3e7e0e4f715304c1d6bf3d0adc9d5292a" , entity . RowKey ) ;
110+ }
111+ }
112+ }
113+ }
0 commit comments