public void WillChoosePackageWithSmallestNumberOfAssembliesFromMultipleMatches() { var packages = new List <IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: new List <string>() { AssemblyCommonDll }), PackageUtility.CreatePackage("Assembly.Other", "1.0", assemblyReferences: new List <string>() { AssemblyCommonDll, "Assembly.Other.dll" }) }; var assemblies = new List <string>() { AssemblyCommonDll }; var filesystem = new MockFileSystem(); var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock <IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false); resolved.OutputPackageConfigFile(); Assert.AreEqual(1, filesystem.Paths.Count); var file = new PackageReferenceFile(filesystem, string.Concat(filesystem.Root, "packages.config")); Assert.AreEqual(1, file.GetPackageReferences().Count()); Assert.AreEqual(true, file.EntryExists(AssemblyCommon, SemanticVersion.Parse("1.0"))); }
public void CanOutputPackageConfigWithSingleEntry() { var fileList = new List <string>() { AssemblyCommonDll }; var packages = new List <IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: fileList) }; var assemblies = new List <string>() { AssemblyCommonDll }; var filesystem = new MockFileSystem(); //filesystem.Root = @"c:\test"; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock <IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false); resolved.OutputPackageConfigFile(); Assert.AreEqual(1, filesystem.Paths.Count); var file = new PackageReferenceFile(filesystem, string.Concat(filesystem.Root, "packages.config")); Assert.AreEqual(1, file.GetPackageReferences().Count()); }
public void CanFindMultipleAssembliesInMultiplePackagesExhaustively() { var fileList = new List <string>() { AssemblyCommonDll, AssemblyDataDll }; var packages = new List <IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.2", assemblyReferences: fileList, isLatest: true), PackageUtility.CreatePackage(AssemblyCommon, "1.1", assemblyReferences: fileList, isLatest: false), PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: fileList, isLatest: false), PackageUtility.CreatePackage(AssemblyData, "1.0", assemblyReferences: new List <string>() { AssemblyDataDll }, isLatest: true) }; var assemblies = new List <string>() { AssemblyCommonDll, AssemblyDataDll }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock <MockFileSystem>().Object, new Mock <IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(true).ResolvedMappings; Assert.AreEqual(3, resolved[AssemblyCommonDll].Count); Assert.AreEqual(4, resolved[AssemblyDataDll].Count); }
public void CanFindAssemblyInSinglePackage(int numberOfRepeatedAssemblies) { var fileList = new List <string>() { AssemblyCommonDll }; var packages = new List <IPackage> { PackageUtility.CreatePackage(AssemblyCommon, "1.0", assemblyReferences: fileList) }; var assemblies = Enumerable.Repeat(AssemblyCommonDll, numberOfRepeatedAssemblies).ToList(); var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock <MockFileSystem>().Object, new Mock <IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false).ResolvedMappings; Assert.AreEqual(1, resolved[AssemblyCommonDll].Count); }
public bool CanDetermineVersionlessPackageIsInstalled(string id, string onDiskVersion, string packageVersion, bool installedUsingMultipleVersion, bool currentlyAllowMultipleVersions, bool exhaustive) { var mfs = new Mock <MockFileSystem>() { CallBase = true }; mfs.Setup(m => m.Root).Returns(@"c:\packages"); var installPathResolver = new DefaultPackagePathResolver(mfs.Object, installedUsingMultipleVersion); var currentPathResolver = new DefaultPackagePathResolver(mfs.Object, currentlyAllowMultipleVersions); var testPackage = new DataServicePackage() { Version = packageVersion, Id = id }; var filePackage = new DataServicePackage() { Version = onDiskVersion, Id = id }; IPackage zipPackage = null; if (!string.IsNullOrEmpty(onDiskVersion)) { string baseLocation = installPathResolver.GetInstallPath(filePackage); string fileName = installPathResolver.GetPackageFileName(filePackage.Id, SemanticVersion.Parse(filePackage.Version)); string filePath = Path.Combine(baseLocation, fileName); zipPackage = PackageUtility.GetZipPackage(filePackage.Id, filePackage.Version); mfs.Setup(m => m.FileExists(filePath)).Returns(true); mfs.Setup(m => m.OpenFile(filePath)).Returns(zipPackage.GetStream()); mfs.Object.AddFile(filePath, zipPackage.GetStream()); } var pm = new PackageManager(new MockPackageRepository(), currentPathResolver, mfs.Object); var exists = pm.IsPackageInstalled(testPackage, exhaustive: exhaustive); //var test = testPackage.IsPackageInstalled(allowMultipleVersions, pm, mfs.Object); return(exists); }
public void NonExhaustiveSearchStopsAfterResolvingOnePackagePerAssembly() { var willThrowErrorIfManipulatedAsPath = new List <string>() { "c:\\temp c:\\windows" }; var packages = new List <IPackage> { PackageUtility.CreatePackage("Assembly.Common", "1.2", assemblyReferences: new[] { AssemblyCommonDll }, isLatest: true), PackageUtility.CreatePackage("Assembly.Data", "1.1", assemblyReferences: new[] { AssemblyDataDll }, isLatest: false), PackageUtility.CreatePackage("Assembly.Common", "1.0", assemblyReferences: willThrowErrorIfManipulatedAsPath, isLatest: false) }; var assemblies = new List <string>() { AssemblyCommonDll, AssemblyDataDll }; var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), new Mock <MockFileSystem>().Object, new Mock <IConsole>().Object); var resolved = assemblyResolver.GetAssemblyToPackageMapping(false).ResolvedMappings; Assert.AreEqual(1, resolved[AssemblyCommonDll].Count); Assert.AreEqual(1, resolved[AssemblyDataDll].Count); }