@@ -250,4 +250,80 @@ public void TempData_Loads_WhenLoaded()
250250 Assert . True ( tempData . WasLoaded ) ;
251251 Assert . Equal ( "Value" , value ) ;
252252 }
253+
254+ [ Fact ]
255+ public void Get_ConsumesValue_WhenFirstAccessTriggersLazyLoad ( )
256+ {
257+ var tempData = new TempData ( ( ) => new Dictionary < string , object >
258+ {
259+ [ "Message" ] = "hello"
260+ } ) ;
261+
262+ var value = tempData . Get ( "Message" ) ;
263+ var saved = tempData . Save ( ) ;
264+
265+ Assert . Equal ( "hello" , value ) ;
266+ Assert . Empty ( saved ) ;
267+ }
268+
269+ [ Fact ]
270+ public void Indexer_ConsumesValue_WhenFirstAccessTriggersLazyLoad ( )
271+ {
272+ var tempData = new TempData ( ( ) => new Dictionary < string , object >
273+ {
274+ [ "Message" ] = "hello"
275+ } ) ;
276+
277+ var value = tempData [ "Message" ] ;
278+ var saved = tempData . Save ( ) ;
279+
280+ Assert . Equal ( "hello" , value ) ;
281+ Assert . Empty ( saved ) ;
282+ }
283+
284+ [ Fact ]
285+ public void Remove_RemovesValue_WhenFirstAccessTriggersLazyLoad ( )
286+ {
287+ var tempData = new TempData ( ( ) => new Dictionary < string , object >
288+ {
289+ [ "Message" ] = "hello"
290+ } ) ;
291+
292+ var result = tempData . Remove ( "Message" ) ;
293+ var saved = tempData . Save ( ) ;
294+
295+ Assert . True ( result ) ;
296+ Assert . Empty ( saved ) ;
297+ }
298+
299+ [ Fact ]
300+ public void Keep_RetainsAllKeys_WhenFirstAccessTriggersLazyLoad ( )
301+ {
302+ var tempData = new TempData ( ( ) => new Dictionary < string , object >
303+ {
304+ [ "Key1" ] = "Value1" ,
305+ [ "Key2" ] = "Value2"
306+ } ) ;
307+
308+ tempData . Keep ( ) ;
309+ var saved = tempData . Save ( ) ;
310+
311+ Assert . Equal ( 2 , saved . Count ) ;
312+ Assert . Equal ( "Value1" , saved [ "Key1" ] ) ;
313+ Assert . Equal ( "Value2" , saved [ "Key2" ] ) ;
314+ }
315+
316+ [ Fact ]
317+ public void Enumerator_IteratesAllKeys_WhenFirstAccessTriggersLazyLoad ( )
318+ {
319+ var tempData = new TempData ( ( ) => new Dictionary < string , object >
320+ {
321+ [ "Key1" ] = "Value1" ,
322+ [ "Key2" ] = "Value2"
323+ } ) ;
324+
325+ var items = ( ( IEnumerable < KeyValuePair < string , object > > ) tempData ) . ToList ( ) ;
326+
327+ Assert . Equal ( 2 , items . Count ) ;
328+ }
253329}
0 commit comments