-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jim Przybylinski
authored
Jul 31, 2017
1 parent
5581455
commit f45cec8
Showing
9 changed files
with
261 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
GoogleCloudExtension/GoogleCloudExtension.Utils.UnitTests/ProcessUtilsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System.ComponentModel; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Threading.Tasks; | ||
|
||
namespace GoogleCloudExtension.Utils.UnitTests | ||
{ | ||
[SuppressMessage("ReSharper", "UnassignedField.Global")] | ||
[SuppressMessage("ReSharper", "ClassNeverInstantiated.Global")] | ||
public class JsonDataClass | ||
{ | ||
public string Var; | ||
} | ||
|
||
[TestClass] | ||
[DeploymentItem(EchoAppName)] | ||
public class ProcessUtilsTests | ||
{ | ||
private const string ProcessOutput = "ProcessOutput"; | ||
private const string StdOutArgs = "-out " + ProcessOutput; | ||
private const string StdErrArgs = "-err " + ProcessOutput; | ||
private const string ExpArgs = "-exp " + ProcessOutput; | ||
private const string JsonArgs = "-out \"{\"" + nameof(JsonDataClass.Var) + "\":'" + ProcessOutput + "'}\""; | ||
private const string EchoAppName = "EchoApp.exe"; | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(Win32Exception))] | ||
public async Task GetCommandOutputAsync_TargetInvalid() | ||
{ | ||
await ProcessUtils.GetCommandOutputAsync("BadCommand.exe", StdOutArgs); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetCommandOutputAsync_StandardOutput() | ||
{ | ||
ProcessOutput output = await ProcessUtils.GetCommandOutputAsync(EchoAppName, StdOutArgs); | ||
|
||
Assert.IsTrue(output.Succeeded); | ||
Assert.AreEqual(ProcessOutput, output.StandardOutput); | ||
Assert.AreEqual(string.Empty, output.StandardError); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetCommandOutputAsync_StdErr() | ||
{ | ||
ProcessOutput output = await ProcessUtils.GetCommandOutputAsync(EchoAppName, StdErrArgs); | ||
|
||
Assert.IsTrue(output.Succeeded); | ||
Assert.AreEqual(string.Empty, output.StandardOutput); | ||
Assert.AreEqual(ProcessOutput, output.StandardError); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetCommandOutputAsync_Exp() | ||
{ | ||
ProcessOutput output = await ProcessUtils.GetCommandOutputAsync(EchoAppName, ExpArgs); | ||
|
||
Assert.IsFalse(output.Succeeded); | ||
Assert.AreEqual(ProcessOutput, output.StandardOutput); | ||
Assert.AreEqual(string.Empty, output.StandardError); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(Win32Exception))] | ||
public async Task GetJsonOutputAsync_InvalidTarget() | ||
{ | ||
await ProcessUtils.GetJsonOutputAsync<string>("BadTarget.exe", StdOutArgs); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(JsonOutputException))] | ||
public async Task GetJsonOutputAsync_ProcessError() | ||
{ | ||
await ProcessUtils.GetJsonOutputAsync<string>(EchoAppName, ExpArgs); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(JsonOutputException))] | ||
public async Task GetJsonOutputAsync_InvalidJson() | ||
{ | ||
await ProcessUtils.GetJsonOutputAsync<string>(EchoAppName, StdOutArgs); | ||
} | ||
|
||
[TestMethod] | ||
public async Task GetJsonOutputAsync_Success() | ||
{ | ||
JsonDataClass output = await ProcessUtils.GetJsonOutputAsync<JsonDataClass>(EchoAppName, JsonArgs); | ||
|
||
Assert.IsNotNull(output); | ||
Assert.IsNotNull(output.Var); | ||
Assert.AreEqual(ProcessOutput, output.Var); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<configuration> | ||
<startup> | ||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> | ||
</startup> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{108901A6-861D-4021-A2C9-CE93554A26F5}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>EchoApp</RootNamespace> | ||
<AssemblyName>EchoApp</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<PlatformTarget>AnyCPU</PlatformTarget> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="App.config" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace EchoApp | ||
{ | ||
public static class Program | ||
{ | ||
public static int Main(string[] args) | ||
{ | ||
if (args.Length > 1) | ||
{ | ||
string flag = args[0]; | ||
string message = string.Join(" ", args.Skip(1)); | ||
if (flag.Equals("-out", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Console.Write(message); | ||
return 0; | ||
} | ||
else if (flag.Equals("-err", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Console.Error.Write(message); | ||
return 0; | ||
} | ||
else if (flag.Equals("-exp", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
Console.Write(message); | ||
return 1; | ||
} | ||
} | ||
return -1; | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
GoogleCloudExtension/TestProjects/EchoApp/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("EchoApp")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("")] | ||
[assembly: AssemblyProduct("EchoApp")] | ||
[assembly: AssemblyCopyright("Copyright © 2017")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("108901a6-861d-4021-a2c9-ce93554a26f5")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |