@@ -111,4 +111,54 @@ public void MemberData_DifferentInterface_NotPromoted(
111111 {
112112 yield return [ new DualInterfaceImpl { Name = "n" , Description = "d" } ] ;
113113 }
114+
115+ [ Theory ]
116+ [ AutoNSubstituteData ]
117+ public void Multiple_Frozen_Same_Type_Should_Reference_Same_Instance (
118+ [ Frozen ] ISampleInterface first ,
119+ [ Frozen ] ISampleInterface second ,
120+ SampleDependantClass dependant )
121+ {
122+ first . Should ( ) . NotBeNull ( ) ;
123+ second . Should ( ) . NotBeNull ( ) ;
124+ first . Should ( ) . BeSameAs ( second ) ;
125+ dependant . Dependency . Should ( ) . BeSameAs ( first ) ;
126+ }
127+
128+ [ Theory ]
129+ [ MemberAutoNSubstituteData ( nameof ( DataSingleProvidedInterface ) ) ]
130+ public void Earlier_Single_Supplied_Value_Reused_For_Multiple_Later_Frozens (
131+ ISampleInterface supplied ,
132+ [ Frozen ] ISampleInterface frozen1 ,
133+ [ Frozen ] ISampleInterface frozen2 ,
134+ SampleDependantClass dependant )
135+ {
136+ supplied . Should ( ) . NotBeNull ( ) ;
137+ frozen1 . Should ( ) . BeSameAs ( supplied ) ;
138+ frozen2 . Should ( ) . BeSameAs ( supplied ) ;
139+ dependant . Dependency . Should ( ) . BeSameAs ( supplied ) ;
140+ }
141+
142+ public static IEnumerable < object ? [ ] > DataSingleProvidedInterface ( )
143+ {
144+ yield return [ Substitute . For < ISampleInterface > ( ) ] ;
145+ }
146+
147+ [ Theory ]
148+ [ MemberAutoNSubstituteData ( nameof ( DataMultipleSameTypeProvided ) ) ]
149+ public void Promotion_Uses_Earliest_Supplied_Instance (
150+ ISampleInterface firstProvided ,
151+ ISampleInterface secondProvided ,
152+ [ Frozen ] ISampleInterface frozen ,
153+ SampleDependantClass dependant )
154+ {
155+ firstProvided . Should ( ) . NotBeSameAs ( secondProvided ) ; // separate substitutes
156+ frozen . Should ( ) . BeSameAs ( firstProvided ) ; // earliest should win
157+ dependant . Dependency . Should ( ) . BeSameAs ( firstProvided ) ;
158+ }
159+
160+ public static IEnumerable < object ? [ ] > DataMultipleSameTypeProvided ( )
161+ {
162+ yield return [ Substitute . For < ISampleInterface > ( ) , Substitute . For < ISampleInterface > ( ) ] ;
163+ }
114164}
0 commit comments