namespace System.Diagnostics.Tests
{
- public partial class ProcessStartInfoTests : ProcessTestBase
+ public class ProcessStartInfoTests : ProcessTestBase
{
[Fact]
public void TestEnvironmentProperty()
Assert.Equal(expected, Assert.Throws<Win32Exception>(() => Process.Start(info)).NativeErrorCode);
}
+
+ [Fact]
+ public void UnintializedArgumentList()
+ {
+ ProcessStartInfo psi = new ProcessStartInfo();
+ Assert.Equal(0, psi.ArgumentList.Count);
+
+ psi = new ProcessStartInfo("filename", "-arg1 -arg2");
+ Assert.Equal(0, psi.ArgumentList.Count);
+ }
+
+ [Fact]
+ public void InitializeWithArgumentList()
+ {
+ ProcessStartInfo psi = new ProcessStartInfo("filename");
+ psi.ArgumentList.Add("arg1");
+ psi.ArgumentList.Add("arg2");
+
+ Assert.Equal(2, psi.ArgumentList.Count);
+ Assert.Equal("arg1", psi.ArgumentList[0]);
+ Assert.Equal("arg2", psi.ArgumentList[1]);
+ }
+
+ [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // No Notepad on Nano
+ [MemberData(nameof(UseShellExecute))]
+ [OuterLoop("Launches notepad")]
+ [PlatformSpecific(TestPlatforms.Windows)]
+ public void StartInfo_NotepadWithContent_withArgumentList(bool useShellExecute)
+ {
+ string tempFile = GetTestFilePath() + ".txt";
+ File.WriteAllText(tempFile, $"StartInfo_NotepadWithContent({useShellExecute})");
+
+ ProcessStartInfo info = new ProcessStartInfo
+ {
+ UseShellExecute = useShellExecute,
+ FileName = @"notepad.exe",
+ Arguments = null,
+ WindowStyle = ProcessWindowStyle.Minimized
+ };
+
+ info.ArgumentList.Add(tempFile);
+
+ using (var process = Process.Start(info))
+ {
+ Assert.True(process != null, $"Could not start {info.FileName} {info.Arguments} UseShellExecute={info.UseShellExecute}");
+
+ try
+ {
+ process.WaitForInputIdle(); // Give the file a chance to load
+ Assert.Equal("notepad", process.ProcessName);
+
+ // On some Windows versions, the file extension is not included in the title
+ Assert.StartsWith(Path.GetFileNameWithoutExtension(tempFile), process.MainWindowTitle);
+ }
+ finally
+ {
+ process?.Kill();
+ }
+ }
+ }
}
}
+++ /dev/null
-// 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 System.IO;
-using Xunit;
-
-namespace System.Diagnostics.Tests
-{
- public partial class ProcessStartInfoTests
- {
- [Fact]
- public void UnintializedArgumentList()
- {
- ProcessStartInfo psi = new ProcessStartInfo();
- Assert.Equal(0, psi.ArgumentList.Count);
-
- psi = new ProcessStartInfo("filename", "-arg1 -arg2");
- Assert.Equal(0, psi.ArgumentList.Count);
- }
-
- [Fact]
- public void InitializeWithArgumentList()
- {
- ProcessStartInfo psi = new ProcessStartInfo("filename");
- psi.ArgumentList.Add("arg1");
- psi.ArgumentList.Add("arg2");
-
- Assert.Equal(2, psi.ArgumentList.Count);
- Assert.Equal("arg1", psi.ArgumentList[0]);
- Assert.Equal("arg2", psi.ArgumentList[1]);
- }
-
- [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsNotWindowsNanoServer))] // No Notepad on Nano
- [MemberData(nameof(UseShellExecute))]
- [OuterLoop("Launches notepad")]
- [PlatformSpecific(TestPlatforms.Windows)]
- public void StartInfo_NotepadWithContent_withArgumentList(bool useShellExecute)
- {
- string tempFile = GetTestFilePath() + ".txt";
- File.WriteAllText(tempFile, $"StartInfo_NotepadWithContent({useShellExecute})");
-
- ProcessStartInfo info = new ProcessStartInfo
- {
- UseShellExecute = useShellExecute,
- FileName = @"notepad.exe",
- Arguments = null,
- WindowStyle = ProcessWindowStyle.Minimized
- };
-
- info.ArgumentList.Add(tempFile);
-
- using (var process = Process.Start(info))
- {
- Assert.True(process != null, $"Could not start {info.FileName} {info.Arguments} UseShellExecute={info.UseShellExecute}");
-
- try
- {
- process.WaitForInputIdle(); // Give the file a chance to load
- Assert.Equal("notepad", process.ProcessName);
-
- // On some Windows versions, the file extension is not included in the title
- Assert.StartsWith(Path.GetFileNameWithoutExtension(tempFile), process.MainWindowTitle);
- }
- finally
- {
- process?.Kill();
- }
- }
- }
- }
-}
// 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 System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
namespace System.Diagnostics.Tests
{
- public partial class ProcessStreamReadTests : ProcessTestBase
+ public class ProcessStreamReadTests : ProcessTestBase
{
[Fact]
public void TestSyncErrorStream()
Assert.True(p.WaitForExit(WaitInMS));
}
}
+
+ [Fact]
+ public void TestCustomStandardInputEncoding()
+ {
+ var process = CreateProcessPortable(RemotelyInvokable.ReadLineWithCustomEncodingWriteLineWithUtf8, Encoding.UTF32.WebName);
+ process.StartInfo.RedirectStandardInput = true;
+ process.StartInfo.StandardInputEncoding = Encoding.UTF32;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
+ process.Start();
+
+ const string TestLine = "\U0001f627\U0001f62e\U0001f62f";
+ process.StandardInput.WriteLine(TestLine);
+ process.StandardInput.Close();
+
+ var output = process.StandardOutput.ReadLine();
+ Assert.Equal(TestLine, output);
+
+ Assert.True(process.WaitForExit(WaitInMS));
+ Assert.Equal(RemotelyInvokable.SuccessExitCode, process.ExitCode);
+ }
+
+ [Fact]
+ public void TestMismatchedStandardInputEncoding()
+ {
+ var process = CreateProcessPortable(RemotelyInvokable.ReadLineWithCustomEncodingWriteLineWithUtf8, Encoding.UTF32.WebName);
+ process.StartInfo.RedirectStandardInput = true;
+ // incorrect: the process will be writing in UTF-32
+ process.StartInfo.StandardInputEncoding = Encoding.ASCII;
+ process.StartInfo.RedirectStandardOutput = true;
+ process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
+ process.Start();
+
+ const string TestLine = "\U0001f627\U0001f62e\U0001f62f";
+ process.StandardInput.WriteLine(TestLine);
+ process.StandardInput.Close();
+
+ var output = process.StandardOutput.ReadLine();
+ Assert.NotEqual(TestLine, output);
+
+ Assert.True(process.WaitForExit(WaitInMS));
+ Assert.Equal(RemotelyInvokable.SuccessExitCode, process.ExitCode);
+ }
}
}
+++ /dev/null
-// 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 System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace System.Diagnostics.Tests
-{
- public partial class ProcessStreamReadTests : ProcessTestBase
- {
- [Fact]
- public void TestCustomStandardInputEncoding()
- {
- var process = CreateProcessPortable(RemotelyInvokable.ReadLineWithCustomEncodingWriteLineWithUtf8, Encoding.UTF32.WebName);
- process.StartInfo.RedirectStandardInput = true;
- process.StartInfo.StandardInputEncoding = Encoding.UTF32;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
- process.Start();
-
- const string TestLine = "\U0001f627\U0001f62e\U0001f62f";
- process.StandardInput.WriteLine(TestLine);
- process.StandardInput.Close();
-
- var output = process.StandardOutput.ReadLine();
- Assert.Equal(TestLine, output);
-
- Assert.True(process.WaitForExit(WaitInMS));
- Assert.Equal(RemotelyInvokable.SuccessExitCode, process.ExitCode);
- }
-
- [Fact]
- public void TestMismatchedStandardInputEncoding()
- {
- var process = CreateProcessPortable(RemotelyInvokable.ReadLineWithCustomEncodingWriteLineWithUtf8, Encoding.UTF32.WebName);
- process.StartInfo.RedirectStandardInput = true;
- // incorrect: the process will be writing in UTF-32
- process.StartInfo.StandardInputEncoding = Encoding.ASCII;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.StandardOutputEncoding = Encoding.UTF8;
- process.Start();
-
- const string TestLine = "\U0001f627\U0001f62e\U0001f62f";
- process.StandardInput.WriteLine(TestLine);
- process.StandardInput.Close();
-
- var output = process.StandardOutput.ReadLine();
- Assert.NotEqual(TestLine, output);
-
- Assert.True(process.WaitForExit(WaitInMS));
- Assert.Equal(RemotelyInvokable.SuccessExitCode, process.ExitCode);
- }
- }
-}
<Compile Include="ProcessWaitingTests.cs" />
<Compile Include="RemotelyInvokable.cs" />
<Compile Include="XunitAssemblyAttributes.cs" />
- <Compile Include="ProcessStartInfoTests.netcoreapp.cs" />
- <Compile Include="ProcessStreamReadTests.netcoreapp.cs" />
</ItemGroup>
<ItemGroup Condition="'$(TargetsWindows)' == 'true'">
<Compile Include="ProcessTests.Windows.cs" />
using System.IO;
using System.Reflection;
+using System.Reflection.Emit;
+using System.Linq;
+using Microsoft.DotNet.RemoteExecutor;
using Xunit;
namespace System.Diagnostics.TraceSourceTests
{
- public partial class DefaultTraceListenerClassTests : FileCleanupTestBase
+ public class DefaultTraceListenerClassTests : FileCleanupTestBase
{
private class TestDefaultTraceListener : DefaultTraceListener
{
listener.LogFileName = expectedLogFileName;
Assert.Equal(expectedLogFileName, listener.LogFileName);
}
+
+ [Fact]
+ public void EntryAssemblyName_Default_IncludedInTrace()
+ {
+ RemoteExecutor.Invoke(() =>
+ {
+ var listener = new TestDefaultTraceListener();
+ Trace.Listeners.Add(listener);
+ Trace.TraceError("hello world");
+ Assert.Equal(Assembly.GetEntryAssembly()?.GetName().Name + " Error: 0 : hello world", listener.Output.Trim());
+ }).Dispose();
+ }
+
+ [Fact]
+ public void EntryAssemblyName_Null_NotIncludedInTrace()
+ {
+ RemoteExecutor.Invoke(() =>
+ {
+ MakeAssemblyGetEntryAssemblyReturnNull();
+
+ var listener = new TestDefaultTraceListener();
+ Trace.Listeners.Add(listener);
+ Trace.TraceError("hello world");
+ Assert.Equal("Error: 0 : hello world", listener.Output.Trim());
+ }).Dispose();
+ }
+
+ /// <summary>
+ /// Makes Assembly.GetEntryAssembly() return null using private reflection.
+ /// </summary>
+ private static void MakeAssemblyGetEntryAssemblyReturnNull()
+ {
+ typeof(Assembly)
+ .GetField("s_forceNullEntryPoint", BindingFlags.NonPublic | BindingFlags.Static)
+ .SetValue(null, true);
+
+ Assert.Null(Assembly.GetEntryAssembly());
+ }
}
}
+++ /dev/null
-// 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 System.IO;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Linq;
-using Microsoft.DotNet.RemoteExecutor;
-using Xunit;
-
-namespace System.Diagnostics.TraceSourceTests
-{
- public partial class DefaultTraceListenerClassTests
- {
- [Fact]
- public void EntryAssemblyName_Default_IncludedInTrace()
- {
- RemoteExecutor.Invoke(() =>
- {
- var listener = new TestDefaultTraceListener();
- Trace.Listeners.Add(listener);
- Trace.TraceError("hello world");
- Assert.Equal(Assembly.GetEntryAssembly()?.GetName().Name + " Error: 0 : hello world", listener.Output.Trim());
- }).Dispose();
- }
-
- [Fact]
- public void EntryAssemblyName_Null_NotIncludedInTrace()
- {
- RemoteExecutor.Invoke(() =>
- {
- MakeAssemblyGetEntryAssemblyReturnNull();
-
- var listener = new TestDefaultTraceListener();
- Trace.Listeners.Add(listener);
- Trace.TraceError("hello world");
- Assert.Equal("Error: 0 : hello world", listener.Output.Trim());
- }).Dispose();
- }
-
- /// <summary>
- /// Makes Assembly.GetEntryAssembly() return null using private reflection.
- /// </summary>
- private static void MakeAssemblyGetEntryAssemblyReturnNull()
- {
- typeof(Assembly)
- .GetField("s_forceNullEntryPoint", BindingFlags.NonPublic | BindingFlags.Static)
- .SetValue(null, true);
-
- Assert.Null(Assembly.GetEntryAssembly());
- }
- }
-}
<Compile Include="TraceTestHelper.cs" />
<Compile Include="CorrelationManagerTests.cs" />
</ItemGroup>
- <ItemGroup Condition="'$(TargetsNetCoreApp)' == 'true'">
- <Compile Include="DefaultTraceListenerClassTests.netcoreapp.cs" />
- </ItemGroup>
</Project>
\ No newline at end of file