99using WireMock . Models ;
1010using WireMock . Owin ;
1111using WireMock . Services ;
12- using WireMock . Util ;
1312using Xunit ;
1413
1514namespace WireMock . Net . Tests . Owin ;
@@ -26,7 +25,7 @@ public MappingMatcherTests()
2625 _optionsMock = new Mock < IWireMockMiddlewareOptions > ( ) ;
2726 _optionsMock . SetupAllProperties ( ) ;
2827 _optionsMock . Setup ( o => o . Mappings ) . Returns ( new ConcurrentDictionary < Guid , IMapping > ( ) ) ;
29- _optionsMock . Setup ( o => o . LogEntries ) . Returns ( new ConcurrentObservableCollection < LogEntry > ( ) ) ;
28+ _optionsMock . Setup ( o => o . LogEntries ) . Returns ( [ ] ) ;
3029 _optionsMock . Setup ( o => o . Scenarios ) . Returns ( new ConcurrentDictionary < string , ScenarioState > ( ) ) ;
3130
3231 var loggerMock = new Mock < IWireMockLogger > ( ) ;
@@ -35,7 +34,7 @@ public MappingMatcherTests()
3534 _optionsMock . Setup ( o => o . Logger ) . Returns ( loggerMock . Object ) ;
3635
3736 _randomizerDoubleBetween0And1Mock = new Mock < IRandomizerDoubleBetween0And1 > ( ) ;
38- _randomizerDoubleBetween0And1Mock . Setup ( r => r . Generate ( ) ) . Returns ( 0.0 ) ;
37+ _randomizerDoubleBetween0And1Mock . Setup ( r => r . Generate ( ) ) . Returns ( 0.5 ) ;
3938
4039 _sut = new MappingMatcher ( _optionsMock . Object , _randomizerDoubleBetween0And1Mock . Object ) ;
4140 }
@@ -84,8 +83,8 @@ public void MappingMatcher_FindBestMatch_WhenAllowPartialMappingIsFalse_ShouldRe
8483 var guid2 = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
8584 var mappings = InitMappings
8685 (
87- ( guid1 , new [ ] { 0.1 } , null ) ,
88- ( guid2 , new [ ] { 1.0 } , null )
86+ ( guid1 , [ 0.1 ] , null ) ,
87+ ( guid2 , [ 1.0 ] , null )
8988 ) ;
9089 _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
9190
@@ -112,8 +111,8 @@ public void MappingMatcher_FindBestMatch_WhenAllowPartialMappingIsFalse_AndNoExa
112111 var guid2 = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
113112 var mappings = InitMappings
114113 (
115- ( guid1 , new [ ] { 0.1 } , null ) ,
116- ( guid2 , new [ ] { 0.9 } , null )
114+ ( guid1 , [ 0.1 ] , null ) ,
115+ ( guid2 , [ 0.9 ] , null )
117116 ) ;
118117 _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
119118
@@ -139,8 +138,8 @@ public void MappingMatcher_FindBestMatch_WhenAllowPartialMappingIsTrue_ShouldRet
139138
140139 _optionsMock . SetupGet ( o => o . AllowPartialMapping ) . Returns ( true ) ;
141140 var mappings = InitMappings (
142- ( guid1 , new [ ] { 0.1 } , null ) ,
143- ( guid2 , new [ ] { 0.9 } , null )
141+ ( guid1 , [ 0.1 ] , null ) ,
142+ ( guid2 , [ 0.9 ] , null )
144143 ) ;
145144 _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
146145
@@ -166,8 +165,8 @@ public void MappingMatcher_FindBestMatch_WhenAllowPartialMappingIsFalse_And_With
166165 var guid1 = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
167166 var guid2 = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
168167 var mappings = InitMappings (
169- ( guid1 , new [ ] { 1.0 } , null ) ,
170- ( guid2 , new [ ] { 1.0 , 1.0 } , null )
168+ ( guid1 , [ 1.0 ] , null ) ,
169+ ( guid2 , [ 1.0 , 1.0 ] , null )
171170 ) ;
172171 _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
173172
@@ -187,15 +186,15 @@ public void MappingMatcher_FindBestMatch_WhenAllowPartialMappingIsFalse_And_With
187186 }
188187
189188 [ Fact ]
190- public void MappingMatcher_FindBestMatch_WhenProbabilityFailsFirst_ShouldReturnSecondMatch ( )
189+ public void MappingMatcher_FindBestMatch_WhenProbabilityDoesNotMatch_ShouldReturnNormalMatch ( )
191190 {
192191 // Assign
193- var guid1 = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
194- var guid2 = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
192+ var withProbability = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
193+ var noProbability = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
195194 var mappings = InitMappings
196195 (
197- ( guid1 , new [ ] { 1.0 } , 1.0 ) ,
198- ( guid2 , new [ ] { 1.0 } , null )
196+ ( withProbability , [ 1.0 ] , 0.4 ) ,
197+ ( noProbability , [ 1.0 ] , null )
199198 ) ;
200199 _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
201200
@@ -206,8 +205,30 @@ public void MappingMatcher_FindBestMatch_WhenProbabilityFailsFirst_ShouldReturnS
206205
207206 // Assert
208207 result . Match . Should ( ) . NotBeNull ( ) ;
209- result . Match ! . Mapping . Guid . Should ( ) . Be ( guid2 ) ;
210- result . Match . RequestMatchResult . AverageTotalScore . Should ( ) . Be ( 1.0 ) ;
208+ result . Match ! . Mapping . Guid . Should ( ) . Be ( noProbability ) ;
209+ }
210+
211+ [ Fact ]
212+ public void MappingMatcher_FindBestMatch_WhenProbabilityDoesMatch_ShouldReturnProbabilityMatch ( )
213+ {
214+ // Assign
215+ var withProbability = Guid . Parse ( "00000000-0000-0000-0000-000000000001" ) ;
216+ var noProbability = Guid . Parse ( "00000000-0000-0000-0000-000000000002" ) ;
217+ var mappings = InitMappings
218+ (
219+ ( withProbability , [ 1.0 ] , 0.6 ) ,
220+ ( noProbability , [ 1.0 ] , null )
221+ ) ;
222+ _optionsMock . Setup ( o => o . Mappings ) . Returns ( mappings ) ;
223+
224+ var request = new RequestMessage ( new UrlDetails ( "http://localhost/foo" ) , "GET" , "::1" ) ;
225+
226+ // Act
227+ var result = _sut . FindBestMatch ( request ) ;
228+
229+ // Assert
230+ result . Match . Should ( ) . NotBeNull ( ) ;
231+ result . Match ! . Mapping . Guid . Should ( ) . Be ( withProbability ) ;
211232 }
212233
213234 private static ConcurrentDictionary < Guid , IMapping > InitMappings ( params ( Guid guid , double [ ] scores , double ? probability ) [ ] matches )
0 commit comments