Ejemplo n.º 1
0
        protected override void ConfigureObjectCollector()
        {
            if (base.ObjectCollector == null)
            {
                var connectionScope = ((FileConnectionProvider)FileConnectionProvider).ConnectionScope;
                var newWmiDataProvider = new WmiDataProvider(connectionScope);
                var newFileProvider = new WindowsFileProvider(TargetInfo) { WmiDataProvider = newWmiDataProvider };

                ObjectCollector = new TextFileContentObjectCollector() { FileContentProvider = newFileProvider, TargetInfo = TargetInfo };
                FileDataSource = new FileObjectCollector() { WmiDataProvider = newWmiDataProvider };
            }

            if (base.ItemTypeGenerator == null)
            {
                var newFileProvider =
                    new WindowsFileProvider(this.TargetInfo)
                    {
                        WmiDataProvider =
                            WmiDataProviderFactory
                                .CreateWmiDataProviderForFileSearching(this.TargetInfo)
                    };

                var newOperationEvaluator =
                    new TextFileContentEntityOperationEvaluator(ObjectCollector, newFileProvider, FamilyEnumeration.windows);

                ItemTypeGenerator = new TextFileContentItemTypeGenerator()
                {
                    OperationEvaluator = newOperationEvaluator
                };
            }
        }
        public void Should_be_possible_to_get_more_than_one_line_with_pattern_match()
        {
            var fileContentSearchingParameters =
                TextFileContentObjectCollector.GetDictionaryWithParametersToSearchTextFileConten("c:\\windows\\win.ini", @"MAPI.*CMC=1", 1, true, true);
            var textFileContentObjectCollector =
                new TextFileContentObjectCollector() { FileContentProvider = CreateFakeFileContentProvider(CreateFakeFileContent()) };

            var result = textFileContentObjectCollector.GetValues(fileContentSearchingParameters);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("MAPI=1\r\nCMCDLLNAME32=mapi32.dll\r\nCMC=1", result[0].Trim());
        }
        private IList <ItemType> ProcessOperationsPatterns(
            textfilecontent54_object fileContentObject, IEnumerable <string> completePaths)
        {
            var result             = new List <ItemType>();
            var pattern            = ((EntityObjectStringType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.pattern)).Value;
            var instance           = ((EntitySimpleBaseType)fileContentObject.GetItemValue(textfilecontent54_ItemsChoices.instance)).Value;
            var multilineBehavior  = fileContentObject.IsMultiline();
            var singlelineBehavior = fileContentObject.IsSingleline();

            foreach (var filepath in completePaths)
            {
                var parameters =
                    TextFileContentObjectCollector.GetDictionaryWithParametersToSearchTextFileConten(
                        filepath, pattern, Int32.Parse(instance), multilineBehavior, singlelineBehavior);

                result.Add(this.CollectItem(parameters));

                parameters.Clear();
            }

            return(result);
        }
        public void Should_be_possible_to_get_textfilecontent_entries_with_pattern_match()
        {            
            string regex = @"\s*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0\s*(#.*)?";
            var fileContentSearchingParameters =
                TextFileContentObjectCollector.GetDictionaryWithParametersToSearchTextFileConten
                ("c:\\temp\\filecontent_base.xml", regex, 1);
            var textFileContentObjectCollector =
                new TextFileContentObjectCollector() { FileContentProvider = CreateFakeFileContentProvider(GetFakeLinesInFileContent()) };

            var result = textFileContentObjectCollector.GetValues(fileContentSearchingParameters);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.IsTrue(result[0].Contains("net.ipv4.conf.all.accept_redirects = 0"));
        }
        public void Should_be_possible_to_get_xml_entries_with_pattern_match()
        {
            var fileContentSearchingParameters =
                  TextFileContentObjectCollector.GetDictionaryWithParametersToSearchTextFileConten("c:\\windows\\win.ini", @"<book>.*?</book>", 1, true, true);
            var textFileContentObjectCollector =
                new TextFileContentObjectCollector() { FileContentProvider = CreateFakeFileContentProvider(GetFakeLines()) };

            var result = textFileContentObjectCollector.GetValues(fileContentSearchingParameters);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.IsTrue(result[0].Contains("<title>The Lord of the Rings</title>"));
        }
        public void Should_be_possible_to_get_the_second_instance_of_pattern_match()
        {
            var fileContentSearchingParameters =
                TextFileContentObjectCollector.GetDictionaryWithParametersToSearchTextFileConten("c:\\windows\\win.ini", @"<title>.*?</title>", 2);
            var textFileContentObjectCollector =
                new TextFileContentObjectCollector() { FileContentProvider = CreateFakeFileContentProvider(GetFakeLines()) };

            var result = textFileContentObjectCollector.GetValues(fileContentSearchingParameters);

            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(@"<title>Bible</title>", result[0].Trim());
        }
        private TextFileContentEntityOperationEvaluator CreateMockForSimpleFileContent(
            IEnumerable<string> fileNames, IEnumerable<string> paths)
        {
            MockRepository mocks = new MockRepository();
            var fakeFileContentProvider = mocks.DynamicMock<IFileProvider>();
            var fakePathOperator = mocks.DynamicMock<PathOperatorEvaluator>();

            Expect.Call(fakeFileContentProvider.GetFileLinesContentFromHost("")).IgnoreArguments().Repeat.Any()
                .Return(this.CreateFakeFileLines());
            Expect.Call(fakePathOperator.ProcessOperationFileName(null, null, true)).IgnoreArguments()
                .Return(fileNames);
            Expect.Call(fakePathOperator.ProcessOperationsPaths(null)).IgnoreArguments()
                .Return(paths);

            mocks.ReplayAll();

            var objectCollector = new TextFileContentObjectCollector()
            {
                TargetInfo = ProbeHelper.CreateFakeTarget(),
                FileContentProvider = fakeFileContentProvider
            };

            var operationEvaluator = new TextFileContentEntityOperationEvaluator(objectCollector, null, FamilyEnumeration.windows);
            operationEvaluator.PathOperatorEvaluator = fakePathOperator;

            return operationEvaluator;
        }