@@ -40,6 +40,8 @@ public static void DoDeployment(TestContext context) {
4040
4141 [ TestInitialize ]
4242 public void CloseRunningIisExpress ( ) {
43+ PythonVersion . AssertInstalled ( ) ;
44+
4345 IEnumerable < Process > running ;
4446 while ( ( running = Process . GetProcessesByName ( "iisexpress" ) ) . Any ( ) ) {
4547 foreach ( var p in running ) {
@@ -64,30 +66,11 @@ public void CloseRunningIisExpress() {
6466 }
6567 }
6668
67- [ TestMethod , Priority ( 0 ) ]
68- public void DjangoNewApp ( ) {
69- using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoApplication.settings" ) ) {
70- site . StartServer ( ) ;
71-
72- CopyDir ( "TestData" , site . SiteDir ) ;
73-
74- var response = site . Request ( "" ) ;
75- Console . WriteLine ( response . ContentType ) ;
76- var stream = response . GetResponseStream ( ) ;
77- var content = new StreamReader ( stream ) . ReadToEnd ( ) ;
78- Console . WriteLine ( content ) ;
79-
80- Assert . IsTrue ( content . IndexOf ( "Welcome to Django" ) != - 1 , "Expected \" Welcome to Django\" .\r \n Actual:\r \n " + content ) ;
81- }
82- }
83-
8469 [ TestMethod , Priority ( 0 ) ]
8570 public void DjangoHelloWorld ( ) {
8671 using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
8772 site . StartServer ( ) ;
8873
89- CopyDir ( "TestData" , site . SiteDir ) ;
90-
9174 var response = site . Request ( "" ) ;
9275 Console . WriteLine ( response . ContentType ) ;
9376 var stream = response . GetResponseStream ( ) ;
@@ -121,12 +104,8 @@ public void ConfigVariables() {
121104 [ TestMethod , Priority ( 0 ) ]
122105 public void LargeResponse ( ) {
123106 using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
124- File . Copy ( "TestData\\ DjangoTestApp\\ web.config" , Path . Combine ( site . SiteDir , "web.config" ) ) ;
125-
126107 site . StartServer ( ) ;
127108
128- CopyDir ( "TestData" , site . SiteDir ) ;
129-
130109 var response = site . Request ( "large_response" ) ;
131110 Console . WriteLine ( response . ContentType ) ;
132111 var stream = response . GetResponseStream ( ) ;
@@ -151,8 +130,6 @@ public void DjangoHelloWorldParallel() {
151130 using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
152131 site . StartServer ( ) ;
153132
154- CopyDir ( "TestData" , site . SiteDir ) ;
155-
156133 const int threadCnt = 12 ;
157134 const int requests = 1000 ;
158135 var tasks = new Task [ threadCnt ] ;
@@ -180,8 +157,6 @@ public void DjangoHelloWorldParallel() {
180157 [ TestMethod , Priority ( 0 ) ]
181158 public void CustomHandler ( ) {
182159 using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.handler" ) ) {
183- CopyDir ( "TestData" , site . SiteDir ) ;
184-
185160 site . StartServer ( ) ;
186161
187162 var response = site . Request ( "" ) ;
@@ -196,8 +171,6 @@ public void CustomHandler() {
196171 [ TestMethod , Priority ( 0 ) ]
197172 public void CustomCallableHandler ( ) {
198173 using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.callable_handler()" ) ) {
199- CopyDir ( "TestData" , site . SiteDir ) ;
200-
201174 site . StartServer ( ) ;
202175
203176 var response = site . Request ( "" ) ;
@@ -210,8 +183,6 @@ public void CustomCallableHandler() {
210183 [ TestMethod , Priority ( 0 ) ]
211184 public void ErrorHandler ( ) {
212185 using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.error_handler" ) ) {
213- CopyDir ( "TestData" , site . SiteDir ) ;
214-
215186 site . StartServer ( ) ;
216187 try {
217188 var response = site . Request ( "" ) ;
@@ -246,7 +217,7 @@ private static string CreateSite() {
246217 public static void ConfigureIIS ( string appCmd , string appHostConfig , string python , string wfastcgi , Dictionary < string , string > envVars ) {
247218 using ( var p = ProcessOutput . RunHiddenAndCapture (
248219 appCmd , "set" , "config" , "/section:system.webServer/fastCGI" ,
249- string . Format ( "/+[fullPath='{0}', arguments='\" \" \" {1}\" \" \" ']" , python , wfastcgi ) ,
220+ string . Format ( "/+[fullPath='{0}', arguments='\" {1}\" ']" , python , wfastcgi ) ,
250221 "/AppHostConfig:" + appHostConfig
251222 ) ) {
252223 p . Wait ( ) ;
@@ -257,7 +228,7 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
257228 using ( var p = ProcessOutput . RunHiddenAndCapture (
258229 appCmd , "set" , "config" , "/section:system.webServer/handlers" ,
259230 string . Format (
260- "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='{0}|\" \" \" {1}\" \" \" ',resourceType='Unspecified']" ,
231+ "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='{0}|\" {1}\" ',resourceType='Unspecified']" ,
261232 python , wfastcgi
262233 ) ,
263234 "/AppHostConfig:" + appHostConfig
@@ -269,9 +240,9 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
269240
270241 foreach ( var keyValue in envVars ) {
271242 using ( var p = ProcessOutput . RunHiddenAndCapture (
272- appCmd , "set" , "config" , "- section:system.webServer/fastCgi" ,
243+ appCmd , "set" , "config" , "/ section:system.webServer/fastCgi" ,
273244 string . Format (
274- "/+\" [fullPath='{0}', arguments='\" \" \" {1}\" \" \" '].environmentVariables.[name='{2}',value='{3}']" ,
245+ "/+[fullPath='{0}', arguments='\" {1}\" '].environmentVariables.[name='{2}',value='{3}']" ,
275246 python , wfastcgi , keyValue . Key , keyValue . Value
276247 ) ,
277248 "/commit:apphost" ,
@@ -296,6 +267,7 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
296267 }
297268
298269 private static void DumpOutput ( ProcessOutput process ) {
270+ Console . WriteLine ( process . Arguments ) ;
299271 foreach ( var line in process . StandardOutputLines ) {
300272 Console . WriteLine ( line ) ;
301273 }
@@ -334,9 +306,15 @@ private static WebSite ConfigureIISForDjango(string appCmd, string python, strin
334306 { "PYTHONPATH" , "" } ,
335307 { "WSGI_HANDLER" , "django.core.handlers.wsgi.WSGIHandler()" }
336308 }
309+ ) ;
337310
311+ var module = djangoSettings . Split ( new [ ] { '.' } , 2 ) [ 0 ] ;
312+ FileUtils . CopyDirectory (
313+ TestData . GetPath ( Path . Combine ( "TestData" , "WFastCgi" , module ) ) ,
314+ Path . Combine ( site , module )
338315 ) ;
339316
317+
340318 Console . WriteLine ( "Site created at {0}" , site ) ;
341319 return new WebSite ( site ) ;
342320 }
@@ -354,16 +332,33 @@ private static WebSite ConfigureIISForCustomHandler(string appCmd, string python
354332 { "WSGI_HANDLER" , handler } ,
355333 { "WSGI_LOG" , Path . Combine ( site , "log.txt" ) }
356334 }
357-
358335 ) ;
359336
337+ var module = handler . Split ( new [ ] { '.' } , 2 ) [ 0 ] ;
338+ try {
339+ File . Copy (
340+ TestData . GetPath ( "TestData\\ WFastCGI\\ " + module + ".py" ) ,
341+ Path . Combine ( site , module + ".py" ) ,
342+ true
343+ ) ;
344+ } catch ( IOException ex ) {
345+ Console . WriteLine ( "Failed to copy {0}.py: {1}" , module , ex ) ;
346+ }
347+
348+
360349 Console . WriteLine ( "Site created at {0}" , site ) ;
361350 return new WebSite ( site ) ;
362351 }
363352
364- public virtual string InterpreterPath {
353+ public virtual PythonVersion PythonVersion {
365354 get {
366- return PythonPaths . Python27 . InterpreterPath ;
355+ return PythonPaths . Python27 ?? PythonPaths . Python27_x64 ;
356+ }
357+ }
358+
359+ public string InterpreterPath {
360+ get {
361+ return PythonVersion . InterpreterPath ;
367362 }
368363 }
369364
@@ -376,21 +371,6 @@ public virtual string AppCmdPath {
376371 }
377372 }
378373
379- private static void CopyDir ( string source , string target ) {
380- foreach ( var dir in Directory . GetDirectories ( source ) ) {
381- var targetDir = Path . Combine ( target , Path . GetFileName ( dir ) ) ;
382- //Console.WriteLine("Creating dir: {0}", targetDir);
383- Directory . CreateDirectory ( targetDir ) ;
384- CopyDir ( dir , targetDir ) ;
385- }
386-
387- foreach ( var file in Directory . GetFiles ( source ) ) {
388- var targetFile = Path . Combine ( target , Path . GetFileName ( file ) ) ;
389- //Console.WriteLine("Deploying: {0} -> {1}", file, targetFile);
390- File . Copy ( file , targetFile ) ;
391- }
392- }
393-
394374 class WebSite : IDisposable {
395375 private readonly string _dir ;
396376 private ProcessOutput _process ;
@@ -420,8 +400,13 @@ public void StartServer() {
420400 public WebResponse Request ( string uri ) {
421401 WebRequest req = WebRequest . Create (
422402 "http://localhost:8181/" + uri
423- ) ;
424- return req . GetResponse ( ) ;
403+ ) ;
404+ try {
405+ return req . GetResponse ( ) ;
406+ } catch ( WebException ex ) {
407+ Console . WriteLine ( new StreamReader ( ex . Response . GetResponseStream ( ) ) . ReadToEnd ( ) ) ;
408+ throw ;
409+ }
425410 }
426411
427412 public void StopServer ( ) {
@@ -580,7 +565,7 @@ public void TestEnvironment() {
580565 [ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
581566 public void TestFileSystemChanges ( ) {
582567 var location = TestData . GetTempPath ( randomSubPath : true ) ;
583- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChanges" ) , location ) ;
568+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChanges" ) , location ) ;
584569
585570 IisExpressTest (
586571 location ,
@@ -609,7 +594,7 @@ public void TestFileSystemChanges() {
609594 [ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
610595 public void TestFileSystemChangesPackage ( ) {
611596 var location = TestData . GetTempPath ( randomSubPath : true ) ;
612- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesPackage" ) , location ) ;
597+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesPackage" ) , location ) ;
613598
614599 IisExpressTest (
615600 location ,
@@ -633,7 +618,7 @@ public void TestFileSystemChangesPackage() {
633618 [ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
634619 public void TestFileSystemChangesCustomRegex ( ) {
635620 var location = TestData . GetTempPath ( randomSubPath : true ) ;
636- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesCustomRegex" ) , location ) ;
621+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesCustomRegex" ) , location ) ;
637622
638623 IisExpressTest (
639624 location ,
@@ -655,7 +640,7 @@ public void TestFileSystemChangesCustomRegex() {
655640 [ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
656641 public void TestFileSystemChangesDisabled ( ) {
657642 var location = TestData . GetTempPath ( randomSubPath : true ) ;
658- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesDisabled" ) , location ) ;
643+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesDisabled" ) , location ) ;
659644
660645 IisExpressTest (
661646 location ,
@@ -1060,6 +1045,7 @@ public static implicit operator Action(GetAndValidateErrorUrl self) {
10601045 }
10611046
10621047 private Action CollectStaticFiles ( string location ) {
1048+ location = TestData . GetPath ( location ) ;
10631049 return ( ) => {
10641050 using ( var p = ProcessOutput . Run (
10651051 InterpreterPath ,
@@ -1168,7 +1154,7 @@ params Action[] actions
11681154 IisExpressPath ,
11691155 new [ ] { "/config:" + appConfig , "/site:WebSite1" , "/systray:false" , "/trace:info" } ,
11701156 null ,
1171- new [ ] { new KeyValuePair < string , string > ( "WSGI_LOG" , Path . Combine ( location , "log.txt" ) ) } ,
1157+ env ,
11721158 false ,
11731159 new OutputRedirector ( "IIS" )
11741160 ) ) {
@@ -1205,7 +1191,8 @@ public override void WriteErrorLine(string line) {
12051191
12061192 private static string IisExpressPath {
12071193 get {
1208- var iisExpressPath = Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 8.0" , "InstallPath" , null ) as string ;
1194+ var iisExpressPath = Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 10.0" , "InstallPath" , null ) as string ??
1195+ Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 8.0" , "InstallPath" , null ) as string ;
12091196 if ( iisExpressPath == null ) {
12101197 Assert . Inconclusive ( "Can't find IIS Express" ) ;
12111198 return null ;
0 commit comments