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 ConstructorException(string repositoryConfigPath)
 {
     var mfs = new MockFileSystem();
     mfs.AddFile(repositoryConfigPath);
     new RepositoryGroupManager(repositoryConfigPath, mfs);
 }