diff --git a/src/Test/L0/CommandLineParserL0.cs b/src/Test/L0/CommandLineParserL0.cs index 19ab497fa35..e502868ba3b 100644 --- a/src/Test/L0/CommandLineParserL0.cs +++ b/src/Test/L0/CommandLineParserL0.cs @@ -68,7 +68,7 @@ public void ParsesCommands() trace.Info("Parsed"); trace.Info("Commands: {0}", clp.Commands.Count); - Assert.True(clp.Commands.Count == 2); + Assert.Equal(2, clp.Commands.Count); } } @@ -88,7 +88,7 @@ public void ParsesArgs() trace.Info("Parsed"); trace.Info("Args: {0}", clp.Args.Count); - Assert.True(clp.Args.Count == 2); + Assert.Equal(2, clp.Args.Count); Assert.True(clp.Args.ContainsKey("arg1")); Assert.Equal("arg1val", clp.Args["arg1"]); Assert.True(clp.Args.ContainsKey("arg2")); @@ -112,7 +112,7 @@ public void ParsesFlags() trace.Info("Parsed"); trace.Info("Args: {0}", clp.Flags.Count); - Assert.True(clp.Flags.Count == 2); + Assert.Equal(2, clp.Flags.Count); Assert.Contains("flag1", clp.Flags); Assert.Contains("flag2", clp.Flags); } diff --git a/src/Test/L0/ConstantGenerationL0.cs b/src/Test/L0/ConstantGenerationL0.cs index 204248516d7..f3c1b8f9eaf 100644 --- a/src/Test/L0/ConstantGenerationL0.cs +++ b/src/Test/L0/ConstantGenerationL0.cs @@ -24,7 +24,7 @@ public void BuildConstantGenerateSucceed() "osx-arm64" }; - Assert.True(BuildConstants.Source.CommitHash.Length == 40, $"CommitHash should be SHA-1 hash {BuildConstants.Source.CommitHash}"); + Assert.Equal(40, BuildConstants.Source.CommitHash.Length); Assert.True(validPackageNames.Contains(BuildConstants.RunnerPackage.PackageName), $"PackageName should be one of the following '{string.Join(", ", validPackageNames)}', current PackageName is '{BuildConstants.RunnerPackage.PackageName}'"); } } diff --git a/src/Test/L0/Listener/CommandSettingsL0.cs b/src/Test/L0/Listener/CommandSettingsL0.cs index ed7b672b86c..f823ba82f47 100644 --- a/src/Test/L0/Listener/CommandSettingsL0.cs +++ b/src/Test/L0/Listener/CommandSettingsL0.cs @@ -806,7 +806,7 @@ public void ValidateGoodCommandline() "test runner" }); // Assert. - Assert.True(command.Validate().Count == 0); + Assert.Equal(0, command.Validate().Count); } } @@ -844,7 +844,7 @@ public void ValidateGoodFlagCommandCombination(string validCommand, string flag) var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{flag}" }); // Assert. - Assert.True(command.Validate().Count == 0); + Assert.Equal(0, command.Validate().Count); } } @@ -874,7 +874,7 @@ public void ValidateGoodArgCommandCombination(string validCommand, string arg, s var command = new CommandSettings(hc, args: new string[] { validCommand, $"--{arg}", argValue }); // Assert. - Assert.True(command.Validate().Count == 0); + Assert.Equal(0, command.Validate().Count); } } diff --git a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs index 5ee14404a61..3c698fdda12 100644 --- a/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs +++ b/src/Test/L0/Listener/Configuration/ConfigurationManagerL0.cs @@ -190,11 +190,11 @@ public async Task CanEnsureConfigure() trace.Info("Configured, verifying all the parameter value"); var s = configManager.LoadSettings(); Assert.NotNull(s); - Assert.True(s.ServerUrl.Equals(_expectedServerUrl)); - Assert.True(s.AgentName.Equals(_expectedAgentName)); - Assert.True(s.PoolId.Equals(_secondRunnerGroupId)); - Assert.True(s.WorkFolder.Equals(_expectedWorkFolder)); - Assert.True(s.Ephemeral.Equals(true)); + Assert.Equal(_expectedServerUrl, s.ServerUrl); + Assert.Equal(_expectedAgentName, s.AgentName); + Assert.Equal(_secondRunnerGroupId, s.PoolId); + Assert.Equal(_expectedWorkFolder, s.WorkFolder); + Assert.True(s.Ephemeral); // validate GetAgentPoolsAsync gets called twice with automation pool type _runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny(), It.Is(p => p == TaskAgentPoolType.Automation)), Times.Exactly(2)); @@ -292,11 +292,11 @@ public async Task ConfigureDefaultLabelsDisabledWithCustomLabels() trace.Info("Configured, verifying all the parameter value"); var s = configManager.LoadSettings(); Assert.NotNull(s); - Assert.True(s.ServerUrl.Equals(_expectedServerUrl)); - Assert.True(s.AgentName.Equals(_expectedAgentName)); - Assert.True(s.PoolId.Equals(_secondRunnerGroupId)); - Assert.True(s.WorkFolder.Equals(_expectedWorkFolder)); - Assert.True(s.Ephemeral.Equals(true)); + Assert.Equal(_expectedServerUrl, s.ServerUrl); + Assert.Equal(_expectedAgentName, s.AgentName); + Assert.Equal(_secondRunnerGroupId, s.PoolId); + Assert.Equal(_expectedWorkFolder, s.WorkFolder); + Assert.True(s.Ephemeral); // validate GetAgentPoolsAsync gets called twice with automation pool type _runnerServer.Verify(x => x.GetAgentPoolsAsync(It.IsAny(), It.Is(p => p == TaskAgentPoolType.Automation)), Times.Exactly(2)); diff --git a/src/Test/L0/Listener/JobDispatcherL0.cs b/src/Test/L0/Listener/JobDispatcherL0.cs index 4d3f258c86c..cc50c180456 100644 --- a/src/Test/L0/Listener/JobDispatcherL0.cs +++ b/src/Test/L0/Listener/JobDispatcherL0.cs @@ -734,7 +734,10 @@ public async void DispatchesOneTimeJobRequest() await jobDispatcher.WaitAsync(CancellationToken.None); Assert.True(jobDispatcher.RunOnceJobCompleted.Task.IsCompleted, "JobDispatcher should set task complete token for one time agent."); - Assert.True(jobDispatcher.RunOnceJobCompleted.Task.Result, "JobDispatcher should set task complete token to 'TRUE' for one time agent."); + if (jobDispatcher.RunOnceJobCompleted.Task.IsCompleted) + { + Assert.True(await jobDispatcher.RunOnceJobCompleted.Task, "JobDispatcher should set task complete token to 'TRUE' for one time agent."); + } } } diff --git a/src/Test/L0/Listener/RunnerL0.cs b/src/Test/L0/Listener/RunnerL0.cs index 10b6d8c0fed..03f251a7720 100644 --- a/src/Test/L0/Listener/RunnerL0.cs +++ b/src/Test/L0/Listener/RunnerL0.cs @@ -126,7 +126,7 @@ public async void TestRunAsync() //wait for the runner to run one job if (!await signalWorkerComplete.WaitAsync(2000)) { - Assert.True(false, $"{nameof(_messageListener.Object.GetNextMessageAsync)} was not invoked."); + Assert.Fail($"{nameof(_messageListener.Object.GetNextMessageAsync)} was not invoked."); } else { @@ -305,8 +305,11 @@ public async void TestRunOnce() await Task.WhenAny(runnerTask, Task.Delay(30000)); Assert.True(runnerTask.IsCompleted, $"{nameof(runner.ExecuteCommand)} timed out."); - Assert.True(!runnerTask.IsFaulted, runnerTask.Exception?.ToString()); - Assert.True(runnerTask.Result == Constants.Runner.ReturnCode.Success); + Assert.False(runnerTask.IsFaulted, runnerTask.Exception?.ToString()); + if (runnerTask.IsCompleted) + { + Assert.Equal(Constants.Runner.ReturnCode.Success, await runnerTask); + } _jobDispatcher.Verify(x => x.Run(It.IsAny(), true), Times.Once(), $"{nameof(_jobDispatcher.Object.Run)} was not invoked."); @@ -406,7 +409,10 @@ public async void TestRunOnceOnlyTakeOneJobMessage() Assert.True(runnerTask.IsCompleted, $"{nameof(runner.ExecuteCommand)} timed out."); Assert.True(!runnerTask.IsFaulted, runnerTask.Exception?.ToString()); - Assert.True(runnerTask.Result == Constants.Runner.ReturnCode.Success); + if (runnerTask.IsCompleted) + { + Assert.Equal(Constants.Runner.ReturnCode.Success, await runnerTask); + } _jobDispatcher.Verify(x => x.Run(It.IsAny(), true), Times.Once(), $"{nameof(_jobDispatcher.Object.Run)} was not invoked."); @@ -492,7 +498,10 @@ public async void TestRunOnceHandleUpdateMessage() Assert.True(runnerTask.IsCompleted, $"{nameof(runner.ExecuteCommand)} timed out."); Assert.True(!runnerTask.IsFaulted, runnerTask.Exception?.ToString()); - Assert.True(runnerTask.Result == Constants.Runner.ReturnCode.RunOnceRunnerUpdating); + if (runnerTask.IsCompleted) + { + Assert.Equal(Constants.Runner.ReturnCode.RunOnceRunnerUpdating, await runnerTask); + } _updater.Verify(x => x.SelfUpdate(It.IsAny(), It.IsAny(), false, It.IsAny()), Times.Once); _jobDispatcher.Verify(x => x.Run(It.IsAny(), true), Times.Never()); diff --git a/src/Test/L0/ProcessExtensionL0.cs b/src/Test/L0/ProcessExtensionL0.cs index 9708c14953a..e9791250b20 100644 --- a/src/Test/L0/ProcessExtensionL0.cs +++ b/src/Test/L0/ProcessExtensionL0.cs @@ -58,7 +58,7 @@ public async Task SuccessReadProcessEnv() trace.Error(ex); } - Assert.True(false, "Fail to retrive process environment variable."); + Assert.Fail("Failed to retrieve process environment variable."); } finally { diff --git a/src/Test/L0/RunnerWebProxyL0.cs b/src/Test/L0/RunnerWebProxyL0.cs index 61fe68d181c..5e339e0a32f 100644 --- a/src/Test/L0/RunnerWebProxyL0.cs +++ b/src/Test/L0/RunnerWebProxyL0.cs @@ -65,7 +65,14 @@ public void IsNotUseRawHttpClientHandler() } } - Assert.True(badCode.Count == 0, $"The following code is using Raw HttpClientHandler() which will not follow the proxy setting agent have. Please use HostContext.CreateHttpClientHandler() instead.\n {string.Join("\n", badCode)}"); + if (badCode.Count > 0) + { + Assert.Fail($"The following code is using Raw HttpClientHandler() which will not follow the proxy setting agent have. Please use HostContext.CreateHttpClientHandler() instead.\n {string.Join("\n", badCode)}"); + } + else + { + Assert.True(true); + } } [Fact] @@ -112,7 +119,14 @@ public void IsNotUseRawHttpClient() } } - Assert.True(badCode.Count == 0, $"The following code is using Raw HttpClient() which will not follow the proxy setting agent have. Please use New HttpClient(HostContext.CreateHttpClientHandler()) instead.\n {string.Join("\n", badCode)}"); + if (badCode.Count > 0) + { + Assert.Fail($"The following code is using Raw HttpClient() which will not follow the proxy setting agent have. Please use New HttpClient(HostContext.CreateHttpClientHandler()) instead.\n {string.Join("\n", badCode)}"); + } + else + { + Assert.True(true); + } } [Fact] diff --git a/src/Test/L0/Worker/ActionManagerL0.cs b/src/Test/L0/Worker/ActionManagerL0.cs index 1176966149f..91f183ae220 100644 --- a/src/Test/L0/Worker/ActionManagerL0.cs +++ b/src/Test/L0/Worker/ActionManagerL0.cs @@ -460,7 +460,7 @@ public async void PrepareActions_SkipDownloadActionForSelfRepo() //Act var steps = (await _actionManager.PrepareActionsAsync(_ec.Object, actions)).ContainerSetupSteps; - Assert.True(steps.Count == 0); + Assert.Equal(0, steps.Count); } finally { @@ -915,7 +915,7 @@ public async void PrepareActions_RepositoryActionWithActionfile_Node() var steps = (await _actionManager.PrepareActionsAsync(_ec.Object, actions)).ContainerSetupSteps; // node.js based action doesn't need any extra steps to build/pull containers. - Assert.True(steps.Count == 0); + Assert.Equal(0, steps.Count); } finally { @@ -1051,7 +1051,7 @@ public async void PrepareActions_CompositeActionWithActionfile_Node() var steps = (await _actionManager.PrepareActionsAsync(_ec.Object, actions)).ContainerSetupSteps; // node.js based action doesn't need any extra steps to build/pull containers. - Assert.True(steps.Count == 0); + Assert.Equal(0, steps.Count); var watermarkFile = Path.Combine(_hc.GetDirectory(WellKnownDirectory.Actions), "TingluoHuang/runner_L0", "CompositeBasic.completed"); Assert.True(File.Exists(watermarkFile)); // Comes from the composite action @@ -1245,7 +1245,7 @@ public void LoadsScriptActionDefinition() // Assert. Assert.NotNull(definition); Assert.NotNull(definition.Data); - Assert.True(definition.Data.Execution.ExecutionType == ActionExecutionType.Script); + Assert.Equal(ActionExecutionType.Script, definition.Data.Execution.ExecutionType); } finally { diff --git a/src/Test/Test.csproj b/src/Test/Test.csproj index 0f336013050..1beddbfc251 100644 --- a/src/Test/Test.csproj +++ b/src/Test/Test.csproj @@ -16,7 +16,7 @@ - +