public void ReturnNet20PathAsFallbackOnWindows()
        {
            var net20Path  = Path.Combine("Windows", "Microsoft.NET", "Framework", "v2.0.50727");
            var fileSystem = FileSystemMockBuilder.Create()
                             .AddFiles(net20Path, "some.dll")
                             .Build();

            var environment = EnvironmentMockBuilder.Create()
                              .AddVariable("WINDIR", "Windows")
                              .Build();

            var result = ReferenceAssemblyPathResolver.GetFallbackSearchPaths(fileSystem, Platform.Windows, environment);

            result.Should().Contain(net20Path);
        }
        public void ShouldThrowForNonResolvedInPublishedApps()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType
                );

            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            Assert.Throws <InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));
        }
        public void ResolvesReferenceAssemblyType()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var resolver = CreateResolver(fileSystem);
            var library  = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType,
                assemblies: TestLibraryFactory.EmptyAssemblies);

            var result = resolver.TryResolveAssemblyPaths(library, null);

            Assert.True(result);
        }
        public void ChecksForFileNameInFallbackLocation()
        {
            var fileSystem = FileSystemMockBuilder.Create()
                             .AddFiles(ReferencePath, F.DefaultAssembly)
                             .Build();

            var library    = F.Create(libraryType: F.ReferenceAssemblyType);
            var assemblies = new List <string>();

            var resolver = new ReferenceAssemblyPathResolver(fileSystem, null, new string[] { ReferencePath });
            var result   = resolver.TryResolveAssemblyPaths(library, assemblies);

            result.Should().BeTrue();
            assemblies.Should().Contain(Path.Combine(ReferencePath, F.DefaultAssembly));
        }
Beispiel #5
0
        public void ResolvesPackageType()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var resolver = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
            var library  = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType,
                assemblies: TestLibraryFactory.EmptyAssemblies);

            var result = resolver.TryResolveAssemblyPaths(library, null);

            Assert.True(result);
        }
        public void ShouldSkipForNonResolvedInNonPublishedApps()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType
                );

            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.False(result);
        }
Beispiel #7
0
        public void FailsWhenOneOfAssembliesNotFound()
        {
            var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion);
            var fileSystem  = FileSystemMockBuilder.Create()
                              .AddFiles(packagePath, F.DefaultAssemblyPath)
                              .Build();
            var library = F.Create(assemblies: F.TwoAssemblies);

            var resolver   = new PackageCompilationAssemblyResolver(fileSystem, new string[] { PackagesPath });
            var assemblies = new List <string>();

            resolver.TryResolveAssemblyPaths(library, assemblies)
            .Should().BeFalse();

            assemblies.Should().BeEmpty();
        }
Beispiel #8
0
        public void ShouldReturnFalseForNonResolvedInPublishedApps()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType
                );

            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            resolver.TryResolveAssemblyPaths(library, assemblies).Should().Be(false);
            assemblies.Should().BeEmpty();
        }
Beispiel #9
0
        public void RequiresAllLibrariesToExist()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly)
                             .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType,
                assemblies: TestLibraryFactory.TwoAssemblies);
            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            resolver.TryResolveAssemblyPaths(library, assemblies).Should().Be(false);
            assemblies.Should().BeEmpty();
        }
Beispiel #10
0
        public void ResolvesAllAssemblies()
        {
            var packagePath = Path.Combine(PackagesPath, F.DefaultPackageName, F.DefaultVersion);
            var fileSystem  = FileSystemMockBuilder.Create()
                              .AddFiles(packagePath, F.TwoAssemblies)
                              .Build();
            var library = F.Create(assemblies: F.TwoAssemblies);

            var resolver   = new PackageCompilationAssemblyResolver(fileSystem, PackagesPath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath));
            assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath));
        }
Beispiel #11
0
        public void FailsWhenOneOfAssembliesNotFound()
        {
            var packagePath = Path.Combine(PackagesPath, F.DefaultPackageName, F.DefaultVersion);
            var fileSystem  = FileSystemMockBuilder.Create()
                              .AddFiles(packagePath, F.DefaultAssemblyPath)
                              .Build();
            var library = F.Create(assemblies: F.TwoAssemblies);

            var resolver   = new PackageCompilationAssemblyResolver(fileSystem, PackagesPath);
            var assemblies = new List <string>();

            var exception = Assert.Throws <InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));

            exception.Message.Should()
            .Contain(F.SecondAssemblyPath)
            .And.Contain(library.Name);
        }
        public void ShouldResolveAll()
        {
            var fileSystem = FileSystemMockBuilder.Create()
                             .AddFiles(ReferencePath, F.DefaultAssembly)
                             .Build();

            var library    = F.Create(libraryType: F.ReferenceAssemblyType, assemblies: F.TwoAssemblies);
            var assemblies = new List <string>();

            var resolver = new ReferenceAssemblyPathResolver(fileSystem, null, new string[] { ReferencePath });

            var exception = Assert.Throws <InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));

            exception.Message.Should()
            .Contain(F.SecondAssemblyPath)
            .And.Contain(library.Name);
        }
        public void RequiresExistingRefsFolderForNonProjects()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType,
                assemblies: TestLibraryFactory.TwoAssemblies);
            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.False(result);
            assemblies.Should().HaveCount(0);
        }
Beispiel #14
0
        public void ChecksHashFile()
        {
            var packagePath = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion);
            var fileSystem  = FileSystemMockBuilder.Create()
                              .AddFile(
                GetHashFilePath(packagePath),
                "WRONGHASH"
                )
                              .AddFiles(packagePath, F.DefaultAssemblies)
                              .Build();

            var resolver   = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(F.Create(), assemblies);

            result.Should().BeFalse();
        }
Beispiel #15
0
        public void ChecksHashFile()
        {
            var packagePath = Path.Combine(CachePath, F.DefaultPackageName, F.DefaultVersion);
            var fileSystem  = FileSystemMockBuilder.Create()
                              .AddFile(
                Path.Combine(packagePath, $"{F.DefaultPackageName}.{F.DefaultVersion}.nupkg.{F.DefaultHashAlgoritm}"),
                "WRONGHASH"
                )
                              .AddFiles(packagePath, F.DefaultAssemblies)
                              .Build();

            var resolver   = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(F.Create(), assemblies);

            result.Should().BeFalse();
        }
        public void SkipsSharedFxPathForNonPublishedPortable()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(SharedFxPath, TestLibraryFactory.DefaultAssembly)
                             .AddFiles(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType
                );

            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.False(result);
        }
        public void SearchesInSharedFxRefsPathForPublishedPortable()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePathRefs, TestLibraryFactory.SecondAssembly)
                             .AddFiles(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.PackageType
                );

            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();
            var result     = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.True(result);
            assemblies.Should().HaveCount(1);
            assemblies.Should().Contain(Path.Combine(SharedFxPathRefs, TestLibraryFactory.DefaultAssembly));
        }
        public void ResolvesProjectWithoutRefsFolder()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ProjectType,
                assemblies: TestLibraryFactory.TwoAssemblies);
            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.True(result);
            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.DefaultAssembly));
            assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.SecondAssembly));
        }
Beispiel #19
0
        public void ResolvesIfAllAreInBaseDir()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly, TestLibraryFactory.SecondAssembly)
                             .AddFiles(BasePathRefs, "Dummy.dll")
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType,
                assemblies: TestLibraryFactory.TwoAssemblies);
            var resolver   = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.True(result);
            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.DefaultAssembly));
            assemblies.Should().Contain(Path.Combine(BasePath, TestLibraryFactory.SecondAssembly));
        }
        public void RequiresAllLibrariesToExist()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly)
                             .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType,
                assemblies: TestLibraryFactory.TwoAssemblies);
            var resolver   = CreateResolver(fileSystem);
            var assemblies = new List <string>();

            var exception = Assert.Throws <InvalidOperationException>(() => resolver.TryResolveAssemblyPaths(library, assemblies));

            exception.Message.Should()
            .Contain(BasePath)
            .And.Contain(BasePathRefs)
            .And.Contain(TestLibraryFactory.SecondAssembly);
        }
Beispiel #21
0
        public void PrefersRefs()
        {
            var fileSystem = FileSystemMockBuilder
                             .Create()
                             .AddFiles(BasePath, TestLibraryFactory.DefaultAssembly)
                             .AddFiles(BasePathRefs, TestLibraryFactory.DefaultAssembly)
                             .Build();
            var library = TestLibraryFactory.Create(
                TestLibraryFactory.ReferenceAssemblyType
                );

            var resolver   = new AppBaseCompilationAssemblyResolver(fileSystem, BasePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            Assert.True(result);
            assemblies.Should().HaveCount(1);
            assemblies.Should().Contain(Path.Combine(BasePathRefs, TestLibraryFactory.DefaultAssembly));
        }
Beispiel #22
0
        public void KeepsLookingWhenOneOfAssembliesNotFound()
        {
            var packagePath1 = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion);
            var secondPath   = "secondPath";
            var packagePath2 = GetPackagesPath(secondPath, F.DefaultPackageName, F.DefaultVersion);
            var fileSystem   = FileSystemMockBuilder.Create()
                               .AddFiles(packagePath1, F.DefaultAssemblyPath)
                               .AddFiles(packagePath2, F.DefaultAssemblyPath, F.SecondAssemblyPath)
                               .Build();
            var library = F.Create(assemblies: F.TwoAssemblies);

            var resolver   = new PackageCompilationAssemblyResolver(fileSystem, new string[] { PackagesPath, secondPath });
            var assemblies = new List <string>();

            resolver.TryResolveAssemblyPaths(library, assemblies)
            .Should().BeTrue();

            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(packagePath2, F.DefaultAssemblyPath));
            assemblies.Should().Contain(Path.Combine(packagePath2, F.SecondAssemblyPath));
        }
        public void UsesHashPathProperty()
        {
            var hashFileName = "myFunkyHashPath.sha29";
            var packagePath  = GetPackagesPath(F.DefaultPackageName, F.DefaultVersion);
            var fileSystem   = FileSystemMockBuilder.Create()
                               .AddFile(
                Path.Combine(packagePath, hashFileName),
                F.DefaultHashValue
                )
                               .AddFiles(packagePath, F.TwoAssemblies)
                               .Build();

            var library = F.Create(assemblies: F.TwoAssemblies, hashPath: hashFileName);

            var resolver   = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            result.Should().BeTrue();
            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath));
            assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath));
        }
        public void UsesPathProperty()
        {
            var testPathValue = "NotPackageId";
            var packagePath   = Path.Combine(CachePath, testPathValue);
            var fileSystem    = FileSystemMockBuilder.Create()
                                .AddFile(
                GetHashFilePath(packagePath),
                F.DefaultHashValue
                )
                                .AddFiles(packagePath, F.TwoAssemblies)
                                .Build();

            var library = F.Create(assemblies: F.TwoAssemblies, path: testPathValue);

            var resolver   = new PackageCacheCompilationAssemblyResolver(fileSystem, CachePath);
            var assemblies = new List <string>();

            var result = resolver.TryResolveAssemblyPaths(library, assemblies);

            result.Should().BeTrue();
            assemblies.Should().HaveCount(2);
            assemblies.Should().Contain(Path.Combine(packagePath, F.DefaultAssemblyPath));
            assemblies.Should().Contain(Path.Combine(packagePath, F.SecondAssemblyPath));
        }
Beispiel #25
0
        public void LoadLoadsExtraPaths()
        {
            string appDepsPath   = "appPath.deps.json";
            string fxDepsPath    = "fxPath.deps.json";
            string extraDepsPath = "extra1.deps.json";

            var fileSystem = FileSystemMockBuilder.Create()
                             .AddFile(
                appDepsPath,
                @"{
    ""runtimeTarget"": {
        ""name"":"".NETCoreApp,Version=v1.0/osx.10.10-x64"",
        ""signature"":""target-signature""
    },
    ""targets"": {
        "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {},
    }
}")
                             .AddFile(
                fxDepsPath,
                @"{
    ""targets"": {
        "".NETCoreApp,Version=v1.0/osx.10.10-x64"": {
            
        },
    }
}")
                             .AddFile(
                extraDepsPath,
                @"
 {
     ""targets"": {
         "".NETStandard,Version=v1.5"": {
             ""System.Banana/1.0.0"": {
                 ""runtimeTargets"": {
                     ""runtimes/unix/Banana.dll"": { ""rid"": ""unix"", ""assetType"": ""runtime"" },
                     ""runtimes/win7/Banana.dll"": { ""rid"": ""win7"",  ""assetType"": ""runtime"" },

                     ""runtimes/native/win7/Apple.dll"": { ""rid"": ""win7"",  ""assetType"": ""native"" },
                     ""runtimes/native/unix/libapple.so"": { ""rid"": ""unix"",  ""assetType"": ""native"" }
                 }
             }
         }
     },
     ""libraries"": {
         ""System.Banana/1.0.0"": {
             ""type"": ""package"",
             ""serviceable"": false,
             ""sha512"": ""HASH-System.Banana""
         },
     }
 }")
                             .Build();

            var loader = new DependencyContextLoader(
                appDepsPath,
                new[] { fxDepsPath, extraDepsPath },
                fileSystem,
                () => new DependencyContextJsonReader());

            var context = loader.Load(Assembly.GetEntryAssembly());

            context.RuntimeLibraries.Should().Contain(l => l.Name == "System.Banana");
        }