Skip to content

Commit

Permalink
Three basic tests are now working. Had to change Directory.Builds.Pro…
Browse files Browse the repository at this point in the history
…ps due to the error saying -> the feature global using directive is currently in preview and unsupported. Planning to further flesh out testing and clean up code.
  • Loading branch information
kkeirstead committed Aug 18, 2021
1 parent d7c5e29 commit 1014578
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 24 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<DisableImplicitNamespaceImports_DotNet>true</DisableImplicitNamespaceImports_DotNet>
</PropertyGroup>

<PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion dotnet-monitor.sln
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monit
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.Tool.UnitTests", "src\Tests\Microsoft.Diagnostics.Monitoring.Tool.UnitTests\Microsoft.Diagnostics.Monitoring.Tool.UnitTests.csproj", "{0DBE362D-82F1-4740-AE6A-40C1A82EDCDB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.ExecuteActionApp", "src\Tests\Microsoft.Diagnostics.Monitoring.ExecuteActionApp\Microsoft.Diagnostics.Monitoring.ExecuteActionApp.csproj", "{A5A0CAAB-C200-44D2-BC93-8445C6E748AD}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Diagnostics.Monitoring.ExecuteApp", "src\Tests\Microsoft.Diagnostics.Monitoring.ExecuteActionApp\Microsoft.Diagnostics.Monitoring.ExecuteApp.csproj", "{A5A0CAAB-C200-44D2-BC93-8445C6E748AD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Diagnostics.Monitoring.TestCommon\Microsoft.Diagnostics.Monitoring.TestCommon.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Threading.Tasks;
using System.IO;
using System.Threading;

namespace Microsoft.Diagnostics.Monitoring.ExecuteActionApp
namespace Microsoft.Diagnostics.Monitoring.ExecuteApp
{
internal class Program
{
public static int Main(string[] args)
{
string testType = args[1];
File.WriteAllText("C:\\Users\\kkeirstead\\FileOutputs\\Test.txt", args[0]); // Testing purposes only

string testType = args[0];
const int DelayMs = 3000; // Should be greater than the token delay in the test.

switch (testType)
Expand All @@ -22,7 +25,7 @@ public static int Main(string[] args)
return -1;

case "TokenCancellation":
Task.Delay(DelayMs);
Thread.Sleep(DelayMs);
return 0;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public sealed class ExecuteActionTests
// This should be identical to the error message found in Strings.resx (except without the process's exit code)
private const string NonzeroExitCodeMessage = "The process exited with exit code";

// This should be identical to the error message found in Strings.resx (except without the process's exit code)
private const string TaskCanceledMessage = "A task was canceled";

[Fact]
public async Task ExecuteAction_ZeroExitCode()
{
Expand All @@ -30,7 +33,7 @@ public async Task ExecuteAction_ZeroExitCode()
options.Path = DotNetHost.HostExePath;
options.Arguments = Assembly.GetExecutingAssembly().Location.Replace(
Assembly.GetExecutingAssembly().GetName().Name,
"Microsoft.Diagnostics.Monitoring.ExecuteActionApp") + " ZeroExitCode";
"Microsoft.Diagnostics.Monitoring.ExecuteApp") + " ZeroExitCode";

using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TokenTimeoutMs);
CancellationToken cancellationToken = cancellationTokenSource.Token;
Expand All @@ -50,7 +53,7 @@ public async Task ExecuteAction_NonzeroExitCode()
options.Path = DotNetHost.HostExePath;
options.Arguments = Assembly.GetExecutingAssembly().Location.Replace(
Assembly.GetExecutingAssembly().GetName().Name,
"Microsoft.Diagnostics.Monitoring.ExecuteActionApp") + " NonzeroExitCode";
"Microsoft.Diagnostics.Monitoring.ExecuteApp") + " NonzeroExitCode";

using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TokenTimeoutMs);
CancellationToken cancellationToken = cancellationTokenSource.Token;
Expand All @@ -70,14 +73,14 @@ public async Task ExecuteAction_TokenCancellation()
options.Path = DotNetHost.HostExePath;
options.Arguments = Assembly.GetExecutingAssembly().Location.Replace(
Assembly.GetExecutingAssembly().GetName().Name,
"Microsoft.Diagnostics.Monitoring.ExecuteActionApp") + " TokenCancellation";
"Microsoft.Diagnostics.Monitoring.ExecuteApp") + " TokenCancellation";

using CancellationTokenSource cancellationTokenSource = new CancellationTokenSource(TokenTimeoutMs);
CancellationToken cancellationToken = cancellationTokenSource.Token;

OperationCanceledException invalidOperationException = await Assert.ThrowsAsync<OperationCanceledException>(
TaskCanceledException invalidOperationException = await Assert.ThrowsAsync<TaskCanceledException>(
() => action.ExecuteAsync(options, null, cancellationToken));
Assert.Contains(NonzeroExitCodeMessage, invalidOperationException.Message);
Assert.Contains(TaskCanceledMessage, invalidOperationException.Message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ public async Task<CollectionRuleActionResult> ExecuteAsync(ExecuteOptions option
foreach (string arg in args)
{
process.StartInfo.ArgumentList.Add(arg);
}
*/
}*/

process.EnableRaisingEvents = true;

Expand Down

0 comments on commit 1014578

Please sign in to comment.