123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- using Microsoft.Extensions.Tools.Internal;
- namespace Microsoft.DotNet.Watcher.Tools
- {
- public class NoRestoreTests
- {
- private readonly string[] _arguments = new[] { "run" };
- [Fact]
- public void ProcessAsync_LeavesArgumentsUnchangedOnFirstRun()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = _arguments,
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- Assert.Same(_arguments, processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_LeavesArgumentsUnchangedIfMsBuildRevaluationIsRequired()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = _arguments,
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.RequiresRevaluation = true;
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Same(_arguments, processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_LeavesArgumentsUnchangedIfOptimizationIsSuppressed()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental with { SuppressMSBuildIncrementalism = true },
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = _arguments,
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Same(_arguments, processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_AddsNoRestoreSwitch()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var processSpec = new ProcessSpec
- {
- Arguments = _arguments,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Equal(new[] { "run", "--no-restore" }, processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_AddsNoRestoreSwitch_WithAdditionalArguments()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = ["run", "-f", ToolsetInfo.CurrentTargetFramework, "--", "foo=bar"],
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Equal(["run", "--no-restore", "-f", ToolsetInfo.CurrentTargetFramework, "--", "foo=bar"], processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_AddsNoRestoreSwitch_ForTestCommand()
- {
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = ["test", "--filter SomeFilter"],
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Equal(["test", "--no-restore", "--filter SomeFilter"], processSpec.Arguments);
- }
- [Fact]
- public void ProcessAsync_DoesNotModifyArgumentsForUnknownCommands()
- {
- var arguments = new[] { "ef", "database", "update" };
- var context = new DotNetWatchContext
- {
- Reporter = NullReporter.Singleton,
- LaunchSettingsProfile = new(),
- Options = TestOptions.CommandLine,
- EnvironmentOptions = TestOptions.Environmental,
- };
- var evaluator = new BuildEvaluator(context, new MockFileSetFactory());
- var processSpec = new ProcessSpec
- {
- Arguments = arguments,
- };
- evaluator.UpdateProcessArguments(processSpec, iteration: 0);
- evaluator.UpdateProcessArguments(processSpec, iteration: 1);
- Assert.Same(arguments, processSpec.Arguments);
- }
- }
- }
|