/// <summary>
        /// Handles lookup response message.
        /// </summary>
        /// <param name="parent">Parent variable.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of evaluation results.</returns>
        public NodeEvaluationResult[] ProcessLookup(NodeEvaluationResult parent, JsonValue message)
        {
            Utilities.ArgumentNotNull("parent", parent);
            Utilities.ArgumentNotNull("message", message);

            // Retrieve references
            JsonArray refs       = message.GetArray("refs");
            var       references = new Dictionary <int, JsonValue>(refs.Count);

            for (int i = 0; i < refs.Count; i++)
            {
                JsonValue reference = refs[i];
                var       id        = reference.GetValue <int>("handle");
                references.Add(id, reference);
            }

            // Retrieve properties
            JsonValue body       = message["body"];
            string    handle     = parent.Handle.ToString(CultureInfo.InvariantCulture);
            JsonValue objectData = body[handle];
            var       properties = new List <NodeEvaluationResult>();

            JsonArray props = objectData.GetArray("properties");

            if (props != null)
            {
                for (int i = 0; i < props.Count; i++)
                {
                    JsonValue            property         = props[i];
                    var                  variableProvider = new NodeLookupVariable(parent, property, references);
                    NodeEvaluationResult result           = _evaluationResultFactory.Create(variableProvider);
                    properties.Add(result);
                }
            }

            // Try to get prototype
            JsonValue prototype = objectData["protoObject"];

            if (prototype != null)
            {
                var variableProvider        = new NodePrototypeVariable(parent, prototype, references);
                NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider);
                properties.Add(result);
            }

            return(properties.ToArray());
        }
        public void CreateLookupVariableWithNullJsonValue() {
            // Arrange
            var parent = new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null);
            Exception exception = null;
            Dictionary<int, JToken> references = SerializationTestData.GetLookupJsonReferences();
            NodePrototypeVariable result = null;

            // Act
            try {
                result = new NodePrototypeVariable(parent, null, references);
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof (ArgumentNullException));
        }
        public void CreateLookupVariableWithNullParent() {
            // Arrange
            JObject json = SerializationTestData.GetLookupJsonPrototype();
            Dictionary<int, JToken> references = SerializationTestData.GetLookupJsonReferences();

            // Act
            var result = new NodePrototypeVariable(null, json, references);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.DontEnum, result.Attributes);
            Assert.AreEqual(NodeVariableType.Object, result.Class);
            Assert.AreEqual(4, result.Id);
            Assert.AreEqual(NodeVariableType.Prototype, result.Name);
            Assert.IsNull(result.Parent);
            Assert.IsNull(result.StackFrame);
            Assert.AreEqual("#<Object>", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("object", result.TypeName);
            Assert.IsNull(result.Value);
        }
        /// <summary>
        /// Handles lookup response message.
        /// </summary>
        /// <param name="parent">Parent variable.</param>
        /// <param name="message">Message.</param>
        /// <returns>Array of evaluation results.</returns>
        public NodeEvaluationResult[] ProcessLookup(NodeEvaluationResult parent, JsonValue message) {
            Utilities.ArgumentNotNull("parent", parent);
            Utilities.ArgumentNotNull("message", message);

            // Retrieve references
            JsonArray refs = message.GetArray("refs");
            var references = new Dictionary<int, JsonValue>(refs.Count);
            for (int i = 0; i < refs.Count; i++) {
                JsonValue reference = refs[i];
                var id = reference.GetValue<int>("handle");
                references.Add(id, reference);
            }

            // Retrieve properties
            JsonValue body = message["body"];
            string handle = parent.Handle.ToString(CultureInfo.InvariantCulture);
            JsonValue objectData = body[handle];
            var properties = new List<NodeEvaluationResult>();

            JsonArray props = objectData.GetArray("properties");
            if (props != null) {
                for (int i = 0; i < props.Count; i++) {
                    JsonValue property = props[i];
                    var variableProvider = new NodeLookupVariable(parent, property, references);
                    NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider);
                    properties.Add(result);
                }
            }

            // Try to get prototype
            JsonValue prototype = objectData["protoObject"];
            if (prototype != null) {
                var variableProvider = new NodePrototypeVariable(parent, prototype, references);
                NodeEvaluationResult result = _evaluationResultFactory.Create(variableProvider);
                properties.Add(result);
            }

            return properties.ToArray();
        }