public void TestStream()
        {
            Stream stream1 = "test".AsStream();
            IFileSystem fs = new MockFileSystem();
            fs.AddFile(@"c:\test.config",stream1);
            //Stream stream2 = fs.OpenFile();

        }
 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 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 CanOutputPackageConfigWithSingleEntry()
        {
            var fileList = new List<string>() { "Assembly.Common.dll" };
            var packages = new List<IPackage> { PackageUtility.CreatePackage("Assembly.Common", "1.0", assemblyReferences: fileList) };

            var assemblies = new List<string>() { "Assembly.Common.dll" };
            var filesystem = new MockFileSystem();
            //filesystem.Root = @"c:\test";

            var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock<IConsole>().Object);
            var resolved = assemblyResolver.ResolveAssemblies(false);
            assemblyResolver.OutputPackageConfigFile();
            Assert.AreEqual(1,filesystem.Paths.Count);
            var file = new PackageReferenceFile(filesystem,".\\packages.config");
            Assert.AreEqual(1, file.GetPackageReferences().Count());
        }
        public void WillChoosePackageWithSmallestNumberOfAssembliesFromMultipleMatches()
        {
            var packages = new List<IPackage> 
            {
                PackageUtility.CreatePackage("Assembly.Common", "1.0", assemblyReferences: new List<string>() { "Assembly.Common.dll" }),
                PackageUtility.CreatePackage("Assembly.Other", "1.0", assemblyReferences: new List<string>() { "Assembly.Common.dll", "Assembly.Other.dll" }) 
            };

            var assemblies = new List<string>() { "Assembly.Common.dll" };
            var filesystem = new MockFileSystem();

            var assemblyResolver = new RepositoryAssemblyResolver(assemblies, packages.AsQueryable(), filesystem, new Mock<IConsole>().Object);
            var resolved = assemblyResolver.ResolveAssemblies(false);
            assemblyResolver.OutputPackageConfigFile();
            Assert.AreEqual(1, filesystem.Paths.Count);
            var file = new PackageReferenceFile(filesystem, ".\\packages.config");
            Assert.AreEqual(1, file.GetPackageReferences().Count());
            Assert.AreEqual(true, file.EntryExists("Assembly.Common",SemanticVersion.Parse("1.0")));
        }
 public void ConstructorException(string repositoryConfigPath)
 {
     var mfs = new MockFileSystem();
     mfs.AddFile(repositoryConfigPath);
     new RepositoryGroupManager(repositoryConfigPath, mfs);
 }