public void Setup()
 {
     _mfs = new MockFileSystem();
     _mfs.CreateDirectory(@"c:\files");
     _mfs.CreateDirectory(@"c:\files\TestSolution");
     _mfs.CreateDirectory(@"c:\files\TestSolution\packages");
     _mfs.AddFile(@"c:\files\TestSolution\packages\repositories.config", baseRepositoriesConfig);
     _mfs.AddFile(@"c:\files\TestSolution\repositories.config", baseRepositoriesConfig);
     _mfs.CreateDirectory(@"c:\random\empty");
 }
        public void TestStream()
        {
            Stream stream1 = "test".AsStream();
            IFileSystem fs = new MockFileSystem();
            fs.AddFile(@"c:\test.config",stream1);
            //Stream stream2 = fs.OpenFile();

        }
        public void CanCleanPackageFolders()
        {
            var mfs = new MockFileSystem();

            mfs.CreateDirectory("c:\\packages\\Component");
            mfs.AddFile("c:\\packages\\Component\\test.txt", "blah");
            mfs.AddFile("c:\\packages\\Component\\test.dll","blah");
            mfs.AddFile("c:\\packages\\repositories.config","blah");

            var re = new Mock<IRepositoryEnumerator>();
            re.Setup(r => r.GetPackageReferenceFiles(It.IsAny<FileInfo>())).Returns(new List<PackageReferenceFile>());
            var repositoryManager = new RepositoryManager(@"c:\packages\repositories.config", re.Object, mfs);
            
            Assert.AreEqual(1, mfs.GetDirectories(repositoryManager.RepositoryConfig.Directory.FullName).Count());
            
            //_repositoryManager.CleanPackageFolders();

            Assert.AreEqual(0, mfs.GetDirectories(repositoryManager.RepositoryConfig.Directory.FullName).Count());
        }
        public void ConstructParser()
        {
            var mfs = new MockFileSystem();
            var correctConfig = @"<?xml version='1.0' encoding='utf-8'?>
                                    <repositories>
                                        <repository path='..\Project1\packages.config' />
                                        <repository path='..\Project2\packages.config' />
                                        <repository path='..\Project3\packages.config' />
                                    </repositories>";

            mfs.AddFile(@"c:\packages\repositories.config", correctConfig);
            mfs.AddFile(@"c:\project1\packages.config", correctConfig);
            mfs.AddFile(@"c:\project2\packages.config", correctConfig);
            mfs.AddFile(@"c:\project3\packages.config", correctConfig);
            mfs.AddFile(@"c:\packages\repositories.config", correctConfig);

            var repositoryManager = new RepositoryManager(@"c:\packages\repositories.config", new RepositoryEnumerator(mfs), mfs);
            Assert.IsNotNull(repositoryManager);
            Assert.AreEqual(3, repositoryManager.PackageReferenceFiles.Count());
        }
        public void CanEnumerateOverSet()
        {
            IFileSystem fs = new MockFileSystem();
            var test1 = @"c:\test1\packages.config";
            var test2 = @"c:\test1\packages.config";

            var p1 = @"<packages>
                      <package id='Test' version='1.0.0.0' />
                      <package id='Test' version='1.1.0.0' />
                      <package id='Test' version='1.2.0.07' />
                    </packages>";

            var p2 = @"<packages>
                      <package id='Test' version='1.0.0.0' />
                      <package id='Test' version='1.1.0.0' />
                      <package id='Test' version='1.2.0.07' />
                    </packages>";

            fs.AddFile(test1, p1.AsStream());
            fs.AddFile(test2, p2.AsStream());

            var list = new List<PackageReferenceFile>();

            list.Add(new PackageReferenceFile(fs, test1));
            list.Add(new PackageReferenceFile(fs, test2));


            PackageEnumerator enumerator = new PackageEnumerator();
            var idOnly = enumerator.GetPackageReferences(list, (a, b) => { }, PackageReferenceEqualityComparer.Id);
            Assert.AreEqual(1, idOnly.Count());

            var idAndVersion = enumerator.GetPackageReferences(list, (a, b) => { }, PackageReferenceEqualityComparer.IdAndVersion);
            Assert.AreEqual(3, idAndVersion.Count());


        }
        public void ReferenceToPackageIdNotOnFeedStays()
        {
            var fileSystem = new MockFileSystem(@"d:\");
            fileSystem.AddFile(@"d:\test\packages.config",
                "<packages>" +
                    "<package id=\"Missing\" version=\"1.0.0.0\" />" +
                "</packages>");

            var repository = new MockPackageRepository("http://test.com");

            var command = new FixReferences(fileSystem, repository, new Console()) { Directory = @"d:\test" };
            command.Execute();

            var packageReferences = new PackageReferenceFile(fileSystem, @"d:\test\packages.config").GetPackageReferences().ToList();
            Assert.AreEqual("1.0.0.0", packageReferences.First(p => p.Id == "Missing").Version.Version.ToString());
        }
        public void CanDetectMissingVersionAndUpdateToValid()
        {
            var fileSystem = new MockFileSystem(@"d:\");
            fileSystem.AddFile(@"d:\test\packages.config",
                "<packages>" +
                    "<package id=\"Test\" version=\"1.0.0.0\" />" +
                    "<package id=\"Other\" version=\"1.0.0.0\" />" +
                "</packages>");

            var repository = new MockPackageRepository("http://test.com");
            repository.AddPackage(PackageUtility.CreatePackage("Test", "2.0.0.0"));
            repository.AddPackage(PackageUtility.CreatePackage("Other", "1.0.0.0"));

            var command = new FixReferences(fileSystem, repository, new Console()) {Directory = @"d:\test"};
            command.Execute();

            var packageReferences = new PackageReferenceFile(fileSystem, @"d:\test\packages.config").GetPackageReferences().ToList();
            Assert.AreEqual("2.0.0.0", packageReferences.First(p => p.Id == "Test").Version.Version.ToString());
            Assert.AreEqual("1.0.0.0", packageReferences.First(p => p.Id == "Other").Version.Version.ToString());
        }
 public void ConstructorException(string repositoryConfigPath)
 {
     var mfs = new MockFileSystem();
     mfs.AddFile(repositoryConfigPath);
     new RepositoryGroupManager(repositoryConfigPath, mfs);
 }