@@ -11,27 +11,15 @@ public class RuntimeOptionsUpdateBuilderTests
1111{
1212 private static RuntimeCacheOptions BaseOptions ( ) => new ( 1.0 , 2.0 , 0.1 , 0.2 , TimeSpan . FromMilliseconds ( 50 ) ) ;
1313
14- // Helper to create an internal builder via WindowCache (public API) isn't needed here
15- // because we can test ApplyTo directly via internal access.
16- // However, RuntimeOptionsUpdateBuilder's ctor is internal, so we access it via WindowCache.
17- // Instead we test the builder indirectly through WindowCache.UpdateRuntimeOptions.
18- // For pure unit tests of the builder logic, we use InternalsVisibleTo.
19-
20- // Since RuntimeOptionsUpdateBuilder constructor is internal but the tests are in a separate
21- // assembly, we verify builder behaviour through ApplyTo by instantiating via reflection,
22- // or test the full behaviour through WindowCache integration tests.
23- // Here we use the WindowCache public API to exercise each builder method.
24-
2514 #region Builder Method Tests — WithLeftCacheSize
2615
2716 [ Fact ]
2817 public void ApplyTo_WithLeftCacheSizeSet_ChangesOnlyLeftCacheSize ( )
2918 {
30- // We test ApplyTo indirectly: create builder through internal constructor via reflection.
31- var builder = CreateBuilder ( ) ;
19+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
3220 builder . WithLeftCacheSize ( 5.0 ) ;
3321
34- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
22+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
3523
3624 Assert . Equal ( 5.0 , result . LeftCacheSize ) ;
3725 Assert . Equal ( 2.0 , result . RightCacheSize ) ; // unchanged
@@ -47,10 +35,10 @@ public void ApplyTo_WithLeftCacheSizeSet_ChangesOnlyLeftCacheSize()
4735 [ Fact ]
4836 public void ApplyTo_WithRightCacheSizeSet_ChangesOnlyRightCacheSize ( )
4937 {
50- var builder = CreateBuilder ( ) ;
38+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
5139 builder . WithRightCacheSize ( 7.0 ) ;
5240
53- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
41+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
5442
5543 Assert . Equal ( 1.0 , result . LeftCacheSize ) ; // unchanged
5644 Assert . Equal ( 7.0 , result . RightCacheSize ) ;
@@ -66,10 +54,10 @@ public void ApplyTo_WithRightCacheSizeSet_ChangesOnlyRightCacheSize()
6654 [ Fact ]
6755 public void ApplyTo_WithLeftThresholdSet_UpdatesLeftThreshold ( )
6856 {
69- var builder = CreateBuilder ( ) ;
57+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
7058 builder . WithLeftThreshold ( 0.3 ) ;
7159
72- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
60+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
7361
7462 Assert . Equal ( 0.3 , result . LeftThreshold ) ;
7563 Assert . Equal ( 0.2 , result . RightThreshold ) ; // unchanged
@@ -78,10 +66,10 @@ public void ApplyTo_WithLeftThresholdSet_UpdatesLeftThreshold()
7866 [ Fact ]
7967 public void ApplyTo_ClearLeftThreshold_SetsLeftThresholdToNull ( )
8068 {
81- var builder = CreateBuilder ( ) ;
69+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
8270 builder . ClearLeftThreshold ( ) ;
8371
84- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
72+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
8573
8674 Assert . Null ( result . LeftThreshold ) ;
8775 Assert . Equal ( 0.2 , result . RightThreshold ) ; // unchanged
@@ -91,10 +79,10 @@ public void ApplyTo_ClearLeftThreshold_SetsLeftThresholdToNull()
9179 public void ApplyTo_LeftThresholdNotSet_KeepsCurrentValue ( )
9280 {
9381 // No threshold method called on builder
94- var builder = CreateBuilder ( ) ;
82+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
9583 builder . WithLeftCacheSize ( 3.0 ) ; // only set left cache size
9684
97- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
85+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
9886
9987 Assert . Equal ( 0.1 , result . LeftThreshold ) ; // unchanged from base
10088 }
@@ -106,10 +94,10 @@ public void ApplyTo_LeftThresholdNotSet_KeepsCurrentValue()
10694 [ Fact ]
10795 public void ApplyTo_WithRightThresholdSet_UpdatesRightThreshold ( )
10896 {
109- var builder = CreateBuilder ( ) ;
97+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
11098 builder . WithRightThreshold ( 0.35 ) ;
11199
112- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
100+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
113101
114102 Assert . Equal ( 0.35 , result . RightThreshold ) ;
115103 Assert . Equal ( 0.1 , result . LeftThreshold ) ; // unchanged
@@ -118,10 +106,10 @@ public void ApplyTo_WithRightThresholdSet_UpdatesRightThreshold()
118106 [ Fact ]
119107 public void ApplyTo_ClearRightThreshold_SetsRightThresholdToNull ( )
120108 {
121- var builder = CreateBuilder ( ) ;
109+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
122110 builder . ClearRightThreshold ( ) ;
123111
124- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
112+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
125113
126114 Assert . Null ( result . RightThreshold ) ;
127115 Assert . Equal ( 0.1 , result . LeftThreshold ) ; // unchanged
@@ -130,11 +118,11 @@ public void ApplyTo_ClearRightThreshold_SetsRightThresholdToNull()
130118 [ Fact ]
131119 public void ApplyTo_RightThresholdNotSet_KeepsCurrentValue ( )
132120 {
133- var builder = CreateBuilder ( ) ;
121+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
134122 // Only change debounce
135123 builder . WithDebounceDelay ( TimeSpan . Zero ) ;
136124
137- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
125+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
138126
139127 Assert . Equal ( 0.2 , result . RightThreshold ) ; // unchanged from base
140128 }
@@ -146,10 +134,10 @@ public void ApplyTo_RightThresholdNotSet_KeepsCurrentValue()
146134 [ Fact ]
147135 public void ApplyTo_WithDebounceDelaySet_ChangesOnlyDebounceDelay ( )
148136 {
149- var builder = CreateBuilder ( ) ;
137+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
150138 builder . WithDebounceDelay ( TimeSpan . FromSeconds ( 1 ) ) ;
151139
152- var result = InvokeApplyTo ( builder , BaseOptions ( ) ) ;
140+ var result = builder . ApplyTo ( BaseOptions ( ) ) ;
153141
154142 Assert . Equal ( TimeSpan . FromSeconds ( 1 ) , result . DebounceDelay ) ;
155143 Assert . Equal ( 1.0 , result . LeftCacheSize ) ; // unchanged
@@ -164,15 +152,15 @@ public void ApplyTo_WithDebounceDelaySet_ChangesOnlyDebounceDelay()
164152 public void ApplyTo_FluentChain_AppliesAllChanges ( )
165153 {
166154 var base_ = new RuntimeCacheOptions ( 1.0 , 1.0 , null , null , TimeSpan . Zero ) ;
167- var builder = CreateBuilder ( ) ;
155+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
168156 builder
169157 . WithLeftCacheSize ( 2.0 )
170158 . WithRightCacheSize ( 3.0 )
171159 . WithLeftThreshold ( 0.1 )
172160 . WithRightThreshold ( 0.15 )
173161 . WithDebounceDelay ( TimeSpan . FromMilliseconds ( 75 ) ) ;
174162
175- var result = InvokeApplyTo ( builder , base_ ) ;
163+ var result = builder . ApplyTo ( base_ ) ;
176164
177165 Assert . Equal ( 2.0 , result . LeftCacheSize ) ;
178166 Assert . Equal ( 3.0 , result . RightCacheSize ) ;
@@ -185,9 +173,9 @@ public void ApplyTo_FluentChain_AppliesAllChanges()
185173 public void ApplyTo_EmptyBuilder_ReturnsSnapshotWithAllCurrentValues ( )
186174 {
187175 var base_ = BaseOptions ( ) ;
188- var builder = CreateBuilder ( ) ;
176+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
189177
190- var result = InvokeApplyTo ( builder , base_ ) ;
178+ var result = builder . ApplyTo ( base_ ) ;
191179
192180 Assert . Equal ( base_ . LeftCacheSize , result . LeftCacheSize ) ;
193181 Assert . Equal ( base_ . RightCacheSize , result . RightCacheSize ) ;
@@ -203,10 +191,10 @@ public void ApplyTo_EmptyBuilder_ReturnsSnapshotWithAllCurrentValues()
203191 [ Fact ]
204192 public void ApplyTo_WithInvalidMergedCacheSize_ThrowsArgumentOutOfRangeException ( )
205193 {
206- var builder = CreateBuilder ( ) ;
194+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
207195 builder . WithLeftCacheSize ( - 1.0 ) ;
208196
209- var exception = Record . Exception ( ( ) => InvokeApplyTo ( builder , BaseOptions ( ) ) ) ;
197+ var exception = Record . Exception ( ( ) => builder . ApplyTo ( BaseOptions ( ) ) ) ;
210198
211199 Assert . NotNull ( exception ) ;
212200 Assert . IsType < ArgumentOutOfRangeException > ( exception ) ;
@@ -216,43 +204,28 @@ public void ApplyTo_WithInvalidMergedCacheSize_ThrowsArgumentOutOfRangeException
216204 public void ApplyTo_WithThresholdSumExceedingOne_ThrowsArgumentException ( )
217205 {
218206 // Base has leftThreshold=0.1; set right=0.95 → sum=1.05
219- var builder = CreateBuilder ( ) ;
207+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
220208 builder . WithRightThreshold ( 0.95 ) ;
221209
222- var exception = Record . Exception ( ( ) => InvokeApplyTo ( builder , BaseOptions ( ) ) ) ;
210+ var exception = Record . Exception ( ( ) => builder . ApplyTo ( BaseOptions ( ) ) ) ;
223211
224212 Assert . NotNull ( exception ) ;
225213 Assert . IsType < ArgumentException > ( exception ) ;
226214 }
227215
228- #endregion
229-
230- // Helpers — create builder via internal constructor using reflection,
231- // and invoke the internal ApplyTo method.
232- private static RuntimeOptionsUpdateBuilder CreateBuilder ( )
216+ [ Fact ]
217+ public void WithDebounceDelay_WithNegativeValue_ThrowsArgumentOutOfRangeException ( )
233218 {
234- var ctor = typeof ( RuntimeOptionsUpdateBuilder )
235- . GetConstructor (
236- System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ,
237- null , Type . EmptyTypes , null ) ! ;
238- return ( RuntimeOptionsUpdateBuilder ) ctor . Invoke ( null ) ;
239- }
219+ // ARRANGE
220+ var builder = new RuntimeOptionsUpdateBuilder ( ) ;
240221
241- private static RuntimeCacheOptions InvokeApplyTo (
242- RuntimeOptionsUpdateBuilder builder ,
243- RuntimeCacheOptions current )
244- {
245- var method = typeof ( RuntimeOptionsUpdateBuilder )
246- . GetMethod ( "ApplyTo" ,
247- System . Reflection . BindingFlags . NonPublic | System . Reflection . BindingFlags . Instance ) ! ;
248- try
249- {
250- return ( RuntimeCacheOptions ) method . Invoke ( builder , [ current ] ) ! ;
251- }
252- catch ( System . Reflection . TargetInvocationException ex ) when ( ex . InnerException is not null )
253- {
254- System . Runtime . ExceptionServices . ExceptionDispatchInfo . Capture ( ex . InnerException ) . Throw ( ) ;
255- throw ; // unreachable, satisfies compiler
256- }
222+ // ACT
223+ var exception = Record . Exception ( ( ) => builder . WithDebounceDelay ( TimeSpan . FromMilliseconds ( - 1 ) ) ) ;
224+
225+ // ASSERT
226+ Assert . NotNull ( exception ) ;
227+ Assert . IsType < ArgumentOutOfRangeException > ( exception ) ;
257228 }
229+
230+ #endregion
258231}
0 commit comments