Skip to content

Commit f2eb410

Browse files
feat/1421 addressing PR comments - Updated logic to represent IsDisable insted of IsEnabled
1 parent f179d78 commit f2eb410

File tree

12 files changed

+37
-37
lines changed

12 files changed

+37
-37
lines changed

src/WireMock.Net.Abstractions/Admin/Mappings/MappingModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ public class MappingModel
6262
public int? TimesInSameState { get; set; }
6363

6464
/// <summary>
65-
/// Value to determing if the mapping is active
65+
/// Value to determine if the mapping is disabled. Defaults to <c>null</c> (not disabled).
6666
/// </summary>
67-
public bool? IsEnabled { get; set; }
67+
public bool? IsDisabled { get; set; }
6868

6969
/// <summary>
7070
/// The request model.

src/WireMock.Net.Minimal/Mapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public class Mapping : IMapping
6363
public bool IsProxy => Provider is ProxyAsyncResponseProvider;
6464

6565
/// <inheritdoc />
66-
public bool IsEnabled { get; set; } = true;
66+
public bool IsDisabled { get; set; }
6767

6868
/// <inheritdoc />
6969
public bool LogMapping => Provider is not (DynamicResponseProvider or DynamicAsyncResponseProvider);

src/WireMock.Net.Minimal/Owin/MappingMatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class MappingMatcher(IWireMockMiddlewareOptions options, IRandomizerDou
1919
var possibleMappings = new List<MappingMatcherResult>();
2020

2121
var mappings = _options.Mappings.Values
22-
.Where(m=>m.IsEnabled)
22+
.Where(m => !m.IsDisabled)
2323
.Where(m => m.TimeSettings.IsValid())
2424
.Where(m => m.Probability is null || _randomizerDoubleBetween0And1.Generate() <= m.Probability)
2525
.ToArray();

src/WireMock.Net.Minimal/Serialization/MappingConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ public MappingModel ToMappingModel(IMapping mapping)
275275
TimesInSameState = !string.IsNullOrWhiteSpace(mapping.NextState) ? mapping.TimesInSameState : null,
276276
Data = mapping.Data,
277277
Probability = mapping.Probability,
278-
IsEnabled = mapping.IsEnabled ? null : false,
278+
IsDisabled = mapping.IsDisabled ? true : null,
279279
Request = new RequestModel
280280
{
281281
Headers = headerMatchers.Any() ? headerMatchers.Select(hm => new HeaderModel

src/WireMock.Net.Minimal/Server/IRespondWithAProvider.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,11 @@ IRespondWithAProvider WithWebhook(
235235
IRespondWithAProvider WithProbability(double probability);
236236

237237
/// <summary>
238-
/// Define whether this mapping is enabled. Defaults to <c>true</c>.
238+
/// Define whether this mapping is disabled. Defaults to <c>false</c>.
239239
/// </summary>
240-
/// <param name="isEnabled">Whether this mapping is enabled.</param>
240+
/// <param name="isDisabled">Whether this mapping is disabled.</param>
241241
/// <returns>The <see cref="IRespondWithAProvider"/>.</returns>
242-
IRespondWithAProvider WithIsEnabled(bool isEnabled);
242+
IRespondWithAProvider WithIsDisabled(bool isDisabled);
243243

244244
/// <summary>
245245
/// Define a Grpc ProtoDefinition which is used for the request and the response.

src/WireMock.Net.Minimal/Server/RespondWithAProvider.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ internal class RespondWithAProvider : IRespondWithAProvider
3737
private int _timesInSameState = 1;
3838
private bool? _useWebhookFireAndForget;
3939
private double? _probability;
40-
private bool _isEnabled = true;
40+
private bool _isDisabled = false;
4141
private GraphQLSchemaDetails? _graphQLSchemaDetails; // Future Use.
4242

4343
public Guid Guid { get; private set; }
@@ -109,9 +109,9 @@ public void RespondWith(IResponseProvider provider)
109109
mapping.WithProbability(_probability.Value);
110110
}
111111

112-
if (!_isEnabled)
112+
if (_isDisabled)
113113
{
114-
mapping.IsEnabled = false;
114+
mapping.IsDisabled = true;
115115
}
116116

117117
if (ProtoDefinition != null)
@@ -361,9 +361,9 @@ public IRespondWithAProvider WithProbability(double probability)
361361
}
362362

363363
/// <inheritdoc />
364-
public IRespondWithAProvider WithIsEnabled(bool isEnabled)
364+
public IRespondWithAProvider WithIsDisabled(bool isDisabled)
365365
{
366-
_isEnabled = isEnabled;
366+
_isDisabled = isDisabled;
367367
return this;
368368
}
369369

src/WireMock.Net.Minimal/Server/WireMockServer.Admin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ private IResponseMessage MappingEnable(HttpContext _, IRequestMessage requestMes
451451
var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
452452
if (mapping != null)
453453
{
454-
mapping.IsEnabled = true;
454+
mapping.IsDisabled = false;
455455
return ResponseMessageBuilder.Create(HttpStatusCode.OK, "Mapping enabled", guid);
456456
}
457457
}
@@ -467,7 +467,7 @@ private IResponseMessage MappingDisable(HttpContext _, IRequestMessage requestMe
467467
var mapping = Mappings.FirstOrDefault(m => !m.IsAdminInterface && m.Guid == guid);
468468
if (mapping != null)
469469
{
470-
mapping.IsEnabled = false;
470+
mapping.IsDisabled = true;
471471
return ResponseMessageBuilder.Create(HttpStatusCode.OK, "Mapping disabled", guid);
472472
}
473473
}

src/WireMock.Net.Minimal/Server/WireMockServer.ConvertMapping.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ private Guid ConvertMappingAndRegisterAsRespondProvider(MappingModel mappingMode
120120
respondProvider.WithProbability(mappingModel.Probability.Value);
121121
}
122122

123-
if (mappingModel.IsEnabled == false)
123+
if (mappingModel.IsDisabled == true)
124124
{
125-
respondProvider.WithIsEnabled(false);
125+
respondProvider.WithIsDisabled(true);
126126
}
127127

128128
// ProtoDefinition is defined at Mapping level

src/WireMock.Net.Shared/IMapping.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ public interface IMapping
109109
bool IsProxy { get; }
110110

111111
/// <summary>
112-
/// Gets a value indicating whether this mapping is a Proxy Mapping.
112+
/// Gets a value indicating whether this mapping is disabled.
113113
/// </summary>
114114
/// <value>
115-
/// <c>true</c> if this mapping is a Proxy Mapping; otherwise, <c>false</c>.
115+
/// <c>true</c> if this mapping is disabled; otherwise, <c>false</c>.
116116
/// </value>
117-
bool IsEnabled { get; set; }
117+
bool IsDisabled { get; set; }
118118

119119
/// <summary>
120120
/// Gets a value indicating whether this mapping to be logged.

test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.IsEnabled.cs renamed to test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.IsDisabled.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace WireMock.Net.Tests.AdminApi;
1010
public partial class WireMockAdminApiTests
1111
{
1212
[Fact]
13-
public async Task IWireMockAdminApi_PostMappingAsync_WithIsEnabledFalse_DoesNotMatchRequests()
13+
public async Task IWireMockAdminApi_PostMappingAsync_WithIsDisabledTrue_DoesNotMatchRequests()
1414
{
1515
// Arrange
1616
var ct = TestContext.Current.CancellationToken;
@@ -22,7 +22,7 @@ public async Task IWireMockAdminApi_PostMappingAsync_WithIsEnabledFalse_DoesNotM
2222
{
2323
Request = new RequestModel { Path = "/foo", Methods = ["GET"] },
2424
Response = new ResponseModel { Body = "hello", StatusCode = 200 },
25-
IsEnabled = false
25+
IsDisabled = true
2626
};
2727

2828
// Act — POST the disabled mapping
@@ -33,8 +33,8 @@ public async Task IWireMockAdminApi_PostMappingAsync_WithIsEnabledFalse_DoesNotM
3333
var response = await httpClient.GetAsync("/foo", ct);
3434
((int)response.StatusCode).Should().Be(404);
3535

36-
// Assert — mapping exists but IsEnabled is false
37-
server.Mappings.Where(m => !m.IsAdminInterface).Should().ContainSingle(m => m.IsEnabled == false);
36+
// Assert — mapping exists but IsDisabled is true
37+
server.Mappings.Where(m => !m.IsAdminInterface).Should().ContainSingle(m => m.IsDisabled == true);
3838
}
3939

4040
[Fact]
@@ -80,7 +80,7 @@ public async Task IWireMockAdminApi_EnableMappingAsync_ResumesMatching()
8080
{
8181
Request = new RequestModel { Path = "/baz", Methods = ["GET"] },
8282
Response = new ResponseModel { Body = "re-enabled", StatusCode = 200 },
83-
IsEnabled = false
83+
IsDisabled = true
8484
};
8585
var postResult = await api.PostMappingAsync(model, ct);
8686
var guid = postResult.Guid!.Value;
@@ -99,7 +99,7 @@ public async Task IWireMockAdminApi_EnableMappingAsync_ResumesMatching()
9999
}
100100

101101
[Fact]
102-
public async Task IWireMockAdminApi_GetMappingAsync_ReturnsIsEnabledFalse_WhenDisabled()
102+
public async Task IWireMockAdminApi_GetMappingAsync_ReturnsIsDisabledTrue_WhenDisabled()
103103
{
104104
// Arrange
105105
var ct = TestContext.Current.CancellationToken;
@@ -110,7 +110,7 @@ public async Task IWireMockAdminApi_GetMappingAsync_ReturnsIsEnabledFalse_WhenDi
110110
{
111111
Request = new RequestModel { Path = "/check-disabled" },
112112
Response = new ResponseModel { Body = "x", StatusCode = 200 },
113-
IsEnabled = false
113+
IsDisabled = true
114114
};
115115
var enabledModel = new MappingModel
116116
{
@@ -125,10 +125,10 @@ public async Task IWireMockAdminApi_GetMappingAsync_ReturnsIsEnabledFalse_WhenDi
125125
var disabledGot = await api.GetMappingAsync(disabledPost.Guid!.Value, ct);
126126
var enabledGot = await api.GetMappingAsync(enabledPost.Guid!.Value, ct);
127127

128-
// Assert — disabled mapping serializes IsEnabled = false
129-
disabledGot.IsEnabled.Should().BeFalse();
128+
// Assert — disabled mapping serializes IsDisabled = true
129+
disabledGot.IsDisabled.Should().BeTrue();
130130

131-
// Assert — enabled mapping omits IsEnabled (null = default true)
132-
enabledGot.IsEnabled.Should().BeNull();
131+
// Assert — enabled mapping omits IsDisabled (null = default not disabled)
132+
enabledGot.IsDisabled.Should().BeNull();
133133
}
134134
}

0 commit comments

Comments
 (0)