22// The .NET Foundation licenses this file to you under the MIT license.
33// See the LICENSE file in the project root for more information.
44
5+ using Microsoft . DotNet . Cli . Build ;
56using Microsoft . DotNet . Cli . Build . Framework ;
67using System ;
78using System . Diagnostics ;
@@ -249,7 +250,7 @@ public void AppHost_FrameworkDependent_Succeeds()
249250 var appExe = fixture . TestProject . AppExe ;
250251 File . Copy ( sharedTestState . BuiltAppHost , appExe , overwrite : true ) ;
251252 AppHostExtensions . BindAppHost ( appExe ) ;
252-
253+
253254 // Get the framework location that was built
254255 string builtDotnet = fixture . BuiltDotnet . BinPath ;
255256
@@ -348,6 +349,61 @@ public void ComputedTPADoesntEndWithPathSeparator()
348349 . And . HaveStdErrMatching ( $ "Property TRUSTED_PLATFORM_ASSEMBLIES = .*[^{ Path . PathSeparator } ]$", System . Text . RegularExpressions . RegexOptions . Multiline ) ;
349350 }
350351
352+ [ Theory ]
353+ [ InlineData ( true ) ]
354+ [ InlineData ( false ) ]
355+ public void MissingRuntimeConfig_Fails ( bool useAppHost )
356+ {
357+ Command command ;
358+ if ( useAppHost )
359+ {
360+ command = Command . Create ( sharedTestState . MockApp . AppExe )
361+ . DotNetRoot ( sharedTestState . BuiltDotNet . BinPath ) ;
362+ }
363+ else
364+ {
365+ command = sharedTestState . BuiltDotNet . Exec ( sharedTestState . MockApp . AppDll ) ;
366+ }
367+
368+ string hostPolicyName = RuntimeInformationExtensions . GetSharedLibraryFileNameForCurrentPlatform ( "hostpolicy" ) ;
369+ command . EnableTracingAndCaptureOutputs ( )
370+ . MultilevelLookup ( false )
371+ . Execute ( )
372+ . Should ( ) . Fail ( )
373+ . And . HaveStdErrContaining ( $ "The library '{ hostPolicyName } ' required to execute the application was not found")
374+ . And . HaveStdErrContaining ( "Failed to run as a self-contained app" )
375+ . And . HaveStdErrContaining ( $ "'{ sharedTestState . MockApp . RuntimeConfigJson } ' was not found") ;
376+ }
377+
378+ [ Theory ]
379+ [ InlineData ( true ) ]
380+ [ InlineData ( false ) ]
381+ public void MissingFrameworkInRuntimeConfig_Fails ( bool useAppHost )
382+ {
383+ TestApp app = sharedTestState . MockApp . Copy ( ) ;
384+ RuntimeConfig . FromFile ( app . RuntimeConfigJson ) . Save ( ) ;
385+
386+ Command command ;
387+ if ( useAppHost )
388+ {
389+ command = Command . Create ( app . AppExe )
390+ . DotNetRoot ( sharedTestState . BuiltDotNet . BinPath ) ;
391+ }
392+ else
393+ {
394+ command = sharedTestState . BuiltDotNet . Exec ( app . AppDll ) ;
395+ }
396+
397+ string hostPolicyName = RuntimeInformationExtensions . GetSharedLibraryFileNameForCurrentPlatform ( "hostpolicy" ) ;
398+ command . EnableTracingAndCaptureOutputs ( )
399+ . MultilevelLookup ( false )
400+ . Execute ( )
401+ . Should ( ) . Fail ( )
402+ . And . HaveStdErrContaining ( $ "The library '{ hostPolicyName } ' required to execute the application was not found")
403+ . And . HaveStdErrContaining ( "Failed to run as a self-contained app" )
404+ . And . HaveStdErrContaining ( $ "'{ app . RuntimeConfigJson } ' did not specify a framework") ;
405+ }
406+
351407 [ Theory ]
352408 [ InlineData ( true ) ]
353409 [ InlineData ( false ) ]
@@ -459,7 +515,7 @@ public void AppHost_GUI_FrameworkDependent_DisabledGUIErrors_DialogNotShown()
459515
460516 var fixture = sharedTestState . PortableAppFixture_Built
461517 . Copy ( ) ;
462-
518+
463519 string appExe = fixture . TestProject . AppExe ;
464520 File . Copy ( sharedTestState . BuiltAppHost , appExe , overwrite : true ) ;
465521 AppHostExtensions . BindAppHost ( appExe ) ;
@@ -579,13 +635,18 @@ public class SharedTestState : IDisposable
579635 {
580636 public TestProjectFixture PortableAppFixture_Built { get ; }
581637 public TestProjectFixture PortableAppFixture_Published { get ; }
638+
582639 public RepoDirectoriesProvider RepoDirectories { get ; }
583640 public string BuiltAppHost { get ; }
641+ public DotNetCli BuiltDotNet { get ; }
642+
643+ public TestApp MockApp { get ; }
584644
585645 public SharedTestState ( )
586646 {
587647 RepoDirectories = new RepoDirectoriesProvider ( ) ;
588648 BuiltAppHost = Path . Combine ( RepoDirectories . HostArtifacts , RuntimeInformationExtensions . GetExeFileNameForCurrentPlatform ( "apphost" ) ) ;
649+ BuiltDotNet = new DotNetCli ( RepoDirectories . BuiltDotnet ) ;
589650
590651 PortableAppFixture_Built = new TestProjectFixture ( "PortableApp" , RepoDirectories )
591652 . EnsureRestored ( RepoDirectories . CorehostPackages )
@@ -594,12 +655,19 @@ public SharedTestState()
594655 PortableAppFixture_Published = new TestProjectFixture ( "PortableApp" , RepoDirectories )
595656 . EnsureRestored ( RepoDirectories . CorehostPackages )
596657 . PublishProject ( ) ;
658+
659+ MockApp = new TestApp ( SharedFramework . CalculateUniqueTestDirectory ( Path . Combine ( TestArtifact . TestArtifactsPath , "portableAppActivation" ) ) , "App" ) ;
660+ Directory . CreateDirectory ( MockApp . Location ) ;
661+ File . WriteAllText ( MockApp . AppDll , string . Empty ) ;
662+ File . Copy ( BuiltAppHost , MockApp . AppExe ) ;
663+ AppHostExtensions . BindAppHost ( MockApp . AppExe ) ;
597664 }
598665
599666 public void Dispose ( )
600667 {
601668 PortableAppFixture_Built . Dispose ( ) ;
602669 PortableAppFixture_Published . Dispose ( ) ;
670+ MockApp . Dispose ( ) ;
603671 }
604672 }
605673 }
0 commit comments