Ejemplo n.º 1
0
        private void Bundle_And_Run_App_With_Subdirs_Succeeds()
        {
            var fixture  = sharedTestState.TestFixture.Copy();
            var hostName = Path.GetFileName(fixture.TestProject.AppExe);

            // Bundle to a single-file
            // This step should be removed in favor of publishing with /p:PublishSingleFile=true
            // once associated changes in SDK repo are checked in.
            string singleFileDir = Path.Combine(fixture.TestProject.ProjectDirectory, "oneExe");

            Directory.CreateDirectory(singleFileDir);
            var    bundler    = new Microsoft.NET.HostModel.Bundle.Bundler(hostName, singleFileDir);
            string singleFile = bundler.GenerateBundle(fixture.TestProject.OutputDirectory);

            // Run the bundled app (extract files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Wow! We now say hello to the big world and you.");

            // Run the bundled app again (reuse extracted files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Wow! We now say hello to the big world and you.");
        }
Ejemplo n.º 2
0
        // Bundle to a single-file
        // This step should be removed in favor of publishing with /p:PublishSingleFile=true
        // once core-setup tests use 3.0 SDK
        public static string BundleApp(TestProjectFixture fixture)
        {
            var    hostName    = GetHostName(fixture);
            string publishPath = GetPublishPath(fixture);
            var    bundleDir   = GetBundleDir(fixture);

            var    bundler    = new Microsoft.NET.HostModel.Bundle.Bundler(hostName, bundleDir.FullName);
            string singleFile = bundler.GenerateBundle(publishPath);

            return(singleFile);
        }
Ejemplo n.º 3
0
        private void Bundle_extraction_is_reused()
        {
            var    fixture     = sharedTestState.TestFixture.Copy();
            var    hostName    = BundleHelper.GetHostName(fixture);
            var    appName     = Path.GetFileNameWithoutExtension(hostName);
            string publishPath = BundleHelper.GetPublishPath(fixture);

            // Publish the bundle
            var    bundleDir  = BundleHelper.GetBundleDir(fixture);
            var    bundler    = new Microsoft.NET.HostModel.Bundle.Bundler(hostName, bundleDir.FullName);
            string singleFile = bundler.GenerateBundle(publishPath);

            // Create a directory for extraction.
            var extractBaseDir = BundleHelper.GetExtractDir(fixture);

            // Run the bunded app for the first time, and extract files to
            // $DOTNET_BUNDLE_EXTRACT_BASE_DIR/<app>/bundle-id
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            string extractPath = Path.Combine(extractBaseDir.FullName, appName, bundler.BundleManifest.BundleID);
            var    extractDir  = new DirectoryInfo(extractPath);

            extractDir.Refresh();
            DateTime firstWriteTime = extractDir.LastWriteTimeUtc;

            while (DateTime.Now == firstWriteTime)
            {
                Thread.Sleep(1);
            }

            // Run the bundled app again (reuse extracted files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            extractDir.Should().NotBeModifiedAfter(firstWriteTime);
        }
Ejemplo n.º 4
0
        private void Bundle_extraction_can_recover_missing_files()
        {
            var    fixture     = sharedTestState.TestFixture.Copy();
            var    hostName    = BundleHelper.GetHostName(fixture);
            var    appName     = Path.GetFileNameWithoutExtension(hostName);
            string publishPath = BundleHelper.GetPublishPath(fixture);

            // Publish the bundle
            var    bundleDir  = BundleHelper.GetBundleDir(fixture);
            var    bundler    = new Microsoft.NET.HostModel.Bundle.Bundler(hostName, bundleDir.FullName);
            string singleFile = bundler.GenerateBundle(publishPath);

            // Compute bundled files
            List <string> bundledFiles = bundler.BundleManifest.Files.Select(file => file.RelativePath).ToList();

            // Create a directory for extraction.
            var    extractBaseDir = BundleHelper.GetExtractDir(fixture);
            string extractPath    = Path.Combine(extractBaseDir.FullName, appName, bundler.BundleManifest.BundleID);
            var    extractDir     = new DirectoryInfo(extractPath);

            // Run the bunded app for the first time, and extract files to
            // $DOTNET_BUNDLE_EXTRACT_BASE_DIR/<app>/bundle-id
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            bundledFiles.ForEach(file => File.Delete(Path.Combine(extractPath, file)));

            extractDir.Should().Exist();
            extractDir.Should().NotHaveFiles(bundledFiles);

            // Run the bundled app again (recover deleted files)
            Command.Create(singleFile)
            .CaptureStdErr()
            .CaptureStdOut()
            .EnvironmentVariable(BundleHelper.DotnetBundleExtractBaseEnvVariable, extractBaseDir.FullName)
            .Execute()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hello World");

            extractDir.Should().HaveFiles(bundledFiles);
        }