コード例 #1
0
        private int RunTests(TestOptions options)
        {
            if (options.Sink != null)
            {
                var parts              = options.Sink.Split('|');
                var packagesPath       = Path.GetFullPath(parts[0]);
                var dependencyResolver = new NuGetDependencyResolver(packagesPath);
                var lib = dependencyResolver.GetDescription(new LibraryRange
                {
                    Name = parts[1]
                }, _environment.RuntimeFramework);
                dependencyResolver.Initialize(new[] { lib }, _environment.RuntimeFramework);

                var dependencyLoader = new NuGetAssemblyLoader(_loadContextAccessor, dependencyResolver);
                var referenceLoader  = new ReferenceLoader(_frameworkReferenceResolver, _environment.RuntimeFramework);

                using (_container.AddLoader(dependencyLoader))
                    using (_container.AddLoader(referenceLoader))
                        using (var context = _loadContextFactory.Create())
                        {
                            var assembly = dependencyLoader.Load(parts[1], context);
                            var locator  = assembly.GetCustomAttributes()
                                           .OfType <ITestSinkFactory>()
                                           .FirstOrDefault();

                            if (locator == null)
                            {
                                throw new InvalidOperationException($"No assembly attribute found that implements the interface 'ITestSinkLocator' in the assembly ${assembly.GetName().Name}");
                            }

                            var testServices = new ServiceProvider(_services);
                            testServices.Add(typeof(ITestSinkFactory), locator);

                            return(RunTestAssembly(options, ".", _container, testServices) ? 0 : -1);
                        }
            }
            else
            {
                return(RunTestAssembly(options, ".", _container, _services) ? 0 : -1);
            }
        }
コード例 #2
0
        public void LibrariesAreResolvedCorrectly(string packageName, string framework, bool resolved)
        {
            var repo = new PackageRepository("path/to/packages");
            var resolver = new NuGetDependencyResolver(repo);

            var net45Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName(".NETFramework,Version=v4.5"),
                Libraries = new List<LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("ref", "net45", "_._") },
                        RuntimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net45", "_._") }
                    }
                }
            };

            var dnx451Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName("DNX,Version=v4.5.1"),
                Libraries = new List<LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net451", "Net451LibPackage.dll") },
                        RuntimeAssemblies = new List<LockFileItem> { Path.Combine("lib", "net451", "Net451LibPackage.dll") }
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List<LockFileItem> { Path.Combine("ref", "net451", "Net451LibPackage.dll") }
                    },
                    new LockFileTargetLibrary
                    {
                        Name = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    }
                }
            };

            var metaPackageLibrary = new LockFilePackageLibrary
            {
                Name = "MetaPackage",
                Version = SemanticVersion.Parse("1.0.0")
            };

            var net451LibPackageLibrary = new LockFilePackageLibrary
            {
                Name = "Net451LibPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("lib", "net451", "Net451LibPackage.dll"),
                    Path.Combine("lib", "net451", "Net451LibPackage.xml")
                }
            };

            var net451RefPackageLibrary = new LockFilePackageLibrary
            {
                Name = "Net451RefPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("ref", "net451", "Net451LibPackage.dll")
                }
            };

            var assemblyPlaceholderPackageLibrary = new LockFilePackageLibrary
            {
                Name = "AssemblyPlaceholderPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files = new List<string>
                {
                    Path.Combine("lib", "net45", "_._"),
                    Path.Combine("ref", "net45", "_._"),
                }
            };

            var lockFile = new LockFile()
            {
                Targets = new List<LockFileTarget> { net45Target, dnx451Target },
                PackageLibraries = new List<LockFilePackageLibrary>
                {
                    metaPackageLibrary,
                    net451LibPackageLibrary,
                    net451RefPackageLibrary,
                    assemblyPlaceholderPackageLibrary
                }
            };

            resolver.ApplyLockFile(lockFile);

            var libToLookup = new LibraryRange(packageName, frameworkReference: false);
            Assert.Equal(resolved, resolver.GetDescription(libToLookup, new FrameworkName(framework)).Resolved);
        }
コード例 #3
0
        public void LibrariesAreResolvedCorrectly(string packageName, string framework, bool resolved)
        {
            var repo     = new PackageRepository("path/to/packages");
            var resolver = new NuGetDependencyResolver(repo);

            var net45Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName(".NETFramework,Version=v4.5"),
                Libraries       = new List <LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name    = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List <LockFileItem> {
                            Path.Combine("ref", "net45", "_._")
                        },
                        RuntimeAssemblies = new List <LockFileItem> {
                            Path.Combine("lib", "net45", "_._")
                        }
                    }
                }
            };

            var dnx451Target = new LockFileTarget
            {
                TargetFramework = new FrameworkName("DNX,Version=v4.5.1"),
                Libraries       = new List <LockFileTargetLibrary>
                {
                    new LockFileTargetLibrary
                    {
                        Name    = "MetaPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "Net451LibPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List <LockFileItem> {
                            Path.Combine("lib", "net451", "Net451LibPackage.dll")
                        },
                        RuntimeAssemblies = new List <LockFileItem> {
                            Path.Combine("lib", "net451", "Net451LibPackage.dll")
                        }
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "Net451RefPackage",
                        Version = SemanticVersion.Parse("1.0.0"),
                        CompileTimeAssemblies = new List <LockFileItem> {
                            Path.Combine("ref", "net451", "Net451LibPackage.dll")
                        }
                    },
                    new LockFileTargetLibrary
                    {
                        Name    = "AssemblyPlaceholderPackage",
                        Version = SemanticVersion.Parse("1.0.0")
                    }
                }
            };

            var metaPackageLibrary = new LockFilePackageLibrary
            {
                Name    = "MetaPackage",
                Version = SemanticVersion.Parse("1.0.0")
            };

            var net451LibPackageLibrary = new LockFilePackageLibrary
            {
                Name    = "Net451LibPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files   = new List <string>
                {
                    Path.Combine("lib", "net451", "Net451LibPackage.dll"),
                    Path.Combine("lib", "net451", "Net451LibPackage.xml")
                }
            };

            var net451RefPackageLibrary = new LockFilePackageLibrary
            {
                Name    = "Net451RefPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files   = new List <string>
                {
                    Path.Combine("ref", "net451", "Net451LibPackage.dll")
                }
            };

            var assemblyPlaceholderPackageLibrary = new LockFilePackageLibrary
            {
                Name    = "AssemblyPlaceholderPackage",
                Version = SemanticVersion.Parse("1.0.0"),
                Files   = new List <string>
                {
                    Path.Combine("lib", "net45", "_._"),
                    Path.Combine("ref", "net45", "_._"),
                }
            };

            var lockFile = new LockFile()
            {
                Targets = new List <LockFileTarget> {
                    net45Target, dnx451Target
                },
                PackageLibraries = new List <LockFilePackageLibrary>
                {
                    metaPackageLibrary,
                    net451LibPackageLibrary,
                    net451RefPackageLibrary,
                    assemblyPlaceholderPackageLibrary
                }
            };

            resolver.ApplyLockFile(lockFile);

            var libToLookup = new LibraryRange(packageName, frameworkReference: false);

            Assert.Equal(resolved, resolver.GetDescription(libToLookup, new FrameworkName(framework)).Resolved);
        }