@@ -109,4 +109,63 @@ public async Task GetOrAdd_ShouldAddValueToDictionary_WhenKeyDoesNotExist_Overlo
109109 await Assert . That ( dictionary . ContainsKey ( "key1" ) ) . IsTrue ( ) ;
110110 await Assert . That ( dictionary [ "key1" ] ) . IsEqualTo ( "value10" ) ;
111111 }
112+
113+ // ReSharper disable once UnusedParameter.Local
114+ // ReSharper disable once ConvertToLocalFunction
115+ [ Test ]
116+ public async Task AddOrUpdate_ShouldAddValueToDictionary_WhenKeyDoesNotExist_OverloadFactory ( ) {
117+ // Arrange
118+ var dictionary = new Dictionary < string , string > ( ) ;
119+ const string value = "value" ;
120+ Func < string , string > valueFactory = key => value ;
121+
122+ // Act
123+ dictionary . AddOrUpdate ( "key1" , valueFactory ) ;
124+
125+ // Assert
126+ await Assert . That ( dictionary . ContainsKey ( "key1" ) ) . IsTrue ( ) ;
127+ await Assert . That ( dictionary [ "key1" ] ) . IsEqualTo ( value ) ;
128+ }
129+
130+ // ReSharper disable once UnusedParameter.Local
131+ // ReSharper disable once ConvertToLocalFunction
132+ [ Test ]
133+ public async Task AddOrUpdate_ShouldAddValueToDictionary_WhenKeyDoesExist_OverloadFactory ( ) {
134+ // Arrange
135+ var dictionary = new Dictionary < string , string > { [ "key1" ] = "oldValue" } ;
136+
137+ const string value = "value" ;
138+ Func < string , string > valueFactory = key => $ "{ value } ";
139+
140+ // Act
141+ dictionary . AddOrUpdate ( "key1" , valueFactory ) ;
142+
143+ // Assert
144+ await Assert . That ( dictionary ) . ContainsKey ( "key1" ) ;
145+ await Assert . That ( dictionary [ "key1" ] )
146+ . IsNotEqualTo ( "oldValue" )
147+ . IsEqualTo ( "value" ) ;
148+ }
149+
150+ // ReSharper disable once UnusedParameter.Local
151+ // ReSharper disable once ConvertToLocalFunction
152+ [ Test ]
153+ public async Task AddOrUpdate_ShouldAddValueToDictionary_WhenKeyDoesNotExist_OverloadFactoryAddAndUpdate ( ) {
154+ // Arrange
155+ var dictionary = new Dictionary < string , string > { [ "key1" ] = "oldValue" } ;
156+ const string value = "value" ;
157+ Func < string , string > onAddFactory = key => value ;
158+ Func < string , string , string > onUpdateFactory = ( _ , oldValue ) => $ "{ oldValue } ;{ value } ";
159+
160+ // Act
161+ dictionary . AddOrUpdate ( "key1" , onAddFactory , onUpdateFactory ) ;
162+ dictionary . AddOrUpdate ( "key2" , onAddFactory , onUpdateFactory ) ;
163+
164+ // Assert
165+ await Assert . That ( dictionary ) . ContainsKey ( "key1" ) ;
166+ await Assert . That ( dictionary [ "key1" ] ) . IsEqualTo ( "oldValue;value" ) ;
167+
168+ await Assert . That ( dictionary ) . ContainsKey ( "key2" ) ;
169+ await Assert . That ( dictionary [ "key2" ] ) . IsEqualTo ( value ) ;
170+ }
112171}
0 commit comments