Inheritance: IFileSystemQuery
 public FileSystemIntellisenseProvider()
 {
     Optional = false;
     IntellisenseProviderType = IntellisenseProviderType.Default;
     HandlesResultInsertion = true;
     _intellisenseResults = new List<IntellisenseProviderResult>();
     FileSystemQuery = new FileSystemQuery(); 
 }
Ejemplo n.º 2
0
        private static FileSystemQuery GetFileSystemQuery(bool hasShares = true)
        {
            var dirFact = new Mock<IDirectoryEntryFactory>();
            var dir = new Mock<IDirectoryEntry>();
            var dirLocal = new Mock<IDirectory>();
            dirLocal.Setup(a => a.Exists("bob")).Returns(false);
            dirLocal.Setup(a => a.Exists("bo")).Returns(true);
            dirLocal.Setup(a => a.GetFileSystemEntries(It.IsAny<string>(), It.IsAny<string>())).Returns(new[] { "b", "d", "f" });

            var children = new Mock<IDirectoryEntries>();
            var gChildren = new Mock<IDirectoryEntries>();
            var actualChildren = new List<Mock<IDirectoryEntry>>
                {
                    new Mock<IDirectoryEntry>()
                };
            var actualGChildren = new List<Mock<IDirectoryEntry>>
                {
                    new Mock<IDirectoryEntry>()
                };
            actualGChildren.ForEach(
                b => b.Setup(a => a.Name).Returns("a"));
            actualGChildren.ForEach(
                b => b.Setup(a => a.SchemaClassName).Returns("Computer"));
            actualChildren.ForEach(
                b => b.Setup(a => a.SchemaClassName).Returns("Computer"));
            dirFact.Setup(a => a.Create(It.IsAny<string>())).Returns(dir.Object);

            dir.Setup(a => a.Children).Returns(children.Object);
            children.Setup(a => a.GetEnumerator())
                    .Returns(actualChildren.Select(a => a.Object)
                                           .GetEnumerator());
            actualChildren.First().Setup(a => a.Children).Returns(gChildren.Object);
            gChildren.Setup(a => a.GetEnumerator()).Returns(actualGChildren.Select(a => a.Object).GetEnumerator());
            IList<Share> shares = hasShares? new List<Share>{new Share("a","b",ShareType.Disk)}  : new List<Share>();
            var sFact = new Mock<IShareCollectionFactory>();
            sFact.Setup(a => a.CreateShareCollection(It.IsAny<string>())).Returns(new ShareCollection(shares));

            //------------Execute Test---------------------------
            var query = new FileSystemQuery(dirLocal.Object, dirFact.Object, sFact.Object);

            return query;
        }
Ejemplo n.º 3
0
        public void FileSystemQuery_FindNetworkComputers_ValidEntries_ExpectReturned()
        {
            //------------Setup for test--------------------------
            var dirFact = new Mock<IDirectoryEntryFactory>();
            var dir = new Mock<IDirectoryEntry>();
            var children = new Mock<IDirectoryEntries>();
            var gChildren = new Mock<IDirectoryEntries>();
            var actualChildren = new List<Mock<IDirectoryEntry>>
                {
                    new Mock<IDirectoryEntry>()

                };
               var actualGChildren = new List<Mock<IDirectoryEntry>>
                {
                    new Mock<IDirectoryEntry>()

                };
            actualGChildren.ForEach(
                b=>b.Setup(a=>a.Name).Returns("a"));
            actualGChildren.ForEach(
                b => b.Setup(a => a.SchemaClassName).Returns("Computer"));
            actualChildren.ForEach(
                b=>b.Setup(a=>a.SchemaClassName).Returns("Computer"));
            dirFact.Setup(a => a.Create(It.IsAny<string>())).Returns(dir.Object);

            dir.Setup(a => a.Children).Returns(children.Object);
            children.Setup(a => a.GetEnumerator())
                .Returns(actualChildren.Select(a=>a.Object)
                .GetEnumerator());
            actualChildren.First().Setup(a => a.Children).Returns(gChildren.Object);
            gChildren.Setup(a => a.GetEnumerator()).Returns(actualGChildren.Select(a => a.Object).GetEnumerator());
            //------------Execute Test---------------------------
            var query = new FileSystemQuery(new DirectoryWrapper(), dirFact.Object, new ShareCollectionFactory());

            var res = query.FindNetworkComputers();
            //------------Assert Results-------------------------
            Assert.AreEqual(res.Count, 1);
            Assert.AreEqual("\\\\a", res[0]);
        }
Ejemplo n.º 4
0
        public void FileSystemQuery_QueryList_NullPath_ExpectLocalDrives()
        {
            //------------Setup for test--------------------------
             var dir = new Mock<IDirectory>();
             dir.Setup(a => a.GetLogicalDrives()).Returns(new[] { "a", "b", "c" });
             var query = new FileSystemQuery(dir.Object, new DirectoryEntryFactory(), new ShareCollectionFactory());

             query.QueryList(null);
             //------------Assert Results-------------------------
             var files = query.QueryCollection;
             Assert.AreEqual(3, files.Count);
             Assert.AreEqual("a", files[0]);
             Assert.AreEqual("b", files[1]);
             Assert.AreEqual("c", files[2]);
        }
Ejemplo n.º 5
0
        public void FileSystemQuery_SearchForFileAndFolders_DriveSearchPath_ExpectCurrentValues()
        {
            //------------Setup for test--------------------------
             var dir = new Mock<IDirectory>();
             dir.Setup(a => a.GetFileSystemEntries(It.IsAny<string>())).Returns(new[] { "a", "b", "c" });
             dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(true);
             var query = new FileSystemQuery(dir.Object, new DirectoryEntryFactory(), new ShareCollectionFactory());
             var files = new List<string> { "non" };

             files = query.SearchForFileAndFolders(@"c:", files, '\\');
             //------------Assert Results-------------------------

             Assert.AreEqual(files.Count, 3);
             Assert.AreEqual("a", files[0]);
             Assert.AreEqual("b", files[1]);
             Assert.AreEqual("c", files[2]);
        }
Ejemplo n.º 6
0
        public void FileSystemQuery_GetServerFolderShare_PathLength_ExpectFalse()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var query = new FileSystemQuery();
            string sServerFolderShare;
            var res = query.GetServerFolderShare("bob", out sServerFolderShare);
            //------------Assert Results-------------------------
            Assert.IsFalse(res);
        }
Ejemplo n.º 7
0
        public void FileSystemQuery_GetServerFolderShare_MultipleSlashesShareName_ExpectTrue()
        {
            //------------Setup for test--------------------------
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists("\\\\bobthebuilder\\dave")).Returns(true);

            //------------Execute Test---------------------------
            var query = new FileSystemQuery(dir.Object, new DirectoryEntryFactory(),new ShareCollectionFactory());
            string sServerFolderShare;
            var res = query.GetServerFolderShare("\\\\bobthebuilder\\dave", out sServerFolderShare);
            //------------Assert Results-------------------------
            Assert.IsTrue(res);
        }
Ejemplo n.º 8
0
        public void FileSystemQuery_GetServerFolderShare_MultipleSlashesNoShareName_ExpectFalse()
        {
            //------------Setup for test--------------------------

            //------------Execute Test---------------------------
            var query = new FileSystemQuery();
            string sServerFolderShare;
            var res = query.GetServerFolderShare("\\\\bobthebuilder", out sServerFolderShare);
            //------------Assert Results-------------------------
            Assert.IsFalse(res);
        }
Ejemplo n.º 9
0
        public void FileSystemQuery_GetServerFolderShare_DefaultValue_ExpectTrue()
        {
            //------------Setup for test--------------------------
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists("\\\\bobthebuilder\\dave")).Returns(false).Verifiable();

            //------------Execute Test---------------------------
            var query = new FileSystemQuery(dir.Object, new DirectoryEntryFactory(), new ShareCollectionFactory());
            string sServerFolderShare;
            var res = query.GetServerFolderShare("\\\\bobthebuilder\\dave\\", out sServerFolderShare);
            //------------Assert Results-------------------------
            Assert.IsTrue(res);
            Assert.AreEqual(@"\\BOBTHEBUILDER\DAVE\",sServerFolderShare);
        }
Ejemplo n.º 10
0
        public void FileSystemQuery_GetFilesAndFoldersIncludingNetwork_MultipleSlashesShareNameDoesNotExist_ExpectFalse()
        {
            //------------Setup for test--------------------------
            var dir = new Mock<IDirectory>();
            dir.Setup(a => a.Exists("\\\\bobthebuilder\\dave")).Returns(true).Verifiable();
            dir.Setup(a => a.GetFileSystemEntries("\\\\bobthebuilder\\dave")).Returns(new string[0]);
            //------------Execute Test---------------------------
            var query = new FileSystemQuery(dir.Object, new DirectoryEntryFactory(), new ShareCollectionFactory());

            var res = query.GetFilesAndFoldersIncludingNetwork("\\\\bobthebuilder\\dave",new List<string>(), '\\');
            //------------Assert Results-------------------------
            Assert.AreEqual(res.Count,1);
            Assert.AreEqual("\\\\bobthebuilder\\dave\\".ToUpper(), res[0]);
        }