Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions DevProxy.Tests/DevProxyCommandTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using DevProxy.Commands;

using Xunit;

namespace DevProxy.Tests;

public class DevProxyCommandTests
{
[Fact]
public void ApplyDiscoverOption_True_EnablesRecording()
{
var config = new FakeProxyConfiguration { Record = false };

DevProxyCommand.ApplyDiscoverOption(config, true);

Assert.True(config.Record);
}

[Fact]
public void ApplyDiscoverOption_False_DoesNotEnableRecording()
{
var config = new FakeProxyConfiguration { Record = false };

DevProxyCommand.ApplyDiscoverOption(config, false);

Assert.False(config.Record);
}

[Theory]
[InlineData(false)]
[InlineData(true)]
public void ApplyDiscoverOption_NotSpecified_LeavesRecordingUnchanged(bool record)
{
var config = new FakeProxyConfiguration { Record = record };

DevProxyCommand.ApplyDiscoverOption(config, null);

Assert.Equal(record, config.Record);
}

[Fact]
public void ApplyDiscoverOption_False_KeepsRecordingEnabledFromOtherSources()
{
var config = new FakeProxyConfiguration { Record = true };

DevProxyCommand.ApplyDiscoverOption(config, false);

Assert.True(config.Record);
}
}
15 changes: 10 additions & 5 deletions DevProxy/Commands/DevProxyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,15 @@ private void CustomizeHelp()
}
}

internal static void ApplyDiscoverOption(IProxyConfiguration proxyConfiguration, bool? isDiscover)
{
// Discovery mode requires recording, but --discover false must not enable it
if (isDiscover == true)
{
proxyConfiguration.Record = true;
}
}

private void ConfigureFromOptions(ParseResult parseResult)
{
var port = parseResult.GetValueOrDefault<int?>(PortOptionName);
Expand Down Expand Up @@ -742,11 +751,7 @@ private void ConfigureFromOptions(ParseResult parseResult)
{
_proxyConfiguration.TimeoutSeconds = timeout.Value;
}
var isDiscover = parseResult.GetValueOrDefault<bool?>(DiscoverOptionName);
if (isDiscover is not null)
{
_proxyConfiguration.Record = true;
}
ApplyDiscoverOption(_proxyConfiguration, parseResult.GetValueOrDefault<bool?>(DiscoverOptionName));
var env = parseResult.GetValueOrDefault<string[]?>(EnvOptionName);
if (env is not null)
{
Expand Down
Loading