fix concurrent starts of NuGet.exe'
[teamcity/dotNetPackagesSupport.git] / nuget-extensions / nuget-tests / src / NuGetRunnerTest.cs
1 ´╗┐using System;\r
2 using System.IO;\r
3 using System.Threading;\r
4 using NUnit.Framework;\r
5 using System.Linq;\r
6 \r
7 namespace JetBrains.TeamCity.NuGet.Tests\r
8 {\r
9   [TestFixture]\r
10   public class NuGetRunnerTest\r
11   {\r
12     [Test]\r
13     public void TestExcuteNuGet()\r
14     {\r
15       var r = ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, Files.NuGetExe, "help");\r
16       Console.Out.WriteLine(r);\r
17 \r
18       Assert.IsTrue(r.ExitCode == 0);\r
19     }\r
20 \r
21     [Test]\r
22     public void TestExcuteNuGet_NuGetFromTemp()\r
23     {\r
24       TempFilesHolder.WithTempDirectory(\r
25         home =>\r
26           {\r
27             var destNuGet = Path.Combine(home, "NuGet.exe");\r
28             File.Copy(Files.NuGetExe, destNuGet);\r
29 \r
30             ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, destNuGet, "TeamCity.Ping")\r
31               .Dump()\r
32               .AssertExitedSuccessfully();\r
33           });\r
34     }\r
35 \r
36     [Test]\r
37     public void TestExcuteNuGet_BothInTemp()\r
38     {\r
39       TempFilesHolder.WithTempDirectory(\r
40         home =>\r
41           {\r
42             var destNuGet = Path.Combine(home, "NuGet.exe");\r
43             var destRunner = Path.Combine(home, "TeamCity.NuGetRunner.exe");\r
44             \r
45             File.Copy(Files.NuGetExe, destNuGet);            \r
46             File.Copy(Files.NuGetRunnerExe, destRunner);\r
47             const string ext = "JetBrains.TeamCity.NuGet.ExtendedCommands.dll";\r
48             File.Copy(Path.Combine(Files.NuGetRunnerExe, "../" + ext), Path.Combine(home, ext));\r
49 \r
50             ProcessExecutor.ExecuteProcess(destRunner, destNuGet, "TeamCity.Ping")\r
51               .Dump()\r
52               .AssertExitedSuccessfully();\r
53           });\r
54     }\r
55 \r
56 \r
57     [Test]\r
58     public void TestDumpExtensionsPath()\r
59     {\r
60       var r = ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, Files.NuGetExe, "---TeamCity.DumpExtensionsPath");\r
61       Console.Out.WriteLine(r);\r
62 \r
63       Assert.IsTrue(r.ExitCode == 0);\r
64     }\r
65 \r
66     [Test]\r
67     public void TestCommand_TeamCityPing()\r
68     {\r
69       ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, Files.NuGetExe, "TeamCity.Ping")\r
70         .Dump()\r
71         .AssertExitedSuccessfully()\r
72         .AssertNoErrorOutput()\r
73         .AssertOutputContains("TeamCity NuGet Extension is available.");\r
74     }\r
75 \r
76     [Test]\r
77     public void TestCommands_RunConcurrently()\r
78     {\r
79       bool failed = false;\r
80       new[] {1, 2, 3, 4, 5, 6, 7}\r
81         .Select(\r
82           x => new Thread(() =>\r
83                             {\r
84                               for (int i = 0; i < 3; i++)\r
85                               {\r
86                                 var proc = ProcessExecutor.ExecuteProcess(Files.NuGetRunnerExe, Files.NuGetExe, "TeamCity.Ping", "-Sleep");\r
87                                 if (proc.ExitCode != 0 || !string.IsNullOrWhiteSpace(proc.Error))\r
88                                 {\r
89                                   proc.Dump();\r
90                                   failed = true;\r
91                                 }\r
92                                 proc.AssertNoErrorOutput().AssertExitedSuccessfully();\r
93                               }\r
94                             })\r
95                  {\r
96                    Name = "Checker " + x,\r
97                  })\r
98         .ToList()\r
99         .Select(\r
100           x =>\r
101             {\r
102               x.Start();\r
103               return x;\r
104             })\r
105         .ToList()\r
106         .Select(x =>\r
107                   {\r
108                     x.Join();\r
109                     return 0;\r
110                   })\r
111         .ToList();\r
112 \r
113       Assert.IsFalse(failed);\r
114     }\r
115 \r
116   }\r
117 }\r