コード例 #1
0
 public void FileSystemQuery_GetFoldersAndFiles_NullDirectory_ExpectException()
 {
     //------------Setup for test--------------------------
     FileSystemQuery.GetFoldersAndFiles(null, 'c', new DirectoryWrapper());
     //------------Execute Test---------------------------
     //------------Assert Results-------------------------
 }
コード例 #2
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]);
        }
コード例 #3
0
 public FileSystemIntellisenseProvider()
 {
     Optional = false;
     HandlesResultInsertion = true;
     _intellisenseResults   = new List <IntellisenseProviderResult>();
     FileSystemQuery        = new FileSystemQuery();
 }
コード例 #4
0
 public void FileSystemQuery_GetFoldersAndFiles_NullPath_ExpectException()
 {
     //------------Setup for test--------------------------
     FileSystemQuery.GetFoldersAndFiles("b", 'c', null);
     //------------Execute Test---------------------------
     //------------Assert Results-------------------------
 }
コード例 #5
0
        public IList <IntellisenseProviderResult> GetIntellisenseResults(IntellisenseProviderContext context)
        {
            if (context == null)
            {
                return(new List <IntellisenseProviderResult>());
            }

            var results = new List <IntellisenseProviderResult>();

            if (context.DesiredResultSet == IntellisenseDesiredResultSet.EntireSet)
            {
                IntellisenseResults.Clear();
                FileSystemQuery.QueryList("");
                FileSystemQuery.QueryCollection.ForEach(s => IntellisenseResults.Add(new IntellisenseProviderResult(this, s, string.Empty, string.Empty, false)));
                results.AddRange(IntellisenseResults);
            }
            else
            {
                if (!InLiteralRegion(context.InputText, context.CaretPosition))
                {
                    IntellisenseResults.Clear();
                    var regions    = context.InputText.Split(' ');
                    var sum        = 0;
                    var searchText = regions.Select(a => new { a, a.Length }).TakeWhile(a =>
                    {
                        sum = sum + context.CaretPosition;
                        return(sum >= context.CaretPosition);
                    }).Last().a;
                    FileSystemQuery.QueryList(searchText);
                    FileSystemQuery.QueryCollection.ForEach(s => IntellisenseResults.Add(new IntellisenseProviderResult(this, s, string.Empty, string.Empty, false)));
                    results.AddRange(IntellisenseResults);
                }
            }
            return(results);
        }
コード例 #6
0
        public void VerifyCRootExists_ClientApi_LocalInstance()
        {
            var client = new FileSystemQuery();

            var result = client.DoesDirectoryExist(@"c:");

            Xunit.Assert.True(result);
        }
コード例 #7
0
        public void VerifyCRootExists_ClientApi_SignalrRelay()
        {
            var client = new FileSystemQuery(typeof(SignalrRelayProxy <FileSystemQueryRequest, FileSystemQueryResponse>));

            var result = client.DoesDirectoryExist(@"c:");

            Xunit.Assert.True(result);
        }
コード例 #8
0
        public void VerifyBogusPathNotExist_ClientApi_LocalInstance()
        {
            var client = new FileSystemQuery();

            var result = client.DoesDirectoryExist("slkdjfslkdflsdfjlsdkjf");

            Xunit.Assert.False(result);
        }
コード例 #9
0
        public void VerifyBogusPathNotExist_ClientApi_SignalrRelay()
        {
            var client = new FileSystemQuery(typeof(SignalrRelayProxy <FileSystemQueryRequest, FileSystemQueryResponse>));

            var result = client.DoesDirectoryExist("slkdjfslkdflsdfjlsdkjf");

            Xunit.Assert.False(result);
        }
コード例 #10
0
        public void FileSystemQuery_GetFilesListing_NoSeperator_ExpectNoResults()
        {
            var dir = new Mock <IDirectory>();

            dir.Setup(a => a.GetFileSystemEntries(It.IsAny <string>(), It.IsAny <string>())).Returns(new[] { "a", "b", "c" });
            var files = FileSystemQuery.GetFilesListing("bob", 'c', dir.Object);

            Assert.AreEqual(files.Count, 0);
        }
コード例 #11
0
        public void FileSystemQuery_GetServerFolderShare_NullPath_ExpectFalse()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var query = new FileSystemQuery();
            var res   = query.GetServerFolderShare(null, out string sServerFolderShare);

            //------------Assert Results-------------------------
            Assert.IsFalse(res);
        }
コード例 #12
0
        public void FileSystemQuery_GetServerFolderShare_MultipleSlashesNoShareName_ExpectFalse()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var query = new FileSystemQuery();
            var res   = query.GetServerFolderShare("\\\\bobthebuilder", out string sServerFolderShare);

            //------------Assert Results-------------------------
            Assert.IsFalse(res);
        }
コード例 #13
0
        public void FileSystemQuery_GetServerFolderShare_InvalidStartsWith_ExpectFalse()
        {
            //------------Setup for test--------------------------
            //------------Execute Test---------------------------
            var query = new FileSystemQuery();
            var res   = query.GetServerFolderShare("bobthebuilder", out string sServerFolderShare);

            //------------Assert Results-------------------------
            Assert.IsFalse(res);
        }
コード例 #14
0
        public void FileSystemQuery_GetFilesListing_CorrectPath_ExpectResults()
        {
            var dir = new Mock <IDirectory>();

            dir.Setup(a => a.GetFileSystemEntries(It.IsAny <string>(), It.IsAny <string>())).Returns(new[] { "a", "b", "c" });
            dir.Setup(a => a.Exists(It.IsAny <string>())).Returns(true);
            var files = FileSystemQuery.GetFilesListing("bob", 'o', dir.Object);

            Assert.AreEqual(files.Count, 3);
            Assert.AreEqual("a", files[0]);
            Assert.AreEqual("b", files[1]);
            Assert.AreEqual("c", files[2]);
        }
コード例 #15
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, null, new ShareCollectionFactory());
            var res   = query.GetServerFolderShare("\\\\bobthebuilder\\dave", out string sServerFolderShare);

            //------------Assert Results-------------------------
            Assert.IsTrue(res);
        }
コード例 #16
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, null, new ShareCollectionFactory());
            var res   = query.GetServerFolderShare("\\\\bobthebuilder\\dave\\", out string sServerFolderShare);

            //------------Assert Results-------------------------
            Assert.IsTrue(res);
            Assert.AreEqual(@"\\BOBTHEBUILDER\DAVE\", sServerFolderShare);
        }
コード例 #17
0
        public void FileSystemQuery_GetServerFolderShare_MultipleSlashesShareNameDoesNotExist_ExpectFalse()
        {
            //------------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.IsFalse(res);
            dir.Verify(a => a.Exists("\\\\bobthebuilder\\dave"));
        }
コード例 #18
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, null, 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]);
        }
コード例 #19
0
        public async void VerifyBogusPathNotExist_ServiceApi_LocalInstance()
        {
            var service = new FileSystemQuery().Service;

            var request = new FileSystemQueryRequest
            {
                FolderPath = @"slkdjfslkdflsdfjlsdkjf",
                QueryType  = FileSystemQueryTypeEnum.DirectoryExists
            };

            var result = await service.Execute(request);

            var response = result.ResponseString;

            Xunit.Assert.False(bool.Parse(response));
        }
コード例 #20
0
        public async void VerifyCRootExists_ServiceApi_LocalInstance()
        {
            var service = new FileSystemQuery().Service;

            var request = new FileSystemQueryRequest
            {
                FolderPath = @"c:",
                QueryType  = FileSystemQueryTypeEnum.DirectoryExists
            };

            var result = await service.Execute(request);

            var response = result.ResponseString;

            Xunit.Assert.True(bool.Parse(response));
        }
コード例 #21
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);
        }
コード例 #22
0
        public void FileSystemQuery_GetFoldersAndFiles_ValidPathAndDir_ExpectResults()
        {
            //------------Setup for test--------------------------

            var dir = new Mock <IDirectory>();

            dir.Setup(a => a.Exists(It.IsAny <string>())).Returns(true);
            dir.Setup(a => a.GetFileSystemEntries(It.IsAny <string>())).Returns(new[] { "a", "d", "f" });
            //------------Execute Test---------------------------
            var files = FileSystemQuery.GetFoldersAndFiles("bob", 'o', dir.Object);

            //------------Assert Results-------------------------
            Assert.AreEqual(files.Count, 3);
            Assert.AreEqual(files[0], "a");
            Assert.AreEqual(files[1], "d");
            Assert.AreEqual(files[2], "f");
        }
コード例 #23
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, null, 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]);
        }
コード例 #24
0
        public void FileSystemQuery_GetFilesAndFoldersFromDrive_NonDriveSearchPath_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, null, new ShareCollectionFactory());
            var files = new List <string> {
                "non"
            };

            files = query.GetFilesAndFoldersFromDrive("bobo", files, 'o');
            //------------Assert Results-------------------------
            Assert.AreEqual(files.Count, 1);
            Assert.AreEqual("non", files[0]);
        }
コード例 #25
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]);
        }
コード例 #26
0
        public IList <IntellisenseProviderResult> GetIntellisenseResults(IntellisenseProviderContext context)
        {
            var results = new List <IntellisenseProviderResult>();

            if (context.DesiredResultSet == IntellisenseDesiredResultSet.EntireSet)
            {
                FileSystemQuery.QueryList("");
                FileSystemQuery.QueryCollection.ForEach(s => _intellisenseResults.Add(new IntellisenseProviderResult(this, s, string.Empty, string.Empty, false)));
                results.AddRange(_intellisenseResults);
            }
            else
            {
                if (!InLiteralRegion(context.InputText, context.CaretPosition))
                {
                    _intellisenseResults.Clear();
                    string searchText = context.InputText; //context.InputText.Substring(context.CaretPositionOnPopup, (context.CaretPosition - context.CaretPositionOnPopup));
                    FileSystemQuery.QueryList(searchText);
                    FileSystemQuery.QueryCollection.ForEach(s => _intellisenseResults.Add(new IntellisenseProviderResult(this, s, string.Empty, string.Empty, false)));
                    results.AddRange(_intellisenseResults);
                }
            }
            return(results);
        }
コード例 #27
0
        static void DoFileSystemQuery()
        {
            Console.Write("Enter folder path to check if exists: ");
            var folderPath = Console.ReadLine().Trim();

            if (folderPath == string.Empty)
            {
                return;
            }

            var fsq = default(IFileSystemQuery);

            if (RelayUtil.RelayTypeDflt == RelayTypeEnum.SignalR)
            {
                fsq = new FileSystemQuery(typeof(SignalrRelayProxy <FileSystemQueryRequest, FileSystemQueryResponse>));
            }
            if (RelayUtil.RelayTypeDflt == RelayTypeEnum.NamedPipes)
            {
                fsq = new FileSystemQuery(typeof(NamedPipeRelayProxy <FileSystemQueryRequest, FileSystemQueryResponse>));
            }
            var result = fsq.DoesDirectoryExist(folderPath);

            Console.WriteLine($"Was folder path [{folderPath}] found? [{result}].");
        }
コード例 #28
0
        private async void PressMeButton_Clicked(object sender, EventArgs e)
        {
            var button = (Button)sender;

            button.Text = "Init";
            //Task.Run(() =>
            //{
            HubConnection _hub = null;

            //try
            //{
            //    //button.Text = "Building...";
            //    //Task.Delay(1500).Wait();
            //    _hub = new HubConnectionBuilder()
            //        .WithUrl("http://*****:*****@"c:\";
                var fsq        = new FileSystemQuery(typeof(SignalrRelayProxy <FileSystemQueryRequest, FileSystemQueryResponse>));
                //var fsq = new FileSystemQuery(typeof(NamedPipeRelayProxy<FileSystemQueryRequest, FileSystemQueryResponse>));
                var result = fsq.DoesDirectoryExist(folderPath);
                button.Text = $"Does folder [{folderPath}] exist? [{result}].";
            }
            catch (Exception ex)
            {
                var txt = ex.Message;
                if (ex.InnerException != null)
                {
                    txt += Environment.NewLine + ex.InnerException.Message;
                }
                button.Text = txt;
            }
            finally
            {
            }

            //}).Wait();
        }
コード例 #29
0
 public void FileSystemQuery_GetFilesListing_NullDir_ExpectException()
 {
     FileSystemQuery.GetFilesListing("bob", 'c', null);
 }