[TestCase("Assembly.Common", "0.0", "[1.0,2.0]", false, Result = "0.0")] // get latest constrained version (0.0 version)
 public string FindPackageLatestTests(string id, string version, string versionSpec, bool latest)
 {
     var pr = new PackageReference(id, SemanticVersion.Parse(version), string.IsNullOrEmpty(versionSpec) ? new VersionSpec() : VersionUtility.ParseVersionSpec(versionSpec), new FrameworkName(".NET Framework, Version=4.0"), false);
     var prc = new PackageResolutionManager(new Mock<ILogger>().Object, latest, new MemoryBasedPackageCache(new Mock<ILogger>().Object));
     var v = prc.ResolveInstallableVersion(Utilities.GetFactory().CreateRepository("SingleAggregate"), pr);
     return v != null ? v.ToString() : "";
 }
        public string ResolvesUsingMultipleRepos(string id, string version, string spec, bool isLatest)
        {
            var versionSpec = spec == null ? null : VersionUtility.ParseVersionSpec(spec);

            //Add to appropriate cache we want to test based on whether we have a versionspec or not.
            var console = new Mock<ILogger>().Object;
            var cache = new MemoryBasedPackageCache(console);

            //Repository does not have these versions, so any call to it will fail...
            var resolver = new PackageResolutionManager(console, isLatest, cache);
            var remoteRepository = Utilities.GetFactory().CreateRepository("MultiAggregate");
            var result = resolver.ResolveLatestInstallablePackage(remoteRepository, new PackageReference(id, SemanticVersion.Parse(version), versionSpec, null, false));

            //Null result when we call ResolveLastestInstallablePackage when PackageResolutionManager not using Latest
            return result == null ? "" : result.Version.ToString();
        }
        public void CanResolveFromLocalRepository()
        {
            var console = new Mock<ILogger>().Object;
            var resolver = new PackageResolutionManager(console, true, new MemoryBasedPackageCache(console));
            var remoteRepository = Utilities.GetFactory().CreateRepository("SingleAggregate");
            var localRepository = new MockPackageRepository();

            var package = new DataServicePackage()
                              {
                                  Id = "Assembly.Common",
                                  Version = "1.0"
                              };

            var test = resolver.FindPackageInAllLocalSources(localRepository, remoteRepository, package, false, false);
            Assert.AreEqual("Assembly.Common", test.Id);
        }
        public string ResolvesFromCacheFirst(string id, string version, string spec, string cacheVersion, bool isLatest)
        {
            //Setup the package and versionspec for the cache
            var cachePackage = new DataServicePackage() { Id = id, Version = cacheVersion };
            var versionSpec = spec == null ? null : VersionUtility.ParseVersionSpec(spec);

            //Add to appropriate cache we want to test based on whether we have a versionspec or not.
            var console = new Mock<ILogger>().Object;
            var cache = new MemoryBasedPackageCache(console);
            if (versionSpec == null)
                cache.AddCacheEntryByIsLatest(cachePackage);
            else
                cache.AddCacheEntryByConstraint(cachePackage, versionSpec);

            //Repository does not have these versions, so any call to it will fail...
            var resolver = new PackageResolutionManager(console, isLatest, cache);
            var remoteRepository = Utilities.GetFactory().CreateRepository("SingleAggregate");
            var result = resolver.ResolveLatestInstallablePackage(remoteRepository, new PackageReference(id, SemanticVersion.Parse(version), versionSpec, null, false));
            
            //Null result when we call ResolveLastestInstallablePackage when PackageResolutionManager not using Latest
            return result == null ? "" : result.Version.ToString();
        }
        public void WillNotUseODataIfPackageLocal()
        {
            var console = new Mock<ILogger>().Object;
            var resolver = new PackageResolutionManager(console, true, new MemoryBasedPackageCache(console));
            var odata = new Mock<DataServicePackageRepository>(new Uri(@"http://nuget.org"));
            var list = new List<IPackage>()
                           {
                               new DataServicePackage()
                                   {
                                       Id = "Assembly.Common",
                                       Version = "3.0"
                                   }
                           };
            odata.Setup(o => o.GetPackages()).Returns(list.AsQueryable());
            var remoteRepository = new AggregateRepository(new List<IPackageRepository>()
                                                               {
                                                                   Utilities.GetFactory().CreateRepository("SingleAggregate"),
                                                                   odata.Object
                                                               });
        

            var localRepository = new MockPackageRepository();

            var package = new DataServicePackage()
            {
                Id = "Assembly.Common",
                Version = "3.0"
            };

            Assert.AreEqual(true,remoteRepository.GetPackages().Contains(package));
            var local = resolver.FindPackageInAllLocalSources(localRepository, remoteRepository, package, false, false);
            Assert.AreEqual(null, local);

        }
        public void CanResolveInstallablePackages()
        {
            var console = new Mock<ILogger>().Object;
            var resolver = new PackageResolutionManager(console, true, new MemoryBasedPackageCache(console));
            var remoteRepository = Utilities.GetFactory().CreateRepository("SingleAggregate");

            var packageReference = new PackageReference("Assembly.Common", SemanticVersion.Parse("1.0"), new VersionSpec(), new FrameworkName(".NET Framework, Version=4.0"), false);

            var test = resolver.ResolveLatestInstallablePackage(remoteRepository, packageReference);
            Assert.AreEqual("Assembly.Common", test.Id);
        }