Exemplo n.º 1
0
        public void Given_Passing_ResolvedTargetingPacks_It_Passes_Again_With_Cached_Results()
        {
            ResolveTargetingPackAssets task1 = InitializeMockTargetingPackAssetsDirectory(out string packageDirectory);

            // Save off that build engine to inspect and reuse
            MockBuildEngine4 buildEngine = (MockBuildEngine4)task1.BuildEngine;

            task1.Execute().Should().BeTrue();

            buildEngine.RegisteredTaskObjectsQueries.Should().Be(2,
                                                                 because: "there should be a lookup for the overall and the specific targeting pack");

            buildEngine.RegisteredTaskObjects.Count.Should().Be(2,
                                                                because: "there should be a cache entry for the overall lookup and for the specific targeting pack");

            ResolveTargetingPackAssets task2 = InitializeTask(packageDirectory, buildEngine);

            task2.Execute().Should().BeTrue();

            buildEngine.RegisteredTaskObjectsQueries.Should().Be(3,
                                                                 because: "there should be a hit on the overall lookup this time through");

            buildEngine.RegisteredTaskObjects.Count.Should().Be(2,
                                                                because: "the cache keys should match");
        }
Exemplo n.º 2
0
        public void Given_Passing_ResolvedTargetingPacks_A_Different_Language_Parses_Again()
        {
            ResolveTargetingPackAssets task1 = InitializeMockTargetingPackAssetsDirectory(out string packageDirectory);

            // Save off that build engine to inspect and reuse
            MockBuildEngine4 buildEngine = (MockBuildEngine4)task1.BuildEngine;

            task1.Execute().Should().BeTrue();

            buildEngine.RegisteredTaskObjectsQueries.Should().Be(2,
                                                                 because: "there should be a lookup for the overall and the specific targeting pack");

            buildEngine.RegisteredTaskObjects.Count.Should().Be(2,
                                                                because: "there should be a cache entry for the overall lookup and for the specific targeting pack");

            ResolveTargetingPackAssets task2 = InitializeTask(packageDirectory, buildEngine);

            task2.ProjectLanguage = "F#";

            task2.Execute().Should().BeTrue();

            buildEngine.RegisteredTaskObjectsQueries.Should().Be(4,
                                                                 because: "there should be no hits on the overall or targeting pack lookup this time through");

            buildEngine.RegisteredTaskObjects.Count.Should().Be(4,
                                                                because: "there should be distinct results for C# and F#");
        }
Exemplo n.º 3
0
        public void Given_ResolvedTargetingPacks_with_valid_PATH_in_PlatformManifest_It_resolves_TargetingPack()
        {
            ResolveTargetingPackAssets task = InitializeMockTargetingPackAssetsDirectory(out string mockPackageDirectory);

            task.Execute().Should().BeTrue();

            task.ReferencesToAdd[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "lib/Microsoft.Windows.SDK.NET.dll"));
            task.PlatformManifests[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, $"data{Path.DirectorySeparatorChar}PlatformManifest.txt"));
            task.AnalyzersToAdd.Length.Should().Be(2);
            task.AnalyzersToAdd[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "analyzers/dotnet/anyAnalyzer.dll"));
            task.AnalyzersToAdd[1].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "analyzers/dotnet/cs/csAnalyzer.dll"));

            ((MockBuildEngine4)task.BuildEngine).RegisteredTaskObjectsQueries.Should().Be(2,
                                                                                          because: "There should be a lookup for the overall and the specific targeting pack");

            ((MockBuildEngine4)task.BuildEngine).RegisteredTaskObjects.Count.Should().Be(2,
                                                                                         because: "There should be a cache entry for the overall lookup and for the specific targeting pack");
        }
Exemplo n.º 4
0
        public void Given_ResolvedTargetingPacks_with_valid_PATH_in_PlatformManifest_It_resolves_TargetingPack()
        {
            string mockPackageDirectory = Path.Combine(Path.GetTempPath(), "dotnetSdkTests", Path.GetRandomFileName());

            string dataDir = Path.Combine(mockPackageDirectory, "data");

            Directory.CreateDirectory(dataDir);

            File.WriteAllText(Path.Combine(dataDir, "FrameworkList.xml"), _frameworkList);
            File.WriteAllText(Path.Combine(dataDir, "PlatformManifest.txt"), "");

            var task = new ResolveTargetingPackAssets();

            task.FrameworkReferences = new[]
            {
                new MockTaskItem("Microsoft.Windows.SDK.NET.Ref", new Dictionary <string, string>())
            };

            task.ResolvedTargetingPacks = new[]
            {
                new MockTaskItem("Microsoft.Windows.SDK.NET.Ref",
                                 new Dictionary <string, string>()
                {
                    { MetadataKeys.NuGetPackageId, "Microsoft.Windows.SDK.NET.Ref" },
                    { MetadataKeys.NuGetPackageVersion, "5.0.0-preview1" },
                    { MetadataKeys.PackageConflictPreferredPackages, "Microsoft.Windows.SDK.NET.Ref;" },
                    { MetadataKeys.PackageDirectory, mockPackageDirectory },
                    { MetadataKeys.Path, mockPackageDirectory },
                    { "TargetFramework", "net5.0" }
                })
            };

            task.ProjectLanguage = "C#";

            task.Execute().Should().BeTrue();

            task.ReferencesToAdd[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "lib/Microsoft.Windows.SDK.NET.dll"));
            task.PlatformManifests[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, $"data{Path.DirectorySeparatorChar}PlatformManifest.txt"));
            task.AnalyzersToAdd.Length.Should().Be(2);
            task.AnalyzersToAdd[0].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "analyzers/dotnet/anyAnalyzer.dll"));
            task.AnalyzersToAdd[1].ItemSpec.Should().Be(Path.Combine(mockPackageDirectory, "analyzers/dotnet/cs/csAnalyzer.dll"));
        }
Exemplo n.º 5
0
        public void It_Uses_Multiple_Frameworks()
        {
            ResolveTargetingPackAssets task = InitializeMockTargetingPackAssetsDirectory(out string mockPackageDirectory);

            // Add two RuntimeFrameworks that both point to the default targeting pack.
            task.RuntimeFrameworks = new[] {
                new MockTaskItem("RuntimeFramework1", new Dictionary <string, string> {
                    ["FrameworkName"] = "Microsoft.Windows.SDK.NET.Ref"
                }),
                new MockTaskItem("RuntimeFramework2", new Dictionary <string, string> {
                    ["FrameworkName"] = "Microsoft.Windows.SDK.NET.Ref"
                }),
            };

            task.Execute().Should().BeTrue();

            task.UsedRuntimeFrameworks.Select(item => item.ItemSpec)
            .Should().BeEquivalentTo(new[]
            {
                "RuntimeFramework1",
                "RuntimeFramework2",
            });
        }