674b65debd7e1633b83cd1f215d912a6060f434b
[teamcity/dotNetPackagesSupport.git] / nuget-extensions / nuget-tests / src / NuGetRunnerWithTrunk.cs
1 using System;\r
2 using System.Collections.Generic;\r
3 using System.IO;\r
4 using System.Net;\r
5 using NUnit.Framework;\r
6 \r
7 namespace JetBrains.TeamCity.NuGet.Tests\r
8 {\r
9   [TestFixture("bt4")]\r
10   [TestFixture("bt22")]\r
11   [TestFixture("bt21")]  \r
12   public class NuGetRunnerWithTrunk\r
13   {\r
14     private readonly Lazy<string> home;\r
15     \r
16     private readonly Lazy<string> nuget;\r
17 \r
18     public NuGetRunnerWithTrunk(string bt)\r
19     {\r
20 \r
21       home = new Lazy<string>(() =>\r
22                                 {\r
23                                   var homePath = Path.GetTempFileName();\r
24                                   File.Delete(homePath);\r
25                                   Directory.CreateDirectory(homePath);\r
26                                   return homePath;\r
27                                 });\r
28       \r
29       nuget = new Lazy<string>(() =>\r
30                                  {\r
31                                    string url = "http://ci.nuget.org:8080/guestAuth/repository/download/" + bt +\r
32                                                 "/.lastSuccessful/Console/NuGet.exe";\r
33                                    var nugetPath = Path.Combine(home.Value, "NuGet.exe");\r
34                                    var cli = new WebClient();\r
35                                    cli.DownloadFile(url, nugetPath);\r
36                                    return nugetPath;\r
37                                  });\r
38       \r
39      \r
40     }\r
41 \r
42     [TestFixtureTearDown]\r
43     public void Cleanup()\r
44     {\r
45       if (home.IsValueCreated)\r
46       {\r
47         Directory.Delete(home.Value, true);\r
48       }\r
49     }\r
50 \r
51     [Test]\r
52     public void Test_Ping()\r
53     {\r
54       DoTest("TeamCity.Ping");\r
55     }\r
56 \r
57     [Test]\r
58     public void Test_List_NUnit_Remote()\r
59     {\r
60       DoTest("TeamCity.List", "-Id", "NUnit")\r
61         .AssertOutputContains("##teamcity[nuget-package Id='NUnit' Version='2.5.10.11092']");\r
62     }\r
63 \r
64     [Test]\r
65     public void Test_List_NUnit_Local()\r
66     {\r
67       DoTest("TeamCity.List", "-Id", "Web", "-Source", Files.LocalFeed)\r
68         .AssertOutputContains("##teamcity[nuget-package Id='Web' Version='1.1.1']");\r
69     }\r
70     \r
71     private ProcessExecutor.Result DoTest(params string[] argz)\r
72     {\r
73       var az = new List<string>();\r
74       az.Add(nuget.Value);\r
75       az.AddRange(argz);\r
76 \r
77       return ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, az.ToArray())\r
78         .Dump()\r
79         .AssertExitedSuccessfully();\r
80     }\r
81   }\r
82 }