add more tests on native part
authorEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 13 Jul 2011 15:01:09 +0000 (19:01 +0400)
committerEugene.Petrenko <eugene.petrenko@gmail.com>
Wed, 13 Jul 2011 15:01:09 +0000 (19:01 +0400)
nuget-extensions/nuget-extensions.sln
nuget-extensions/nuget-runner/src/Program.cs
nuget-extensions/nuget-tests/Properties/AssemblyInfo.cs [new file with mode: 0644]
nuget-extensions/nuget-tests/nuget-tests.csproj [new file with mode: 0644]
nuget-extensions/nuget-tests/src/AssemblyHelper.cs [new file with mode: 0644]
nuget-extensions/nuget-tests/src/NuGet.cs [new file with mode: 0644]
nuget-extensions/nuget-tests/src/NuGetRunnerTest.cs [new file with mode: 0644]
nuget-extensions/nuget-tests/src/ProcessExecutor.cs [new file with mode: 0644]

index 5f9cfe944e32c39460c903b121cad1a1b3ba3e51..25eebb3606b0019f966bc78e01a54f1223de1645 100644 (file)
@@ -5,6 +5,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nuget-commands", "nuget-com
 EndProject\r
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nuget-runner", "nuget-runner\nuget-runner.csproj", "{B79E58CB-F8FD-4CD6-8B62-10EBA0DF592B}"\r
 EndProject\r
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "nuget-tests", "nuget-tests\nuget-tests.csproj", "{6D862627-466B-4CD1-82DE-E57B7B976EB6}"\r
+EndProject\r
 Global\r
        GlobalSection(SolutionConfigurationPlatforms) = preSolution\r
                Debug|Any CPU = Debug|Any CPU\r
@@ -35,6 +37,16 @@ Global
                {B79E58CB-F8FD-4CD6-8B62-10EBA0DF592B}.Release|Mixed Platforms.Build.0 = Release|x86\r
                {B79E58CB-F8FD-4CD6-8B62-10EBA0DF592B}.Release|x86.ActiveCfg = Release|x86\r
                {B79E58CB-F8FD-4CD6-8B62-10EBA0DF592B}.Release|x86.Build.0 = Release|x86\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Debug|Any CPU.Build.0 = Debug|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Debug|x86.ActiveCfg = Debug|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Release|Any CPU.ActiveCfg = Release|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Release|Any CPU.Build.0 = Release|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Release|Mixed Platforms.Build.0 = Release|Any CPU\r
+               {6D862627-466B-4CD1-82DE-E57B7B976EB6}.Release|x86.ActiveCfg = Release|Any CPU\r
        EndGlobalSection\r
        GlobalSection(SolutionProperties) = preSolution\r
                HideSolutionNode = FALSE\r
index d883be7cffe367bedbce8eeb0ee517ebf83bdd00..b8b3888475f2960f0c0b6abcff0ec02f7039d3bd 100644 (file)
@@ -16,7 +16,6 @@ namespace nuget_runner
       string[] nugetArgs = args.Skip(1).ToArray();\r
 \r
       var nugetAssembly = Assembly.LoadFrom(nuget);\r
-\r
       var result = nugetAssembly.EntryPoint.Invoke(null, new[] {nugetArgs});\r
 \r
       if (result is int)\r
diff --git a/nuget-extensions/nuget-tests/Properties/AssemblyInfo.cs b/nuget-extensions/nuget-tests/Properties/AssemblyInfo.cs
new file mode 100644 (file)
index 0000000..32db0c1
--- /dev/null
@@ -0,0 +1,36 @@
+using System.Reflection;\r
+using System.Runtime.CompilerServices;\r
+using System.Runtime.InteropServices;\r
+\r
+// General Information about an assembly is controlled through the following \r
+// set of attributes. Change these attribute values to modify the information\r
+// associated with an assembly.\r
+[assembly: AssemblyTitle("nuget-tests")]\r
+[assembly: AssemblyDescription("")]\r
+[assembly: AssemblyConfiguration("")]\r
+[assembly: AssemblyCompany("Microsoft")]\r
+[assembly: AssemblyProduct("nuget-tests")]\r
+[assembly: AssemblyCopyright("Copyright © Microsoft 2011")]\r
+[assembly: AssemblyTrademark("")]\r
+[assembly: AssemblyCulture("")]\r
+\r
+// Setting ComVisible to false makes the types in this assembly not visible \r
+// to COM components.  If you need to access a type in this assembly from \r
+// COM, set the ComVisible attribute to true on that type.\r
+[assembly: ComVisible(false)]\r
+\r
+// The following GUID is for the ID of the typelib if this project is exposed to COM\r
+[assembly: Guid("c2154a46-f923-4f8a-9347-4fac39ad0b33")]\r
+\r
+// Version information for an assembly consists of the following four values:\r
+//\r
+//      Major Version\r
+//      Minor Version \r
+//      Build Number\r
+//      Revision\r
+//\r
+// You can specify all the values or you can default the Build and Revision Numbers \r
+// by using the '*' as shown below:\r
+// [assembly: AssemblyVersion("1.0.*")]\r
+[assembly: AssemblyVersion("1.0.0.0")]\r
+[assembly: AssemblyFileVersion("1.0.0.0")]\r
diff --git a/nuget-extensions/nuget-tests/nuget-tests.csproj b/nuget-extensions/nuget-tests/nuget-tests.csproj
new file mode 100644 (file)
index 0000000..a952d59
--- /dev/null
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">\r
+  <PropertyGroup>\r
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>\r
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>\r
+    <ProductVersion>8.0.30703</ProductVersion>\r
+    <SchemaVersion>2.0</SchemaVersion>\r
+    <ProjectGuid>{6D862627-466B-4CD1-82DE-E57B7B976EB6}</ProjectGuid>\r
+    <OutputType>Library</OutputType>\r
+    <AppDesignerFolder>Properties</AppDesignerFolder>\r
+    <RootNamespace>JetBrains.TeamCity.NuGet.Tests</RootNamespace>\r
+    <AssemblyName>JetBrains.TeamCity.NuGet.Tests</AssemblyName>\r
+    <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>\r
+    <FileAlignment>512</FileAlignment>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">\r
+    <DebugSymbols>true</DebugSymbols>\r
+    <DebugType>full</DebugType>\r
+    <Optimize>false</Optimize>\r
+    <OutputPath>bin\Debug\</OutputPath>\r
+    <DefineConstants>DEBUG;TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">\r
+    <DebugType>pdbonly</DebugType>\r
+    <Optimize>true</Optimize>\r
+    <OutputPath>bin\Release\</OutputPath>\r
+    <DefineConstants>TRACE</DefineConstants>\r
+    <ErrorReport>prompt</ErrorReport>\r
+    <WarningLevel>4</WarningLevel>\r
+  </PropertyGroup>\r
+  <ItemGroup>\r
+    <Reference Include="NuGet">\r
+      <HintPath>..\lib\nuget\1.4\NuGet.exe</HintPath>\r
+    </Reference>\r
+    <Reference Include="nunit.framework">\r
+      <HintPath>..\lib\nunit\nunit.framework.dll</HintPath>\r
+    </Reference>\r
+    <Reference Include="System" />\r
+    <Reference Include="System.Core" />\r
+    <Reference Include="System.Xml.Linq" />\r
+    <Reference Include="System.Data.DataSetExtensions" />\r
+    <Reference Include="Microsoft.CSharp" />\r
+    <Reference Include="System.Data" />\r
+    <Reference Include="System.Xml" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="src\AssemblyHelper.cs" />\r
+    <Compile Include="src\NuGet.cs" />\r
+    <Compile Include="src\NuGetRunnerTest.cs" />\r
+    <Compile Include="Properties\AssemblyInfo.cs" />\r
+    <Compile Include="src\ProcessExecutor.cs" />\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <ProjectReference Include="..\nuget-commands\nuget-commands.csproj">\r
+      <Project>{8FA969EA-85C0-464E-9745-66B9820121A9}</Project>\r
+      <Name>nuget-commands</Name>\r
+    </ProjectReference>\r
+    <ProjectReference Include="..\nuget-runner\nuget-runner.csproj">\r
+      <Project>{B79E58CB-F8FD-4CD6-8B62-10EBA0DF592B}</Project>\r
+      <Name>nuget-runner</Name>\r
+    </ProjectReference>\r
+  </ItemGroup>\r
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />\r
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
+       Other similar extension points exist, see Microsoft.Common.targets.\r
+  <Target Name="BeforeBuild">\r
+  </Target>\r
+  <Target Name="AfterBuild">\r
+  </Target>\r
+  -->\r
+</Project>
\ No newline at end of file
diff --git a/nuget-extensions/nuget-tests/src/AssemblyHelper.cs b/nuget-extensions/nuget-tests/src/AssemblyHelper.cs
new file mode 100644 (file)
index 0000000..f5614c2
--- /dev/null
@@ -0,0 +1,24 @@
+using System;\r
+using System.IO;\r
+using System.Reflection;\r
+\r
+namespace JetBrains.TeamCity.NuGet.Tests\r
+{\r
+  public static class AssemblyHelper\r
+  {\r
+    public static string GetAssemblyDirectory(this Assembly assembly)\r
+    {\r
+      return Path.GetDirectoryName(GetAssemblyPath(assembly));\r
+    }\r
+\r
+    public static string GetAssemblyPath(this Assembly assembly)\r
+    {\r
+      return new Uri(assembly.CodeBase).LocalPath;\r
+    }\r
+\r
+    public static string GetAssemblyDirectory(this Type type)\r
+    {\r
+      return GetAssemblyDirectory(type.Assembly);\r
+    }\r
+  }\r
+}
\ No newline at end of file
diff --git a/nuget-extensions/nuget-tests/src/NuGet.cs b/nuget-extensions/nuget-tests/src/NuGet.cs
new file mode 100644 (file)
index 0000000..70b9818
--- /dev/null
@@ -0,0 +1,34 @@
+using System;\r
+using System.IO;\r
+\r
+namespace JetBrains.TeamCity.NuGet.Tests\r
+{\r
+  public static class NuGet\r
+  {\r
+    private static string ourCachedNuGetExe = null;\r
+    public static string NuGetPath\r
+    {\r
+      get\r
+      {\r
+        if (ourCachedNuGetExe != null) return ourCachedNuGetExe;\r
+\r
+        string path = typeof(NuGetRunnerTest).Assembly.GetAssemblyDirectory();\r
+\r
+        do\r
+        {\r
+          foreach (var probe in new[] { "nuget.exe", "lib/nuget/1.4/nuget.exe" })\r
+          {\r
+            string nuget = Path.Combine(path, probe);\r
+            if (File.Exists(nuget))\r
+              return ourCachedNuGetExe = nuget;\r
+          }\r
+\r
+          path = Path.GetDirectoryName(path);\r
+        } while (path != null);\r
+        throw new Exception("Failed to find NuGet.exe near project");\r
+      }\r
+\r
+    }\r
+\r
+  }\r
+}
\ No newline at end of file
diff --git a/nuget-extensions/nuget-tests/src/NuGetRunnerTest.cs b/nuget-extensions/nuget-tests/src/NuGetRunnerTest.cs
new file mode 100644 (file)
index 0000000..1c792d4
--- /dev/null
@@ -0,0 +1,19 @@
+using System;\r
+using System.Linq;\r
+using NUnit.Framework;\r
+\r
+namespace JetBrains.TeamCity.NuGet.Tests\r
+{\r
+  [TestFixture]\r
+  public class NuGetRunnerTest\r
+  {\r
+    [Test]\r
+    public void TestExcuteNuGet()\r
+    {\r
+      var r = ProcessExecutor.ExecuteProcess(NuGet.NuGetPath, "help");\r
+      Console.Out.WriteLine(r);\r
+\r
+      Assert.IsTrue(r.ExitCode == 0);\r
+    }\r
+  }\r
+}\r
diff --git a/nuget-extensions/nuget-tests/src/ProcessExecutor.cs b/nuget-extensions/nuget-tests/src/ProcessExecutor.cs
new file mode 100644 (file)
index 0000000..c2b47af
--- /dev/null
@@ -0,0 +1,75 @@
+using System;\r
+using System.Diagnostics;\r
+using System.IO;\r
+using System.Text;\r
+using System.Threading;\r
+\r
+namespace JetBrains.TeamCity.NuGet.Tests\r
+{\r
+  public static class ProcessExecutor\r
+  {\r
+    public static Result ExecuteProcess(string exe, params string[] args)\r
+    {\r
+      var pi = new ProcessStartInfo\r
+                 {\r
+                   FileName = exe,\r
+                   Arguments = string.Join(" ", args),\r
+                   RedirectStandardError = true,\r
+                   RedirectStandardOutput = true,\r
+                   RedirectStandardInput = true,\r
+                   UseShellExecute = false\r
+                 };\r
+\r
+      var process = Process.Start(pi);\r
+      process.StandardInput.Close();\r
+      Func<StreamReader, string> readOutput = stream =>\r
+                                                {\r
+                                                  var result = "";\r
+                                                  var th = new Thread(delegate()\r
+                                                                        {\r
+                                                                          var sb = new StringBuilder();\r
+                                                                          int i;\r
+                                                                          while ((i = stream.Read()) >= 0)\r
+                                                                            sb.Append((char) i);\r
+                                                                          result = sb.ToString();\r
+                                                                        })\r
+                                                             {Name = "Process output reader " + process.Id};\r
+                                                  th.Start();\r
+                                                  th.Join(TimeSpan.FromMinutes(10));\r
+                                                  return result;\r
+                                                };\r
+\r
+      string output = readOutput(process.StandardOutput);\r
+      string error = readOutput(process.StandardError);\r
+      process.WaitForExit();\r
+\r
+      return new Result(output, error, process.ExitCode);\r
+    }\r
+\r
+    public class Result\r
+    {\r
+      public string Output { get; private set; }\r
+      public string Error { get; private set; }\r
+      public int ExitCode { get; private set; }\r
+\r
+      public Result(string output, string error, int exitCode)\r
+      {\r
+        Output = output;\r
+        Error = error;\r
+        ExitCode = exitCode;\r
+      }\r
+\r
+      public override string ToString()\r
+      {\r
+        return new StringBuilder()\r
+          .AppendFormat("ExitCode: {0}\r\n", ExitCode)\r
+          .Append("Output:\n")\r
+          .Append(Output)\r
+          .Append("\n")\r
+          .Append("Error:\n")\r
+          .Append(Error)\r
+          .ToString();\r
+      }\r
+    }\r
+  }\r
+}
\ No newline at end of file