private static void RefreshAssemblies(ILog log)
        {
            var fileSystem = new FileSystem();

            var packagesFolder = Path.Combine(fileSystem.CurrentDirectory, "packages");

            if (fileSystem.DirectoryExists(packagesFolder))
            {
                // Delete any blacklisted packages to avoid various issues with PackageAssemblyResolver
                // https://github.com/scriptcs/scriptcs/issues/511
                foreach (var packagePath in
                         _blacklistedPackages.SelectMany(packageName => Directory.GetDirectories(packagesFolder)
                                                         .Where(d => new DirectoryInfo(d).Name.StartsWith(packageName, StringComparison.InvariantCultureIgnoreCase)),
                                                         (packageName, packagePath) => new { packageName, packagePath })
                         .Where(t => fileSystem.DirectoryExists(t.packagePath))
                         .Select(t => @t.packagePath))
                {
                    fileSystem.DeleteDirectory(packagePath);
                }
            }

            var par = new PackageAssemblyResolver(fileSystem, new PackageContainer(fileSystem, log), log);

            _assemblies = par.GetAssemblyNames(fileSystem.CurrentDirectory).ToList();

            // Add the assemblies in the current directory
            _assemblies.AddRange(Directory.GetFiles(fileSystem.CurrentDirectory, "*.dll")
                                 .Where(a => new AssemblyUtility().IsManagedAssembly(a)));
        }
Пример #2
0
            public void ShouldNotLoadIncompatibleDependenciesDlls()
            {
                var p = new Mock <IPackageObject>();

                p.Setup(i => i.GetCompatibleDlls(It.IsAny <FrameworkName>()))
                .Returns(new List <string>());
                p.SetupGet(i => i.Id).Returns("p2");
                p.SetupGet(i => i.Version).Returns(new Version("4.0"));
                p.SetupGet(i => i.TextVersion).Returns("4.0");
                p.SetupGet(i => i.FullName).Returns(_package.Object.Id + "." + _package.Object.Version);

                _package.Setup(i => i.Dependencies).Returns(new List <IPackageObject> {
                    p.Object
                });
                _packageContainer.Setup(
                    i => i.FindPackage(It.IsAny <string>(), It.Is <IPackageReference>(x => x.PackageId == "p2")))
                .Returns(p.Object);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                _packageContainer.Verify(i => i.FindPackage(It.IsAny <string>(), It.IsAny <IPackageReference>()), Times.Exactly(2));
                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(2);
            }
Пример #3
0
            public void WhenManyPackagesAreMatchedAllNonMatchingDllsShouldBeExcluded()
            {
                _package.Setup(
                    i =>
                    i.GetCompatibleDlls(
                        It.Is <FrameworkName>(x => x.FullName == VersionUtility.ParseFrameworkName("net40").FullName)))
                .Returns(new List <string> {
                    "test.dll"
                });
                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));

                var p = new Mock <IPackageObject>();

                p.Setup(i => i.GetCompatibleDlls(It.IsAny <FrameworkName>()))
                .Returns(new List <string> {
                    "test3.dll"
                });
                p.SetupGet(i => i.Id).Returns("testId2");
                p.SetupGet(i => i.Version).Returns(new Version("3.0"));
                p.SetupGet(i => i.TextVersion).Returns("3.0");
                p.SetupGet(i => i.FullName).Returns(_package.Object.Id + "." + _package.Object.Version);

                _packageContainer.Setup(i => i.FindPackage(It.IsAny <string>(), It.Is <IPackageReference>(x => x.PackageId == "testId2"))).Returns(p.Object);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(2);
            }
Пример #4
0
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldThrowArgumentEx()
            {
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny <FrameworkName>())).Returns <List <string> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                Assert.Throws <MissingAssemblyException>(() => resolver.GetAssemblyNames(_workingDirectory));
            }
Пример #5
0
            public void WhenDllsAreMatchedDllFilePathsAreCorrectlyConcatenated()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory);

                found.First().ShouldEqual("c:\\test\\packages\\id.3.0\\test.dll");
                found.ElementAt(1).ShouldEqual("c:\\test\\packages\\id.3.0\\test2.dll");
            }
Пример #6
0
            public void WhenNoPackagesAreFoundShouldThrowArgumentEx()
            {
                _packageContainer.Setup(i => i.FindPackage(It.IsAny <string>(), It.IsAny <IPackageReference>()))
                .Returns <List <IPackageObject> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                Assert.Throws <MissingAssemblyException>(() => resolver.GetAssemblyNames(_workingDirectory));
            }
            public void WhenManyPackagesAreMatchedAllMatchingDllsWithUniquePathsShouldBeReturned()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);
                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(4);
            }
Пример #8
0
            public void WhenPackagesConfigDoesNotExistShouldReturnEmptyPackagesList()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, new Mock <IPackageContainer>().Object);

                _filesystem.Setup(i => i.FileExists(It.IsAny <string>())).Returns(false);

                var found = resolver.GetAssemblyNames(_workingDirectory);

                found.ShouldBeEmpty();
            }
            public void WhenDllsAreMatchedDllFilePathsAreCorrectlyConcatenated()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object, _assemblyUtility.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory);

                found.First().ShouldEqual(
                    Path.Combine(_workingDirectory, "packages", "id.3.0", "test.dll"));
                found.ElementAt(1).ShouldEqual(
                    Path.Combine(_workingDirectory, "packages", "id.3.0", "test2.dll"));
            }
Пример #10
0
            public void WhenManyPackagesAreMatchedAllMatchingDllsWithUniquePathsShouldBeReturned()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(2);
            }
            public void ShouldIgnoreUnmanagedAssemblies()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object, _assemblyUtility.Object);

                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));
                _assemblyUtility.Setup(u => u.IsManagedAssembly(It.Is <string>(s => Path.GetFileName(s) == "test.dll"))).Returns(false);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(3);
            }
Пример #12
0
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldLogWarning()
            {
                // arrange
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny <FrameworkName>())).Returns <List <string> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logProvider.Output.ShouldContain(
                    "WARN: Cannot find compatible binaries for .NETFramework,Version=v4.0 in: testId 3.0");
            }
Пример #13
0
            public void WhenNoPackagesAreFoundShouldLogWarning()
            {
                // arrange
                _packageContainer.Setup(i => i.FindPackage(It.IsAny <string>(), It.IsAny <IPackageReference>()))
                .Returns <List <IPackageObject> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logProvider.Output.ShouldContain("WARN: Cannot find: testId 3.0");
            }
Пример #14
0
            public void WhenPackageIsMatchedItsNonMatchingDllsShouldBeExcluded()
            {
                _package.Setup(
                    i =>
                    i.GetCompatibleDlls(
                        It.Is <FrameworkName>(x => x.FullName == VersionUtility.ParseFrameworkName("net40").FullName)))
                .Returns(new List <string> {
                    "test.dll"
                });

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(1);
            }
Пример #15
0
            public void WhenNoPackagesAreFoundShouldLogWarning()
            {
                // arrange
                _packageContainer.Setup(i => i.FindPackage(It.IsAny <string>(), It.IsAny <IPackageReference>()))
                .Returns <List <IPackageObject> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logger.Verify(i => i.WarnFormat(
                                   It.IsAny <IFormatProvider>(),
                                   It.Is <string>(x => x == "Cannot find: {0} {1}"),
                                   It.IsAny <object>(),
                                   It.IsAny <object>()),
                               Times.Exactly(_packageContainer.Object.FindReferences("foo").Count()));
            }
Пример #16
0
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldLogWarning()
            {
                // arrange
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny <FrameworkName>())).Returns <List <string> >(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logger.Verify(i => i.WarnFormat(
                                   It.IsAny <IFormatProvider>(),
                                   It.Is <string>(x => x == "Cannot find compatible binaries for {0} in: {1} {2}"),
                                   It.IsAny <object>(),
                                   It.IsAny <object>(),
                                   It.IsAny <object>()),
                               Times.Exactly(_packageContainer.Object.FindReferences("foo").Count()));
            }
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldLogWarning()
            {
                // arrange
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny<FrameworkName>())).Returns<List<string>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logger.Verify(i => i.WarnFormat(
                    It.IsAny<IFormatProvider>(),
                    It.Is<string>(x => x == "Cannot find compatible binaries for {0} in: {1} {2}"),
                    It.IsAny<object>(),
                    It.IsAny<object>(),
                    It.IsAny<object>()),
                    Times.Exactly(_packageContainer.Object.FindReferences("foo").Count()));
            }
            public void WhenDllsAreMatchedDllFilePathsAreCorrectlyConcatenated()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory);

                found.First().ShouldEqual(
                    Path.Combine(_workingDirectory, "packages", "id.3.0", "test.dll"));
                found.ElementAt(1).ShouldEqual(
                    Path.Combine(_workingDirectory, "packages", "id.3.0", "test2.dll"));
            }
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldLogWarning()
            {
                // arrange
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny<FrameworkName>())).Returns<List<string>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logProvider.Output.ShouldContain(
                    "WARN: Cannot find compatible binaries for .NETFramework,Version=v4.0 in: testId 3.0");
            }
            public void WhenNoPackagesAreFoundShouldLogWarning()
            {
                // arrange
                _packageContainer.Setup(i => i.FindPackage(It.IsAny<string>(), It.IsAny<IPackageReference>()))
                                 .Returns<List<IPackageObject>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logProvider.Output.ShouldContain("WARN: Cannot find: testId 3.0");
            }
Пример #21
0
            public void WhenPackagesConfigDoesNotExistShouldReturnEmptyPackagesList()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, new Mock<IPackageContainer>().Object, _logger.Object);
                _filesystem.Setup(i => i.FileExists(It.IsAny<string>())).Returns(false);

                var found = resolver.GetAssemblyNames(_workingDirectory);
                found.ShouldBeEmpty();
            }
Пример #22
0
            public void ShouldLoadAllDependenciesIfPackageHasAny()
            {
                var p = new Mock<IPackageObject>();
                p.Setup(i => i.GetCompatibleDlls(It.IsAny<FrameworkName>()))
                        .Returns(new List<string> { "test3.dll", "test4.dll" });
                p.SetupGet(i => i.Id).Returns("p2");
                p.SetupGet(i => i.Version).Returns(new Version("4.0"));
                p.SetupGet(i => i.TextVersion).Returns("4.0");
                p.SetupGet(i => i.FullName).Returns(_package.Object.Id + "." + _package.Object.Version);

                _package.Setup(i => i.Dependencies).Returns(new List<IPackageObject> { p.Object });
                _packageContainer.Setup(
                    i => i.FindPackage(It.IsAny<string>(), It.Is<IPackageReference>(x => x.PackageId == "p2")))
                                 .Returns(p.Object);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                _packageContainer.Verify(i => i.FindPackage(It.IsAny<string>(), It.IsAny<IPackageReference>()), Times.Exactly(2));
                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(4);
            }
Пример #23
0
            public void WhenPackagesAreFoundButNoMatchingDllsExistShouldThrowArgumentEx()
            {
                _package.Setup(i => i.GetCompatibleDlls(It.IsAny<FrameworkName>())).Returns<List<string>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                Assert.Throws<MissingAssemblyException>(() => resolver.GetAssemblyNames(_workingDirectory));
            }
Пример #24
0
            public void WhenPackageIsMatchedItsNonMatchingDllsShouldBeExcluded()
            {
                _package.Setup(
                    i =>
                    i.GetCompatibleDlls(
                        It.Is<FrameworkName>(x => x.FullName == VersionUtility.ParseFrameworkName("net40").FullName)))
                        .Returns(new List<string> { "test.dll" });

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(1);
            }
Пример #25
0
            public void WhenNoPackagesAreFoundShouldThrowArgumentEx()
            {
                _packageContainer.Setup(i => i.FindPackage(It.IsAny<string>(), It.IsAny<IPackageReference>()))
                                 .Returns<List<IPackageObject>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                Assert.Throws<MissingAssemblyException>(() => resolver.GetAssemblyNames(_workingDirectory));
            }
Пример #26
0
            public void WhenManyPackagesAreMatchedAllNonMatchingDllsShouldBeExcluded()
            {
                _package.Setup(
                    i =>
                    i.GetCompatibleDlls(
                        It.Is<FrameworkName>(x => x.FullName == VersionUtility.ParseFrameworkName("net40").FullName)))
                        .Returns(new List<string> { "test.dll" });
                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));

                var p = new Mock<IPackageObject>();
                p.Setup(i => i.GetCompatibleDlls(It.IsAny<FrameworkName>()))
                        .Returns(new List<string> { "test3.dll" });
                p.SetupGet(i => i.Id).Returns("testId2");
                p.SetupGet(i => i.Version).Returns(new Version("3.0"));
                p.SetupGet(i => i.TextVersion).Returns("3.0");
                p.SetupGet(i => i.FullName).Returns(_package.Object.Id + "." + _package.Object.Version);

                _packageContainer.Setup(i => i.FindPackage(It.IsAny<string>(), It.Is<IPackageReference>(x => x.PackageId == "testId2"))).Returns(p.Object);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(2);
            }
            public void ShouldIgnoreUnmanagedAssemblies()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logProvider, _assemblyUtility.Object);
                _packageIds.Add(new PackageReference("testId2", VersionUtility.ParseFrameworkName("net40"), new Version("3.0")));
                _assemblyUtility.Setup(u => u.IsManagedAssembly(It.Is<string>(s => Path.GetFileName(s) == "test.dll"))).Returns(false);

                var found = resolver.GetAssemblyNames(_workingDirectory).ToList();

                found.ShouldNotBeEmpty();
                found.Count.ShouldEqual(3);
            }
Пример #28
0
            public void WhenDllsAreMatchedDllFilePathsAreCorrectlyConcatenated()
            {
                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                var found = resolver.GetAssemblyNames(_workingDirectory);

                found.First().ShouldEqual("c:\\test\\packages\\id.3.0\\test.dll");
                found.ElementAt(1).ShouldEqual("c:\\test\\packages\\id.3.0\\test2.dll");
            }
            public void WhenNoPackagesAreFoundShouldLogWarning()
            {
                // arrange
                _packageContainer.Setup(i => i.FindPackage(It.IsAny<string>(), It.IsAny<IPackageReference>()))
                                 .Returns<List<IPackageObject>>(null);

                var resolver = new PackageAssemblyResolver(_filesystem.Object, _packageContainer.Object, _logger.Object);

                // act
                resolver.GetAssemblyNames(_workingDirectory);

                // assert
                _logger.Verify(i => i.WarnFormat(
                    It.IsAny<IFormatProvider>(),
                    It.Is<string>(x => x == "Cannot find: {0} {1}"),
                    It.IsAny<object>(),
                    It.IsAny<object>()),
                    Times.Exactly(_packageContainer.Object.FindReferences("foo").Count()));
            }