@@ -29,6 +29,14 @@ public void Constructor_should_fail_when_algorithm_is_null()
2929 exception . Should ( ) . BeOfType < ArgumentNullException > ( ) ;
3030 }
3131
32+ [ Fact ]
33+ public void Constructor_should_fail_when_contentionFactor_and_algorithm_is_not_indexed ( )
34+ {
35+ var exception = Record . Exception ( ( ) => new EncryptOptions ( algorithm : "test" , contentionFactor : 1 , keyId : Guid . NewGuid ( ) ) ) ;
36+ var e = exception . Should ( ) . BeOfType < ArgumentException > ( ) . Subject ;
37+ e . Message . Should ( ) . Be ( "ContentionFactor only applies for Indexed algorithm." ) ;
38+ }
39+
3240 [ Fact ]
3341 public void Constructor_should_fail_when_keyId_and_alternateKeyName_are_both_empty ( )
3442 {
@@ -45,6 +53,14 @@ public void Constructor_should_fail_when_keyId_and_alternateKeyName_are_both_spe
4553 e . Message . Should ( ) . Be ( "Key Id and AlternateKeyName may not both be set." ) ;
4654 }
4755
56+ [ Fact ]
57+ public void Constructor_should_fail_when_queryType_and_algorithm_is_not_indexed ( )
58+ {
59+ var exception = Record . Exception ( ( ) => new EncryptOptions ( algorithm : "test" , queryType : QueryType . Equality , keyId : Guid . NewGuid ( ) ) ) ;
60+ var e = exception . Should ( ) . BeOfType < ArgumentException > ( ) . Subject ;
61+ e . Message . Should ( ) . Be ( "QueryType only applies for Indexed algorithm." ) ;
62+ }
63+
4864 [ Theory ]
4965 [ InlineData ( EncryptionAlgorithm . AEAD_AES_256_CBC_HMAC_SHA_512_Deterministic , "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" ) ]
5066 [ InlineData ( EncryptionAlgorithm . AEAD_AES_256_CBC_HMAC_SHA_512_Random , "AEAD_AES_256_CBC_HMAC_SHA_512-Random" ) ]
@@ -59,6 +75,10 @@ public void Constructor_should_fail_when_keyId_and_alternateKeyName_are_both_spe
5975 [ InlineData ( "TEST_random" , "TEST_random" ) ]
6076 // just a random value in enum form
6177 [ InlineData ( ( EncryptionAlgorithm ) 99 , "99" ) ]
78+ [ InlineData ( EncryptionAlgorithm . Indexed , "Indexed" ) ]
79+ [ InlineData ( "Indexed" , "Indexed" ) ]
80+ [ InlineData ( EncryptionAlgorithm . Unindexed , "Unindexed" ) ]
81+ [ InlineData ( "Unindexed" , "Unindexed" ) ]
6282 public void Constructor_should_support_different_algorithm_representations ( object algorithm , string expectedAlgorithmRepresentation )
6383 {
6484 var alternateKeyName = "test" ;
@@ -81,44 +101,60 @@ public void Constructor_should_support_different_algorithm_representations(objec
81101 [ Fact ]
82102 public void With_should_set_correct_values ( )
83103 {
84- var originalAlgorithm = "originalAlgorithm" ;
104+ var originalAlgorithm = EncryptionAlgorithm . Indexed . ToString ( ) ;
85105 var newAlgorithm = "newAlgorithm" ;
86106 var originalKeyId = Guid . Empty ;
87107 var newKeyId = Guid . NewGuid ( ) ;
88108 var originalAlternateKeyName = "test" ;
89109 var newAlternateKeyName = "new" ;
110+ long ? originalContention = null ;
111+ var newContention = 2 ;
112+ QueryType ? originalQueryType = null ;
113+ var newQueryType = QueryType . Equality ;
90114
91- var subject = CreateConfiguredSubject ( withKeyId : true ) ;
92- AssertValues ( subject , originalAlgorithm , originalKeyId , null ) ;
115+ var fle1WithKeyIdState = 0 ;
116+ var subject = CreateConfiguredSubject ( state : fle1WithKeyIdState ) ;
117+ AssertValues ( subject , originalAlgorithm , expectedKeyId : originalKeyId ) ;
93118
94119 subject = subject . With ( algorithm : newAlgorithm ) ;
95- AssertValues ( subject , newAlgorithm , originalKeyId , null ) ;
120+ AssertValues ( subject , newAlgorithm , expectedKeyId : originalKeyId ) ;
96121
97122 subject = subject . With ( keyId : newKeyId ) ;
98- AssertValues ( subject , newAlgorithm , newKeyId , null ) ;
123+ AssertValues ( subject , newAlgorithm , expectedKeyId : newKeyId ) ;
99124
100- subject = CreateConfiguredSubject ( withKeyId : false ) ;
101- AssertValues ( subject , originalAlgorithm , null , originalAlternateKeyName ) ;
125+ var fle1WithAlternateKeyNameState = 1 ;
126+ subject = CreateConfiguredSubject ( state : fle1WithAlternateKeyNameState ) ;
127+ AssertValues ( subject , originalAlgorithm , expectedAlternateKeyName : originalAlternateKeyName ) ;
102128
103129 subject = subject . With ( alternateKeyName : newAlternateKeyName ) ;
104- AssertValues ( subject , originalAlgorithm , null , newAlternateKeyName ) ;
130+ AssertValues ( subject , originalAlgorithm , expectedAlternateKeyName : newAlternateKeyName ) ;
131+
132+ var fle2State = 2 ;
133+ subject = CreateConfiguredSubject ( state : fle2State ) ;
134+ subject = subject . With ( contentionFactor : newContention ) ;
135+ AssertValues ( subject , EncryptionAlgorithm . Indexed . ToString ( ) , expectedKeyId : originalKeyId , expectedContentionFactor : newContention ) ;
105136
106- static void AssertValues ( EncryptOptions subject , string algorithm , Guid ? keyId , string alternateKeyName )
137+ subject = CreateConfiguredSubject ( state : fle2State ) ;
138+ subject = subject . With ( queryType : newQueryType ) ;
139+ AssertValues ( subject , EncryptionAlgorithm . Indexed . ToString ( ) , expectedKeyId : originalKeyId , expectedQueryType : newQueryType ) ;
140+
141+ static void AssertValues ( EncryptOptions subject , string expectedAlgorithm , Guid ? expectedKeyId = null , string expectedAlternateKeyName = null , QueryType ? expectedQueryType = null , long ? expectedContentionFactor = null )
107142 {
108- subject . Algorithm . Should ( ) . Be ( algorithm ) ;
109- subject . KeyId . Should ( ) . Be ( keyId ) ;
110- subject . AlternateKeyName . Should ( ) . Be ( alternateKeyName ) ;
143+ subject . Algorithm . Should ( ) . Be ( expectedAlgorithm ) ;
144+ subject . KeyId . Should ( ) . Be ( expectedKeyId ) ;
145+ subject . AlternateKeyName . Should ( ) . Be ( expectedAlternateKeyName ) ;
146+ subject . QueryType . Should ( ) . Be ( expectedQueryType ) ;
147+ subject . ContentionFactor . Should ( ) . Be ( expectedContentionFactor ) ;
111148 }
112149
113- EncryptOptions CreateConfiguredSubject ( bool withKeyId )
150+ EncryptOptions CreateConfiguredSubject ( int state )
114151 {
115- if ( withKeyId )
116- {
117- return new EncryptOptions ( algorithm : originalAlgorithm , keyId : originalKeyId ) ;
118- }
119- else
152+ switch ( state )
120153 {
121- return new EncryptOptions ( algorithm : originalAlgorithm , alternateKeyName : originalAlternateKeyName ) ;
154+ case 0 : return new EncryptOptions ( algorithm : originalAlgorithm , keyId : originalKeyId ) ;
155+ case 1 : return new EncryptOptions ( algorithm : originalAlgorithm , alternateKeyName : originalAlternateKeyName ) ;
156+ case 2 : return new EncryptOptions ( algorithm : originalAlgorithm , keyId : originalKeyId , contentionFactor : originalContention , queryType : originalQueryType ) ;
157+ default : throw new Exception ( $ "Unexpected state: { state } .") ;
122158 }
123159 }
124160 }
0 commit comments