public void TraversPropertyTree_when_called_goes_through_all_child_properties_and_return_value_properties()
        {
            // Arrange
            var exparessionEvaluator = CreateEvaluatorWithThreeLevelProperty();

            Mock <IPropertyVisitor> propertyVisitorMock = new Mock <IPropertyVisitor>(MockBehavior.Strict);

            propertyVisitorMock.Setup(v => v.ParentPropertyAttended(It.Is <IExpandablePropertyInfo>(e => e.FullName == "Parent" && e.Name == "Parent"))).Verifiable();
            propertyVisitorMock.Setup(v => v.ParentPropertyAttended(It.Is <IExpandablePropertyInfo>(e => e.FullName == "ExpandableProperty" && e.Name == "ExpandableProperty"))).Verifiable();
            propertyVisitorMock.Setup(v => v.ValuePropertyAttended(It.Is <IValuePropertyInfo>(e => e.FullName == "ValueProp" && e.Name == "ValueProp"))).Verifiable();
            propertyVisitorMock.Setup(v => v.Dispose());

            // Act
            PropertyIterator propertIterator = new PropertyIterator(exparessionEvaluator,
                                                                    propertyVisitorMock.Object,
                                                                    new SearchStatusLister()
            {
                StatusUpdated = _ => Debug.WriteLine(_)
            });

            propertIterator.TraversPropertyTree(exparessionEvaluator.ExpressionEvaluator.EvaluateExpression("Parent"), String.Empty);

            // Assert
            propertyVisitorMock.VerifyAll();
        }
        public void Test()
        {
            var sw       = Stopwatch.StartNew();
            var propInfo = new MockDebugPropertyInfo();
            Mock <IExpressionEvaluatorProvider> evaluatorProvider = new Mock <IExpressionEvaluatorProvider>();
            Mock <IExpressionEvaluator>         evaluator         = new Mock <IExpressionEvaluator>();

            evaluator.Setup(e => e.EvaluateExpression(It.IsAny <string>())).Returns(Mock.Of <IVSDebugPropertyProxy>());

            evaluatorProvider.Setup(e => e.IsEvaluatorAvailable).Returns(true);
            evaluatorProvider.Setup(e => e.ExpressionEvaluator).Returns(evaluator.Object);

            var eventSink = new ActionBasedPropertyVisitor(e => {
                System.Diagnostics.Debug.WriteLine("ExpandableProps released:" + e.Count());
            }, v => {
                System.Diagnostics.Debug.WriteLine("ValueProps released:" + v.Count());
            });

            PropertyIterator propertyIterator = new PropertyIterator(evaluatorProvider.Object, eventSink, Moq.Mock.Of <ISearchStatus>());

            propertyIterator.TraversPropertyTree(propInfo, String.Empty);

            sw.Stop();
            var filename = "LoadTestResults.txt";

            File.AppendAllText(filename,
                               String.Format("{3}: Values:{0}, Types:{1}, Time {2} " + Environment.NewLine,
                                             propInfo.valuePropertiesCount,
                                             propInfo.expandablePropertiesCount,
                                             sw.ElapsedMilliseconds,
                                             DateTime.Now.ToString("yyyy-MM-dd hh:mm")));

            System.Diagnostics.Process.Start(filename);
        }
        public void TraversPropertyTree_when_called_stops_on_defined_depth()
        {
            // Arrange
            var exparessionEvaluator = CreateEvaluatorWithThreeLevelProperty();

            Mock <IPropertyVisitor> propertyVisitorMock = new Mock <IPropertyVisitor>(MockBehavior.Strict);

            // no other calls except top level
            propertyVisitorMock.Setup(v => v.ParentPropertyAttended(It.Is <IExpandablePropertyInfo>(e => e.Name == "Parent"))).Verifiable();
            propertyVisitorMock.Setup(v => v.Dispose());

            // Act
            PropertyIterator propertIterator = new PropertyIterator(
                exparessionEvaluator,
                propertyVisitorMock.Object,
                1,
                new SearchStatusLister()
            {
                StatusUpdated = _ => Debug.WriteLine(_)
            });

            propertIterator.TraversPropertyTree(exparessionEvaluator.ExpressionEvaluator.EvaluateExpression("Parent"), String.Empty);

            // Assert
            propertyVisitorMock.VerifyAll();
        }
        protected void traverseCollection(CollectionProperty col, TestElementTraverser traverser)
        {
            PropertyIterator iter = col.iterator();

            while (iter.hasNext())
            {
                TraverseProperty(traverser, iter.next());
            }
        }
        protected void TraverseMap(MapProperty map, TestElementTraverser traverser)
        {
            PropertyIterator iter = map.valueIterator();

            while (iter.hasNext())
            {
                TraverseProperty(traverser, iter.next());
            }
        }
        /**
         * Sets the runningVersion.
         *
         * @param runningVersion
         *            the runningVersion to set
         */
        public void SetRunningVersion(bool runningVersion)
        {
            this.runningVersion = runningVersion;
            PropertyIterator iter = propertyIterator();

            while (iter.hasNext())
            {
                iter.next().setRunningVersion(runningVersion);
            }
        }
        /**
         * Add to this the properties of element (by reference)
         * @param element {@link TestElement}
         */
        protected void mergeIn(TestElement element)
        {
            PropertyIterator iter = element.propertyIterator();

            while (iter.hasNext())
            {
                NetMeterProperty prop = iter.next();
                addProperty(prop, false);
            }
        }
        public void Traverse(TestElementTraverser traverser)
        {
            PropertyIterator iter = propertyIterator();

            traverser.startTestElement(this);
            while (iter.hasNext())
            {
                TraverseProperty(traverser, iter.next());
            }
            traverser.endTestElement(this);
        }
 /**
  * Log the properties of the test element
  *
  * @see TestElement#setProperty(JMeterProperty)
  */
 protected void logProperties()
 {
     if (log.IsDebugEnabled)
     {
         PropertyIterator iter = propertyIterator();
         while (iter.hasNext())
         {
             NetMeterProperty prop = iter.next();
             //log.debug("Property " + prop.getName() + " is temp? " + isTemporary(prop) + " and is a " + prop.getObjectValue());
         }
     }
 }
        /**
         * Add to result the values of propertyNames
         * @param result List<String> values of propertyNames
         * @param propertyNames Set<String> properties to extract
         */
        protected sealed void addPropertiesValues(List <String> result, HashSet <String> propertyNames)
        {
            PropertyIterator iterator = propertyIterator();

            while (iterator.hasNext())
            {
                NetMeterProperty jMeterProperty = iterator.next();
                if (propertyNames.Contains(jMeterProperty.getName()))
                {
                    result.Add(jMeterProperty.getStringValue());
                }
            }
        }
Example #11
0
        private LinkedList <NetMeterProperty> ReplaceValues(PropertyIterator iter, ValueTransformer transform)
        {
            LinkedList <NetMeterProperty> props = new LinkedList <NetMeterProperty>();

            while (iter.hasNext())
            {
                NetMeterProperty val = iter.next();
                if (log.IsDebugEnabled)
                {
                    log.Debug("About to replace in property of type: " + val.GetType() + ": " + val);
                }
                if (typeof(StringProperty).IsAssignableFrom(val.GetType()))
                {
                    // Must not convert TestElement.gui_class etc
                    if (!val.getName().Equals(TestElement.GUI_CLASS) &&
                        !val.getName().Equals(TestElement.TEST_CLASS))
                    {
                        val = transform.transformValue(val);
                        if (log.IsDebugEnabled)
                        {
                            log.Debug("Replacement result: " + val);
                        }
                    }
                }
                else if (typeof(MultiProperty).IsAssignableFrom(val.GetType()))
                {
                    MultiProperty multiVal = (MultiProperty)val;
                    LinkedList <NetMeterProperty> newValues = ReplaceValues(multiVal.iterator(), transform);
                    multiVal.Clear();
                    foreach (NetMeterProperty jmp in newValues)
                    {
                        multiVal.addProperty(jmp);
                    }
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Replacement result: " + multiVal);
                    }
                }
                else
                {
                    if (log.IsDebugEnabled)
                    {
                        log.Debug("Won't replace " + val);
                    }
                }
                props.AddLast(val);
            }
            return(props);
        }
 /**
  * {@inheritDoc}
  */
 public void setTemporary(NetMeterProperty property)
 {
     if (temporaryProperties == null)
     {
         temporaryProperties = new HashSet <NetMeterProperty>();
     }
     temporaryProperties.Add(property);
     if (property is MultiProperty)
     {
         PropertyIterator iter = ((MultiProperty)property).iterator();
         while (iter.hasNext())
         {
             setTemporary(iter.next());
         }
     }
 }
        public void Cancel_when_called_stops_search()
        {
            // Arrange
            var exparessionEvaluator = CreateEvaluatorWithThreeLevelProperty();

            ManualResetEvent mre = new ManualResetEvent(false);

            Mock <IPropertyVisitor> propertyVisitorMock = new Mock <IPropertyVisitor>(MockBehavior.Loose);

            propertyVisitorMock.Setup(v => v.ParentPropertyAttended(It.IsAny <IExpandablePropertyInfo>()))
            .Callback(() => mre.Set());

            propertyVisitorMock.Setup(v => v.ValuePropertyAttended(It.IsAny <IValuePropertyInfo>()))
            .Callback(() => mre.Set());
            SearchStatusLister searchStatusLister = new SearchStatusLister()
            {
                StatusUpdated = _ => Debug.WriteLine(_)
            };

            // Act
            PropertyIterator propertIterator = new PropertyIterator(
                exparessionEvaluator,
                propertyVisitorMock.Object,
                searchStatusLister);

            var task = Task.Run(() =>
            {
                propertIterator.TraversPropertyTree(exparessionEvaluator.ExpressionEvaluator.EvaluateExpression("Parent"), String.Empty);
            });

            mre.WaitOne();            // wait till search process start
            propertIterator.Cancel(); // cancel process
            mre.Set();


            // assert
            Assert.That(
                () => {
                try { Task.WaitAll(task); }
                catch (AggregateException e)
                {
                    return(e.InnerExceptions.First() is TaskCanceledException);
                }

                return(false);
            });
        }
        /**
         * {@inheritDoc}}
         */
        public List <String> getSearchableTokens()
        {
            List <String> result = new List <String>(25);

            foreach (String res in result)
            {
            }

            PropertyIterator iterator = propertyIterator();

            while (iterator.hasNext())
            {
                NetMeterProperty jMeterProperty = iterator.next();
                result.Add(jMeterProperty.getName());
                result.Add(jMeterProperty.getStringValue());
            }
            return(result);
        }
        static void Main(string[] args)
        {
            SomeDTO dto        = new SomeDTO();
            int     countFalse = 0;

            PropertyIterator.ForEach <bool>(dto, "^Arrange", (p, v, o) =>
            {
                Console.WriteLine(string.Format("{0}: {1}", p.Name, v));

                if (v == false)
                {
                    countFalse++;
                }
            });

            Console.WriteLine("Non authorized count: " + countFalse);

            Console.ReadKey();
        }
        public void TraversPropertyTree_when_called_returns_property_value()
        {
            var parentValuePropertyInfo = new Mock <IValuePropertyInfo>();

            parentValuePropertyInfo.Setup(p => p.Value).Returns("1").Verifiable();
            parentValuePropertyInfo.Setup(p => p.Name).Returns("Name");
            parentValuePropertyInfo.Setup(p => p.FullName).Returns("FullName");

            var exparessionEvaluatorProviderMock = new Mock <IExpressionEvaluatorProvider>(MockBehavior.Strict);

            exparessionEvaluatorProviderMock.Setup(e => e.IsEvaluatorAvailable).Returns(true);

            var expressionEvaluatorMock = new Mock <IExpressionEvaluator>(MockBehavior.Strict);

            var debugPropertyMock = new Mock <IVSDebugPropertyProxy>();

            debugPropertyMock.Setup(d => d.PropertyInfo).Returns(parentValuePropertyInfo.Object).Verifiable();


            exparessionEvaluatorProviderMock.Setup(e => e.ExpressionEvaluator).Returns(expressionEvaluatorMock.Object);
            expressionEvaluatorMock.Setup(e => e.EvaluateExpression("FullName")).Returns(debugPropertyMock.Object);

            List <IPropertyInfo> results          = new List <IPropertyInfo>();
            PropertyIterator     propertyIterator = new PropertyIterator(
                exparessionEvaluatorProviderMock.Object,
                new PropertyVisitorMock(
                    p => results.Add(p),
                    v => results.Add(v)),
                Moq.Mock.Of <ISearchStatus>());

            propertyIterator.TraversPropertyTree(debugPropertyMock.Object, String.Empty);

            exparessionEvaluatorProviderMock.Verify();
            expressionEvaluatorMock.VerifyAll();
            debugPropertyMock.VerifyAll();

            Assert.AreEqual(1, results.Count);
            Assert.That(results.Any(p => (p as IValuePropertyInfo) != null && (p as IValuePropertyInfo).Value == "1"));
        }
        public void Serialize(object /*T*/ @object, XmlWriter writer)
        {
            if (@object == null)
            {
                //TODO
            }
            if (!Utilities.IsAssignableFrom(@object, this._T))
            {
                throw new ArgumentException($"Can only serialize objects of type {@object.GetType().FullName} but the given object has the type {this._T.FullName}");
            }
            object objectForRealSerialization = GRYSObject.Create(@object, this.SerializationConfiguration);
            IEnumerable <(object, Type)> allReferencedObjects = new PropertyIterator().IterateOverObjectTransitively(objectForRealSerialization);
            HashSet <Type> extraTypes = new();

            foreach ((object, Type)referencedObject in allReferencedObjects)
            {
                if (referencedObject.Item1 != null && referencedObject.Item1 is IGRYSerializable extraTypesProvider)
                {
                    extraTypes.UnionWith(extraTypesProvider.GetExtraTypesWhichAreRequiredForSerialization());
                }
            }
            this.GetSerializer().Serialize(writer, objectForRealSerialization);
        }
        private void IterateThrueProperty(IExpressionEvaluatorProvider expressionEvaluatorProvider)
        {
            ErrorMessage = null;
            _visibleProperties.Clear();

            StatusBarText = "Searching...";

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            if (_property != null)
            {
                IPropertyVisitor propertyVisitor = new ActionBasedPropertyVisitor(
                    expandableProperty =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        _visibleProperties.AddRange(expandableProperty.Select(item => DebugPropertyViewModel.From(item)));
                    });
                    _logger.Info(String.Join("\n", expandableProperty));
                },
                    valueProperty =>
                {
                    Application.Current.Dispatcher.Invoke(() =>
                    {
                        _visibleProperties.AddRange(valueProperty.Select(item => DebugPropertyViewModel.From(item)));
                    });
                    _logger.Info(String.Join("\n", valueProperty));
                });

                PropertyIterator propertyIterator = new PropertyIterator(
                    expressionEvaluatorProvider,
                    propertyVisitor,
                    _searchStatus);

                _cancelSearch.Action = propertyIterator.Cancel;

                var searchTask = Task.Run(
                    () =>
                {
                    IsSearchInProgress = true;
                    propertyIterator.TraversPropertyTree(_property, _searchText);
                })
                                 .ContinueWith(t =>
                {
                    IsSearchInProgress = false;
                    stopwatch.Stop();
                    if (t.Exception != null)
                    {
                        if (t.Exception.InnerExceptions.First() is TaskCanceledException)
                        {
                            _logger.Info("Search canceled");
                            PostSearchCompleteMessage(stopwatch.Elapsed, true);
                        }
                        else     // Error
                        {
                            _logger.Error(t.Exception.ToString());
                            StatusBarText = "Error during evaluation. " + t.Exception.ToString();
                            throw t.Exception;
                        }
                    }
                    else
                    {
                        _logger.Info("Search finished");
                        PostSearchCompleteMessage(stopwatch.Elapsed, false);
                    }

                    _cancelSearch.Action = null;
                },
                                               _taskSchedulerProvider.GetCurrentScheduler());
            }
            else
            {
                _logger.Info("ExpressionEvaluator is not initialized");
                ErrorMessage = "ExpressionEvaluator is not initialized";
            }
        }
Example #19
0
 private LinkedList<NetMeterProperty> ReplaceValues(PropertyIterator iter, ValueTransformer transform)
 {
     LinkedList<NetMeterProperty> props = new LinkedList<NetMeterProperty>();
     while (iter.hasNext()) {
         NetMeterProperty val = iter.next();
         if (log.IsDebugEnabled)
         {
             log.Debug("About to replace in property of type: " + val.GetType() + ": " + val);
         }
         if (typeof(StringProperty).IsAssignableFrom(val.GetType()))
         {
             // Must not convert TestElement.gui_class etc
             if (!val.getName().Equals(TestElement.GUI_CLASS) &&
                     !val.getName().Equals(TestElement.TEST_CLASS))
             {
                 val = transform.transformValue(val);
                 if (log.IsDebugEnabled)
                 {
                     log.Debug("Replacement result: " + val);
                 }
             }
         }
         else if (typeof(MultiProperty).IsAssignableFrom(val.GetType()))
         {
             MultiProperty multiVal = (MultiProperty) val;
             LinkedList<NetMeterProperty> newValues = ReplaceValues(multiVal.iterator(), transform);
             multiVal.Clear();
             foreach (NetMeterProperty jmp in newValues)
             {
                 multiVal.addProperty(jmp);
             }
             if (log.IsDebugEnabled)
             {
                 log.Debug("Replacement result: " + multiVal);
             }
         }
         else
         {
             if (log.IsDebugEnabled)
             {
                 log.Debug("Won't replace " + val);
             }
         }
         props.AddLast(val);
     }
     return props;
 }