public void PackageReferenceRepositoryDoNotFindLatestPackageIfItDoesNotExist()
        {
            // Arrange
            var repository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("A", "1.5");
            var packageD = PackageUtility.CreatePackage("A", "2.0-beta");

            repository.Object.AddPackage(packageA);
            repository.Object.AddPackage(packageB);
            repository.Object.AddPackage(packageC);
            repository.Object.AddPackage(packageD);

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
  <package id=""B"" version=""2.0"" />
  <package id=""A"" version=""1.5"" />
  <package id=""A"" version=""2.0-beta"" />
</packages>");

            ILatestPackageLookup referenceRepository = new PackageReferenceRepository(
                fileSystem,
                repository.Object);

            // Act
            SemanticVersion latestVersion;
            bool            result = referenceRepository.TryFindLatestPackageById("C", out latestVersion);

            // Assert
            Assert.False(result);
            Assert.Null(latestVersion);
        }
        public void PackageReferenceRepositoryFindTheOnlyPackageAsLatestPackage()
        {
            // Arrange
            var repository = new Mock <MockPackageRepository>()
            {
                CallBase = true
            }.As <ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("A", "1.5");
            var packageD = PackageUtility.CreatePackage("A", "2.0-beta");

            repository.Object.AddPackage(packageA);
            repository.Object.AddPackage(packageB);
            repository.Object.AddPackage(packageC);
            repository.Object.AddPackage(packageD);

            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
  <package id=""B"" version=""2.0"" />
  <package id=""A"" version=""1.5"" />
  <package id=""A"" version=""2.0-beta"" />
</packages>");

            ILatestPackageLookup referenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: repository.Object);

            // Act
            SemanticVersion latestVersion;
            bool            result = referenceRepository.TryFindLatestPackageById("B", out latestVersion);

            // Assert
            Assert.True(result);
            Assert.Equal(new SemanticVersion("2.0"), latestVersion);
        }
        public void GetPackageReferencesReturnsFalseForNonExistentId()
        {
            // Arrange
            var config     = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <packages>
          <package id=""A"" version=""1.3.4"" />
          <package id=""A"" version=""2.5-beta"" />
          <package id=""B"" version=""1.0"" />
          <package id=""C"" version=""2.1.4"" />
        </packages>";
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("packages.config", config);
            var sharedRepository           = new Mock <MockPackageRepository>().As <ISharedPackageRepository>();
            var packageReferenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: sharedRepository.Object);

            // Act
            SemanticVersion version;
            bool            result = packageReferenceRepository.TryFindLatestPackageById("does-not-exist", out version);

            // Assert
            Assert.False(result);
            Assert.Null(version);
        }
        public void GetPackageReferencesFindTheOnlyVersionAsLatestVersion()
        {
            // Arrange
            var config     = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <packages>
          <package id=""A"" version=""1.3.4"" />
          <package id=""A"" version=""2.5-beta"" />
          <package id=""B"" version=""1.0"" />
          <package id=""C"" version=""2.1.4"" />
        </packages>";
            var fileSystem = new MockFileSystem();

            fileSystem.AddFile("packages.config", config);
            var sharedRepository           = new Mock <MockPackageRepository>().As <ISharedPackageRepository>();
            var packageReferenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: sharedRepository.Object);

            // Act
            SemanticVersion version;
            bool            result = packageReferenceRepository.TryFindLatestPackageById("B", out version);

            // Assert
            Assert.True(result);
            Assert.Equal(new SemanticVersion("1.0"), version);
        }
        public void PackageReferenceRepositoryDoNotFindLatestPackageIfItDoesNotExist()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("A", "1.5");
            var packageD = PackageUtility.CreatePackage("A", "2.0-beta");
            repository.Object.AddPackage(packageA);
            repository.Object.AddPackage(packageB);
            repository.Object.AddPackage(packageC);
            repository.Object.AddPackage(packageD);

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
  <package id=""B"" version=""2.0"" />
  <package id=""A"" version=""1.5"" />
  <package id=""A"" version=""2.0-beta"" />
</packages>");

            ILatestPackageLookup referenceRepository = new PackageReferenceRepository(
                fileSystem,
                repository.Object);

            // Act
            SemanticVersion latestVersion;
            bool result = referenceRepository.TryFindLatestPackageById("C", out latestVersion);

            // Assert
            Assert.False(result);
            Assert.Null(latestVersion);
        }
        public void GetPackageReferencesReturnsFalseForNonExistentId()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <packages>
          <package id=""A"" version=""1.3.4"" />
          <package id=""A"" version=""2.5-beta"" />
          <package id=""B"" version=""1.0"" />
          <package id=""C"" version=""2.1.4"" />
        </packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var sharedRepository = new Mock<MockPackageRepository>().As<ISharedPackageRepository>();
            var packageReferenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);

            // Act
            SemanticVersion version;
            bool result = packageReferenceRepository.TryFindLatestPackageById("does-not-exist", out version);

            // Assert
            Assert.False(result);
            Assert.Null(version);
        }
        public void GetPackageReferencesFindTheOnlyVersionAsLatestVersion()
        {
            // Arrange
            var config = @"<?xml version=""1.0"" encoding=""utf-8""?>
        <packages>
          <package id=""A"" version=""1.3.4"" />
          <package id=""A"" version=""2.5-beta"" />
          <package id=""B"" version=""1.0"" />
          <package id=""C"" version=""2.1.4"" />
        </packages>";
            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", config);
            var sharedRepository = new Mock<MockPackageRepository>().As<ISharedPackageRepository>();
            var packageReferenceRepository = new PackageReferenceRepository(fileSystem, sharedRepository.Object);

            // Act
            SemanticVersion version;
            bool result = packageReferenceRepository.TryFindLatestPackageById("B", out version);

            // Assert
            Assert.True(result);
            Assert.Equal(new SemanticVersion("1.0"), version);
        }
        public void PackageReferenceRepositoryFindTheOnlyPackageAsLatestPackage()
        {
            // Arrange
            var repository = new Mock<MockPackageRepository>() { CallBase = true }.As<ISharedPackageRepository>();
            var packageA = PackageUtility.CreatePackage("A", "1.0");
            var packageB = PackageUtility.CreatePackage("B", "2.0");
            var packageC = PackageUtility.CreatePackage("A", "1.5");
            var packageD = PackageUtility.CreatePackage("A", "2.0-beta");
            repository.Object.AddPackage(packageA);
            repository.Object.AddPackage(packageB);
            repository.Object.AddPackage(packageC);
            repository.Object.AddPackage(packageD);

            var fileSystem = new MockFileSystem();
            fileSystem.AddFile("packages.config", @"<?xml version=""1.0"" encoding=""utf-8""?>
<packages>
  <package id=""A"" version=""1.0"" />
  <package id=""B"" version=""2.0"" />
  <package id=""A"" version=""1.5"" />
  <package id=""A"" version=""2.0-beta"" />
</packages>");

            ILatestPackageLookup referenceRepository = new PackageReferenceRepository(fileSystem, projectName: null, sourceRepository: repository.Object);

            // Act
            SemanticVersion latestVersion;
            bool result = referenceRepository.TryFindLatestPackageById("B", out latestVersion);

            // Assert
            Assert.True(result);
            Assert.Equal(new SemanticVersion("2.0"), latestVersion);
        }