forked from chriseldredge/Klondike
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.proj
203 lines (170 loc) · 8.91 KB
/
test.proj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Test" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<UseIISExpress Condition=" '$(HttpUrl)' == '' ">true</UseIISExpress>
<UseIISExpress Condition=" '$(UseIISExpress)' == '' ">false</UseIISExpress>
<HttpPort>10080</HttpPort>
<HttpUrl>http://localhost:$(HttpPort)/</HttpUrl>
<TestCaseTargets Condition="'$(TestCase)' != ''">$(TestCase)</TestCaseTargets>
<TestCaseTargets Condition="'$(TestCaseTargets)' == ''">RunEachTest</TestCaseTargets>
<CleanAppDataAfterTests>true</CleanAppDataAfterTests>
<SolutionDir>$(MSBuildProjectDirectory)\..\app\</SolutionDir>
<CurlCommand>curl -s -o out.txt --write-out "%25%25{http_code}"</CurlCommand>
</PropertyGroup>
<Import Project="..\NuGet.targets" />
<Target Name="Test" DependsOnTargets="StartIISExpress">
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CleanAppData" Properties="Phase=BeforeTest"/>
<CallTarget Targets="$(TestCaseTargets)"/>
<CallTarget Targets="CleanUp" />
<OnError ExecuteTargets="CleanUp"/>
</Target>
<Target Name="CleanUp" DependsOnTargets="StopIISExpress">
<MSBuild Projects="$(MSBuildThisFileFullPath)" Targets="CleanAppData" Properties="Phase=AfterTest" Condition="$(CleanAppDataAfterTests)"/>
</Target>
<Target Name="RunEachTest">
<CallTarget RunEachTargetSeparately="true"
Targets="
Test_PutPackage;
Test_InstallPackageFromMirror;
Test_RestorePackageFromMirror;
Test_Session_UserIsLocalAdministratorOnLocalhost;
Test_Session_InvalidApiKey_Unauthorized;
Test_OData_Filter_IdOrTitle_ToLowerContains;
Test_OData_Filter_DateTime;
"/>
</Target>
<Target Name="Test_PutPackage">
<PropertyGroup>
<PackagePath>$(SolutionDir)packages\Microsoft.Bcl.Build.1.0.13\Microsoft.Bcl.Build.1.0.13.nupkg</PackagePath>
</PropertyGroup>
<Error Text="Sample package not found at $(PackagePath)" Condition="!Exists('$(PackagePath)')"/>
<Exec Command="$(NuGetCommand) push "$(PackagePath)" -Source $(HttpUrl) -NonInteractive"/>
</Target>
<Target Name="Test_InstallPackageFromMirror">
<PropertyGroup>
<WorkDir>$(MSBuildProjectDirectory)\tmp</WorkDir>
</PropertyGroup>
<MakeDir Directories="$(WorkDir)"/>
<Exec Command="$(NuGetCommand) install NuGet.Core -Source $(HttpUrl)"
WorkingDirectory="$(WorkDir)"/>
<CallTarget Targets="Clean_InstallPackageFromMirror" />
<OnError ExecuteTargets="Clean_InstallPackageFromMirror"/>
</Target>
<Target Name="Clean_InstallPackageFromMirror">
<PropertyGroup>
<WorkDir>$(MSBuildProjectDirectory)\tmp</WorkDir>
</PropertyGroup>
<Exec Command="rd /s /q "$(WorkDir)"" Condition="Exists('$(WorkDir)')"/>
</Target>
<Target Name="Test_RestorePackageFromMirror">
<PropertyGroup>
<WorkDir>$(MSBuildProjectDirectory)\tmp</WorkDir>
<NuGetCacheDir>$(LocalAppData)\NuGet\Cache</NuGetCacheDir>
</PropertyGroup>
<MakeDir Directories="$(WorkDir)"/>
<WriteLinesToFile File="$(WorkDir)\packages.config" Overwrite="true" Lines="<packages><package id="NuGet.Server" version="2.7.2"/></packages>"/>
<Exec Command="$(NuGetCommand) restore -Source $(HttpUrl) -PackagesDirectory . -NonInteractive"
WorkingDirectory="$(WorkDir)"/>
<CallTarget Targets="Clean_RestorePackageFromMirror" />
<OnError ExecuteTargets="Clean_RestorePackageFromMirror"/>
</Target>
<Target Name="Clean_RestorePackageFromMirror">
<PropertyGroup>
<WorkDir>$(MSBuildProjectDirectory)\tmp</WorkDir>
</PropertyGroup>
<Exec Command="rd /s /q "$(WorkDir)"" Condition="Exists('$(WorkDir)')"/>
</Target>
<Target Name="Test_Session_UserIsLocalAdministratorOnLocalhost">
<Exec Command="$(CurlCommand) $(HttpUrl)api/session" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="HttpStatusCode"/>
</Exec>
<Error Text="Expected 200, was $(HttpStatusCode)" Condition=" '$(HttpStatusCode)' != '200' " />
</Target>
<Target Name="Test_Session_InvalidApiKey_Unauthorized">
<Exec Command="$(CurlCommand) $(HttpUrl)api/session -H 'X-NuGet-ApiKey: nonesuch'" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="HttpStatusCode"/>
</Exec>
<Error Text="Expected 401, was $(HttpStatusCode)" Condition=" '$(HttpStatusCode)' != '401' " />
</Target>
<Target Name="Test_OData_Filter_IdOrTitle_ToLowerContains">
<Exec Command="$(CurlCommand) "$(HttpUrl)api/odata/Packages()?$filter=(substringof('bcl',tolower(Id))+or+Title+ne+null+and+substringof('bcl',tolower(Title)))+and+(IsLatestVersion+or+IsAbsoluteLatestVersion)&$select=Id,Version
" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="HttpStatusCode"/>
</Exec>
<Error Text="Expected 200, was $(HttpStatusCode)" Condition=" '$(HttpStatusCode)' != '200' " />
</Target>
<Target Name="Test_OData_Filter_DateTime">
<Exec Command="$(CurlCommand) "$(HttpUrl)api/odata/Packages()?$filter=Published+lt+datetime'2014-01-01T12:20:01'" ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="HttpStatusCode"/>
</Exec>
<Error Text="Expected 200, was $(HttpStatusCode)" Condition=" '$(HttpStatusCode)' != '200' " />
</Target>
<!-- test cases:
put package to http://example/api/odata
delete with same
list http://example/api/odata
list mirrored packages
mirror package with nuget restore
mirror package with nuget install
create user with roles
delete user
cannot create user when using api key without admin role
cannot see api key for other users without admin role
can see own api key without admin role
can change own api key without admin role
-->
<Target Name="CleanAppData">
<ItemGroup>
<AppData Include="$(DistDir)\App_Data\**\*"/>
</ItemGroup>
<Message Text="Cleaning AppData files"/>
<Delete Files="@(AppData)"/>
</Target>
<Target Name="StartIISExpress" Condition="$(UseIISExpress)">
<Error Message="DistDir property must be specified." Condition=" '$(DistDir)' == '' "/>
<Error Message="DistDir path $(DistDir) does not exist." Condition="!Exists('$(DistDir)')"/>
<Message Text="Starting iisexpress in $(DistDir) port $(HttpPort)."/>
<StartProcess
Command="c:\Program Files\IIS Express\iisexpress.exe"
Arguments="/clr:v4.0 /port:$(HttpPort) /path:"$(DistDir.TrimEnd('\'))"">
<Output TaskParameter="ProcessId" PropertyName="IISExpressPid"/>
</StartProcess>
<Message Text="Started pid $(IISExpressPid)."/>
</Target>
<Target Name="StopIISExpress" Condition=" '$(IISExpressPid)' != '' ">
<Message Text="Stopping IIS Express PID $(IISExpressPid)."/>
<StopProcess ProcessId="$(IISExpressPid)"/>
</Target>
<UsingTask TaskName="StartProcess" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<Command Required="true" />
<Arguments Required="false" />
<WorkingDirectory Required="false" />
<ProcessId ParameterType="System.Int32" Output="true" />
</ParameterGroup>
<Task>
<Reference Include="System"/>
<Using Namespace="System.Diagnostics"/>
<Code Type="Fragment" Language="cs">
var startup = new ProcessStartInfo(Command, Arguments);
startup.WorkingDirectory = WorkingDirectory;
startup.UseShellExecute = false;
var process = Process.Start(startup);
ProcessId = process.Id;
</Code>
</Task>
</UsingTask>
<UsingTask TaskName="StopProcess" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll">
<ParameterGroup>
<ProcessId ParameterType="System.Int32" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="System"/>
<Using Namespace="System.Diagnostics"/>
<Code Type="Fragment" Language="cs">
Process.GetProcessById(ProcessId).Kill();
</Code>
</Task>
</UsingTask>
</Project>