@@ -96,7 +96,7 @@ private static string ValidBody(string variationId = "v1")
9696 public void FetchDecisionReturnsSuccessNoRetry ( )
9797 {
9898 var http = MakeClient ( new ResponseStep ( HttpStatusCode . OK , ValidBody ( "v1" ) ) ) ;
99- var client = new DefaultCmabClient ( http , retryConfig : null , logger : new NoOpLogger ( ) , errorHandler : new NoOpErrorHandler ( ) ) ;
99+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retryConfig : null , logger : new NoOpLogger ( ) , errorHandler : new NoOpErrorHandler ( ) ) ;
100100 var result = client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ;
101101
102102 Assert . AreEqual ( "v1" , result ) ;
@@ -106,7 +106,7 @@ public void FetchDecisionReturnsSuccessNoRetry()
106106 public void FetchDecisionHttpExceptionNoRetry ( )
107107 {
108108 var http = MakeClientExceptionSequence ( new HttpRequestException ( "boom" ) ) ;
109- var client = new DefaultCmabClient ( http , retryConfig : null ) ;
109+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retryConfig : null ) ;
110110
111111 Assert . Throws < CmabFetchException > ( ( ) =>
112112 client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ) ;
@@ -116,7 +116,7 @@ public void FetchDecisionHttpExceptionNoRetry()
116116 public void FetchDecisionNon2xxNoRetry ( )
117117 {
118118 var http = MakeClient ( new ResponseStep ( HttpStatusCode . InternalServerError , null ) ) ;
119- var client = new DefaultCmabClient ( http , retryConfig : null ) ;
119+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retryConfig : null ) ;
120120
121121 Assert . Throws < CmabFetchException > ( ( ) =>
122122 client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ) ;
@@ -126,7 +126,7 @@ public void FetchDecisionNon2xxNoRetry()
126126 public void FetchDecisionInvalidJsonNoRetry ( )
127127 {
128128 var http = MakeClient ( new ResponseStep ( HttpStatusCode . OK , "not json" ) ) ;
129- var client = new DefaultCmabClient ( http , retryConfig : null ) ;
129+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retryConfig : null ) ;
130130
131131 Assert . Throws < CmabInvalidResponseException > ( ( ) =>
132132 client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ) ;
@@ -136,7 +136,7 @@ public void FetchDecisionInvalidJsonNoRetry()
136136 public void FetchDecisionInvalidStructureNoRetry ( )
137137 {
138138 var http = MakeClient ( new ResponseStep ( HttpStatusCode . OK , "{\" predictions\" :[]}" ) ) ;
139- var client = new DefaultCmabClient ( http , retryConfig : null ) ;
139+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retryConfig : null ) ;
140140
141141 Assert . Throws < CmabInvalidResponseException > ( ( ) =>
142142 client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ) ;
@@ -147,7 +147,7 @@ public void FetchDecisionSuccessWithRetryFirstTry()
147147 {
148148 var http = MakeClient ( new ResponseStep ( HttpStatusCode . OK , ValidBody ( "v2" ) ) ) ;
149149 var retry = new CmabRetryConfig ( maxRetries : 2 , initialBackoff : TimeSpan . Zero , maxBackoff : TimeSpan . FromSeconds ( 1 ) , backoffMultiplier : 2.0 ) ;
150- var client = new DefaultCmabClient ( http , retry ) ;
150+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retry ) ;
151151 var result = client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ;
152152
153153 Assert . AreEqual ( "v2" , result ) ;
@@ -162,7 +162,7 @@ public void FetchDecisionSuccessWithRetryThirdTry()
162162 new ResponseStep ( HttpStatusCode . OK , ValidBody ( "v3" ) )
163163 ) ;
164164 var retry = new CmabRetryConfig ( maxRetries : 2 , initialBackoff : TimeSpan . Zero , maxBackoff : TimeSpan . FromSeconds ( 1 ) , backoffMultiplier : 2.0 ) ;
165- var client = new DefaultCmabClient ( http , retry ) ;
165+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retry ) ;
166166 var result = client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ;
167167
168168 Assert . AreEqual ( "v3" , result ) ;
@@ -177,10 +177,40 @@ public void FetchDecisionExhaustsAllRetries()
177177 new ResponseStep ( HttpStatusCode . InternalServerError , null )
178178 ) ;
179179 var retry = new CmabRetryConfig ( maxRetries : 2 , initialBackoff : TimeSpan . Zero , maxBackoff : TimeSpan . FromSeconds ( 1 ) , backoffMultiplier : 2.0 ) ;
180- var client = new DefaultCmabClient ( http , retry ) ;
180+ var client = new DefaultCmabClient ( CmabConstants . DEFAULT_PREDICTION_URL_TEMPLATE , http , retry ) ;
181181
182182 Assert . Throws < CmabFetchException > ( ( ) =>
183183 client . FetchDecision ( "rule-1" , "user-1" , null , "uuid-1" ) ) ;
184184 }
185+
186+ [ Test ]
187+ public void FetchDecision_CustomEndpoint_CallsCorrectUrl ( )
188+ {
189+ var customEndpoint = "https://custom.example.com/api/{0}" ;
190+ string capturedUrl = null ;
191+
192+ var handler = new Mock < HttpMessageHandler > ( MockBehavior . Strict ) ;
193+ handler . Protected ( )
194+ . Setup < Task < HttpResponseMessage > > ( "SendAsync" ,
195+ ItExpr . IsAny < HttpRequestMessage > ( ) ,
196+ ItExpr . IsAny < CancellationToken > ( ) )
197+ . Returns ( ( HttpRequestMessage req , CancellationToken _ ) =>
198+ {
199+ capturedUrl = req . RequestUri . ToString ( ) ;
200+ var response = new HttpResponseMessage ( HttpStatusCode . OK )
201+ {
202+ Content = new StringContent ( ValidBody ( "variation123" ) )
203+ } ;
204+ return Task . FromResult ( response ) ;
205+ } ) ;
206+
207+ var http = new HttpClient ( handler . Object ) ;
208+ var client = new DefaultCmabClient ( customEndpoint , http , retryConfig : null ) ;
209+ var result = client . FetchDecision ( "rule-456" , "user-1" , null , "uuid-1" ) ;
210+
211+ Assert . AreEqual ( "variation123" , result ) ;
212+ Assert . AreEqual ( "https://custom.example.com/api/rule-456" , capturedUrl ,
213+ "Should call custom endpoint with rule ID formatted into template" ) ;
214+ }
185215 }
186216}
0 commit comments