public GivenThatICareAboutLightupAppActivation()
        {
            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = Environment.GetEnvironmentVariable("TEST_ARTIFACTS");

            _builtDotnet = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetLightupSharedFxLookup dir will contain some folders and files that will be necessary to perform the tests
            string sharedLookupDir = Path.Combine(artifactsDir, "dotnetLightupSharedFxLookup");

            _currentWorkingDir = SharedFramework.CalculateUniqueTestDirectory(sharedLookupDir);
            _fxBaseDir         = Path.Combine(_currentWorkingDir, "shared", "Microsoft.NETCore.App");
            _uberFxBaseDir     = Path.Combine(_currentWorkingDir, "shared", "Microsoft.UberFramework");

            SharedFramework.CopyDirectory(_builtDotnet, _currentWorkingDir);

            var repoDirectories = new RepoDirectoriesProvider(builtDotnet: _currentWorkingDir);

            PreviouslyGlobalBuiltAndRestoredLightupAppTestProjectFixture = new TestProjectFixture("LightupClient", repoDirectories)
                                                                           .EnsureRestored(RepoDirectories.CorehostPackages)
                                                                           .BuildProject();

            string greatestVersionSharedFxPath = PreviouslyBuiltAndRestoredLightupLibTestProjectFixture.BuiltDotnet.GreatestVersionSharedFxPath;
            string sharedFxVersion             = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;

            _builtSharedFxDir     = Path.Combine(_builtDotnet, "shared", "Microsoft.NETCore.App", sharedFxVersion);
            _builtSharedUberFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.UberFramework", sharedFxVersion);
            SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);
        }
示例#2
0
        public LightupAppActivation(LightupAppActivation.SharedTestState fixture)
        {
            sharedTestState = fixture;

            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = new RepoDirectoriesProvider().GetTestContextVariable("TEST_ARTIFACTS");
            string builtDotnet  = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetLightupSharedFxLookup dir will contain some folders and files that will be necessary to perform the tests
            string sharedLookupDir = Path.Combine(artifactsDir, "dotnetLightupSharedFxLookup");

            _baseDirArtifact = new TestArtifact(SharedFramework.CalculateUniqueTestDirectory(sharedLookupDir));
            _fxBaseDir       = Path.Combine(_baseDirArtifact.Location, "shared", "Microsoft.NETCore.App");
            _uberFxBaseDir   = Path.Combine(_baseDirArtifact.Location, "shared", "Microsoft.UberFramework");

            SharedFramework.CopyDirectory(builtDotnet, _baseDirArtifact.Location);

            var repoDirectories = new RepoDirectoriesProvider(builtDotnet: _baseDirArtifact.Location);

            GlobalLightupClientFixture = new TestProjectFixture("LightupClient", repoDirectories)
                                         .EnsureRestored()
                                         .BuildProject();

            string greatestVersionSharedFxPath = sharedTestState.LightupLibFixture_Built.BuiltDotnet.GreatestVersionSharedFxPath;
            string sharedFxVersion             = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;

            _builtSharedFxDir     = Path.Combine(builtDotnet, "shared", "Microsoft.NETCore.App", sharedFxVersion);
            _builtSharedUberFxDir = Path.Combine(builtDotnet, "shared", "Microsoft.UberFramework", sharedFxVersion);
            SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);
        }
示例#3
0
            public SharedTestState()
            {
                copiedDotnet = Path.Combine(TestArtifact.TestArtifactsPath, "runtimeProperties");
                SharedFramework.CopyDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), copiedDotnet);

                MockSDK = new DotNetBuilder(copiedDotnet, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "exe")
                          .AddMicrosoftNETCoreAppFrameworkMockCoreClr("9999.0.0")
                          .AddMockSDK("9999.0.0-dev", "9999.0.0")
                          .Build();

                File.WriteAllText(Path.Combine(MockSDK.BinPath, "global.json"),
                                  @"
{
    ""sdk"": {
      ""version"": ""9999.0.0-dev""
    }
}");

                RepoDirectories = new RepoDirectoriesProvider(builtDotnet: copiedDotnet);

                RuntimePropertiesFixture = new TestProjectFixture("RuntimeProperties", RepoDirectories)
                                           .EnsureRestored()
                                           .BuildProject();

                RuntimeConfig.FromFile(RuntimePropertiesFixture.TestProject.RuntimeConfigJson)
                .WithProperty(AppTestPropertyName, AppTestPropertyValue)
                .Save();

                RuntimeConfig.FromFile(Path.Combine(RuntimePropertiesFixture.BuiltDotnet.GreatestVersionSharedFxPath, "Microsoft.NETCore.App.runtimeconfig.json"))
                .WithProperty(FrameworkTestPropertyName, FrameworkTestPropertyValue)
                .Save();
            }
示例#4
0
        public SharedFxLookup()
        {
            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = new RepoDirectoriesProvider().GetTestContextVariable("TEST_ARTIFACTS");

            _builtDotnet = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetSharedFxLookup dir will contain some folders and files that will be
            // necessary to perform the tests
            string baseDir = Path.Combine(artifactsDir, "dotnetSharedFxLookup");

            _baseDir = SharedFramework.CalculateUniqueTestDirectory(baseDir);

            // The two tested locations will be the cwd and the exe dir. Both cwd and exe dir
            // are easily overwritten, so they will be placed inside the multilevel folder.
            _currentWorkingDir = Path.Combine(_baseDir, "cwd");
            _executableDir     = Path.Combine(_baseDir, "exe");

            RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _executableDir);

            // SharedFxBaseDirs contain all available version folders
            _exeSharedFxBaseDir = Path.Combine(_executableDir, "shared", "Microsoft.NETCore.App");

            _exeSharedUberFxBaseDir = Path.Combine(_executableDir, "shared", "Microsoft.UberFramework");

            // Create directories. It's necessary to copy the entire publish folder to the exe dir because
            // we'll need to build from it. The CopyDirectory method automatically creates the dest dir
            Directory.CreateDirectory(_currentWorkingDir);
            SharedFramework.CopyDirectory(_builtDotnet, _executableDir);

            // Restore and build SharedFxLookupPortableApp from exe dir
            SharedFxLookupPortableAppFixture = new TestProjectFixture("SharedFxLookupPortableApp", RepoDirectories)
                                               .EnsureRestored(RepoDirectories.CorehostPackages)
                                               .BuildProject();
            var fixture = SharedFxLookupPortableAppFixture;

            // The actual framework version can be obtained from the built fixture. We'll use it to
            // locate the builtSharedFxDir from which we can get the files contained in the version folder
            string greatestVersionSharedFxPath = fixture.BuiltDotnet.GreatestVersionSharedFxPath;

            _sharedFxVersion      = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;
            _builtSharedFxDir     = Path.Combine(_builtDotnet, "shared", "Microsoft.NETCore.App", _sharedFxVersion);
            _builtSharedUberFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.UberFramework", _sharedFxVersion);
            SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);
        }
示例#5
0
            public SharedTestState()
            {
                copiedDotnet = Path.Combine(TestArtifact.TestArtifactsPath, "runtimeProperties");
                SharedFramework.CopyDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), copiedDotnet);

                RepoDirectories = new RepoDirectoriesProvider(builtDotnet: copiedDotnet);

                RuntimePropertiesFixture = new TestProjectFixture("RuntimeProperties", RepoDirectories)
                                           .EnsureRestored(RepoDirectories.CorehostPackages)
                                           .BuildProject();

                RuntimeConfig.FromFile(RuntimePropertiesFixture.TestProject.RuntimeConfigJson)
                .WithProperty(AppTestPropertyName, AppTestPropertyValue)
                .Save();

                RuntimeConfig.FromFile(Path.Combine(RuntimePropertiesFixture.BuiltDotnet.GreatestVersionSharedFxPath, "Microsoft.NETCore.App.runtimeconfig.json"))
                .WithProperty(FrameworkTestPropertyName, FrameworkTestPropertyValue)
                .Save();
            }
        // This method adds a list of new sdk version folders in the specified
        // sdkBaseDir. The files are copied from the _sdkDir. Also, the dotnet.runtimeconfig.json
        // file is overwritten in order to use a dummy framework version (9999.0.0)
        // Remarks:
        // - If the sdkBaseDir does not exist, then a DirectoryNotFoundException
        //   is thrown.
        // - If a specified version folder already exists, then it is deleted and replaced
        //   with the contents of the _builtSharedFxDir.
        private void AddAvailableSdkVersions(string sdkBaseDir, params string[] availableVersions)
        {
            DirectoryInfo sdkBaseDirInfo = new DirectoryInfo(sdkBaseDir);

            if (!sdkBaseDirInfo.Exists)
            {
                throw new DirectoryNotFoundException();
            }

            string dummyRuntimeConfig = Path.Combine(RepoDirectories.RepoRoot, "src", "test", "Assets", "TestUtils",
                                                     "SDKLookup", "dotnet.runtimeconfig.json");

            foreach (string version in availableVersions)
            {
                string newSdkDir = Path.Combine(sdkBaseDir, version);
                SharedFramework.CopyDirectory(_sdkDir, newSdkDir);

                string runtimeConfig = Path.Combine(newSdkDir, "dotnet.runtimeconfig.json");
                File.Copy(dummyRuntimeConfig, runtimeConfig, true);
            }
        }
示例#7
0
        public DotNetBuilder(string basePath, string builtDotnet, string name)
        {
            _path = Path.Combine(basePath, name);
            Directory.CreateDirectory(_path);

            _repoDirectories = new RepoDirectoriesProvider(builtDotnet: _path);

            // Prepare the dotnet installation mock

            // ./dotnet.exe - used as a convenient way to load and invoke hostfxr. May change in the future to use test-specific executable
            var builtDotNetCli = new DotNetCli(builtDotnet);

            File.Copy(
                builtDotNetCli.DotnetExecutablePath,
                Path.Combine(_path, RuntimeInformationExtensions.GetExeFileNameForCurrentPlatform("dotnet")),
                true);

            // ./host/fxr/<version>/hostfxr.dll - this is the component being tested
            SharedFramework.CopyDirectory(
                builtDotNetCli.GreatestVersionHostFxrPath,
                Path.Combine(_path, "host", "fxr", Path.GetFileName(builtDotNetCli.GreatestVersionHostFxrPath)));
        }
        public GivenThatICareAboutMultilevelSDKLookup()
        {
            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = Environment.GetEnvironmentVariable("TEST_ARTIFACTS");
            string builtDotnet  = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetMultilevelSDKLookup dir will contain some folders and files that will be
            // necessary to perform the tests
            string baseMultilevelDir = Path.Combine(artifactsDir, "dotnetMultilevelSDKLookup");

            _multilevelDir = SharedFramework.CalculateUniqueTestDirectory(baseMultilevelDir);

            // The three tested locations will be the cwd, the user folder and the exe dir. cwd and user are no longer supported.
            //     All dirs will be placed inside the multilevel folder

            _currentWorkingDir = Path.Combine(_multilevelDir, "cwd");
            _userDir           = Path.Combine(_multilevelDir, "user");
            _executableDir     = Path.Combine(_multilevelDir, "exe");

            // It's necessary to copy the entire publish folder to the exe dir because
            // we'll need to build from it. The CopyDirectory method automatically creates the dest dir
            SharedFramework.CopyDirectory(builtDotnet, _executableDir);

            RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _executableDir);

            // SdkBaseDirs contain all available version folders
            _cwdSdkBaseDir  = Path.Combine(_currentWorkingDir, "sdk");
            _userSdkBaseDir = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "sdk");
            _exeSdkBaseDir  = Path.Combine(_executableDir, "sdk");

            // Create directories
            Directory.CreateDirectory(_cwdSdkBaseDir);
            Directory.CreateDirectory(_userSdkBaseDir);
            Directory.CreateDirectory(_exeSdkBaseDir);

            // Restore and build PortableApp from exe dir
            PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("PortableApp", RepoDirectories)
                                                                   .EnsureRestored(RepoDirectories.CorehostPackages)
                                                                   .BuildProject();
            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture;

            // Set a dummy framework version (9999.0.0) in the exe sharedFx location. We will
            // always pick the framework from this to avoid interference with the sharedFxLookup
            string exeDirDummyFxVersion = Path.Combine(_executableDir, "shared", "Microsoft.NETCore.App", "9999.0.0");
            string builtSharedFxDir     = fixture.BuiltDotnet.GreatestVersionSharedFxPath;

            SharedFramework.CopyDirectory(builtSharedFxDir, exeDirDummyFxVersion);

            // The actual SDK version can be obtained from the built fixture. We'll use it to
            // locate the sdkDir from which we can get the files contained in the version folder
            string sdkBaseDir = Path.Combine(fixture.SdkDotnet.BinPath, "sdk");

            var sdkVersionDirs = Directory.EnumerateDirectories(sdkBaseDir)
                                 .Select(p => Path.GetFileName(p));

            string greatestVersionSdk = sdkVersionDirs
                                        .Where(p => !string.Equals(p, "NuGetFallbackFolder", StringComparison.OrdinalIgnoreCase))
                                        .OrderByDescending(p => p.ToLower())
                                        .First();

            _sdkDir = Path.Combine(sdkBaseDir, greatestVersionSdk);

            // Trace messages used to identify from which folder the SDK was picked
            _cwdSelectedMessage  = $"Using dotnet SDK dll=[{_cwdSdkBaseDir}";
            _userSelectedMessage = $"Using dotnet SDK dll=[{_userSdkBaseDir}";
            _exeSelectedMessage  = $"Using dotnet SDK dll=[{_exeSdkBaseDir}";
        }
        public GivenThatICareAboutMultilevelSharedFxLookup()
        {
            // From the artifacts dir, it's possible to find where the sharedFrameworkPublish folder is. We need
            // to locate it because we'll copy its contents into other folders
            string artifactsDir = Environment.GetEnvironmentVariable("TEST_ARTIFACTS");

            _builtDotnet = Path.Combine(artifactsDir, "sharedFrameworkPublish");

            // The dotnetMultilevelSharedFxLookup dir will contain some folders and files that will be
            // necessary to perform the tests
            string baseMultilevelDir = Path.Combine(artifactsDir, "dotnetMultilevelSharedFxLookup");

            _multilevelDir = SharedFramework.CalculateUniqueTestDirectory(baseMultilevelDir);

            // The three tested locations will be the cwd, the user folder and the exe dir. Both cwd and exe dir
            // are easily overwritten, so they will be placed inside the multilevel folder. The actual user location will
            // be used during tests
            _currentWorkingDir = Path.Combine(_multilevelDir, "cwd");
            _userDir           = Path.Combine(_multilevelDir, "user");
            _exeDir            = Path.Combine(_multilevelDir, "exe");
            _regDir            = Path.Combine(_multilevelDir, "reg");

            RepoDirectories = new RepoDirectoriesProvider(builtDotnet: _exeDir);

            // SharedFxBaseDirs contain all available version folders
            _cwdSharedFxBaseDir  = Path.Combine(_currentWorkingDir, "shared", "Microsoft.NETCore.App");
            _userSharedFxBaseDir = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "shared", "Microsoft.NETCore.App");
            _exeSharedFxBaseDir  = Path.Combine(_exeDir, "shared", "Microsoft.NETCore.App");
            _regSharedFxBaseDir  = Path.Combine(_regDir, "shared", "Microsoft.NETCore.App");

            _cwdSharedUberFxBaseDir  = Path.Combine(_currentWorkingDir, "shared", "Microsoft.UberFramework");
            _userSharedUberFxBaseDir = Path.Combine(_userDir, ".dotnet", RepoDirectories.BuildArchitecture, "shared", "Microsoft.UberFramework");
            _exeSharedUberFxBaseDir  = Path.Combine(_exeDir, "shared", "Microsoft.UberFramework");
            _regSharedUberFxBaseDir  = Path.Combine(_regDir, "shared", "Microsoft.UberFramework");

            // Create directories. It's necessary to copy the entire publish folder to the exe dir because
            // we'll need to build from it. The CopyDirectory method automatically creates the dest dir
            Directory.CreateDirectory(_cwdSharedFxBaseDir);
            Directory.CreateDirectory(_userSharedFxBaseDir);
            Directory.CreateDirectory(_regSharedFxBaseDir);
            Directory.CreateDirectory(_cwdSharedUberFxBaseDir);
            Directory.CreateDirectory(_userSharedUberFxBaseDir);
            Directory.CreateDirectory(_regSharedUberFxBaseDir);
            SharedFramework.CopyDirectory(_builtDotnet, _exeDir);

            //Copy dotnet to self-registered directory
            File.Copy(Path.Combine(_builtDotnet, $"dotnet{Constants.ExeSuffix}"), Path.Combine(_regDir, $"dotnet{Constants.ExeSuffix}"), true);

            // Restore and build SharedFxLookupPortableApp from exe dir
            PreviouslyBuiltAndRestoredPortableTestProjectFixture = new TestProjectFixture("SharedFxLookupPortableApp", RepoDirectories)
                                                                   .EnsureRestored(RepoDirectories.CorehostPackages)
                                                                   .BuildProject();
            var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture;

            // The actual framework version can be obtained from the built fixture. We'll use it to
            // locate the builtSharedFxDir from which we can get the files contained in the version folder
            string greatestVersionSharedFxPath = fixture.BuiltDotnet.GreatestVersionSharedFxPath;

            _sharedFxVersion      = (new DirectoryInfo(greatestVersionSharedFxPath)).Name;
            _builtSharedFxDir     = Path.Combine(_builtDotnet, "shared", "Microsoft.NETCore.App", _sharedFxVersion);
            _builtSharedUberFxDir = Path.Combine(_builtDotnet, "shared", "Microsoft.UberFramework", _sharedFxVersion);
            SharedFramework.CreateUberFrameworkArtifacts(_builtSharedFxDir, _builtSharedUberFxDir, SystemCollectionsImmutableAssemblyVersion, SystemCollectionsImmutableFileVersion);

            // Trace messages used to identify from which folder the framework was picked
            _hostPolicyDllName   = Path.GetFileName(fixture.TestProject.HostPolicyDll);
            _cwdSelectedMessage  = $"The expected {_hostPolicyDllName} directory is [{_cwdSharedFxBaseDir}";
            _userSelectedMessage = $"The expected {_hostPolicyDllName} directory is [{_userSharedFxBaseDir}";
            _exeSelectedMessage  = $"The expected {_hostPolicyDllName} directory is [{_exeSharedFxBaseDir}";
            _regSelectedMessage  = $"The expected {_hostPolicyDllName} directory is [{_regSharedFxBaseDir}";

            _cwdFoundUberFxMessage  = $"Chose FX version [{_cwdSharedUberFxBaseDir}";
            _userFoundUberFxMessage = $"Chose FX version [{_userSharedUberFxBaseDir}";
            _exeFoundUberFxMessage  = $"Chose FX version [{_exeSharedUberFxBaseDir}";
            _regFoundUberFxMessage  = $"Chose FX version [{_regSharedUberFxBaseDir}";
        }