コード例 #1
0
        public void ProcessBacktraceForStackFrames()
        {
            // Arrange
            const int commandId         = 3;
            const int fromFrame         = 0;
            const int toFrame           = 7;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var     backtraceCommand = new BacktraceCommand(commandId, resultFactoryMock.Object, fromFrame, toFrame);
            JObject backtraceMessage = SerializationTestData.GetBacktraceResponse();

            // Act
            backtraceCommand.ProcessResponse(backtraceMessage);

            // Assert
            Assert.AreEqual(7, backtraceCommand.StackFrames.Count);
            NodeStackFrame firstFrame = backtraceCommand.StackFrames[0];

            Assert.AreEqual(NodeVariableType.AnonymousFunction, firstFrame.FunctionName);
            Assert.AreEqual(@"C:\Users\Tester\documents\visual studio 2012\Projects\NodejsApp1\NodejsApp1\server.js", firstFrame.FileName);
            Assert.AreEqual(22, firstFrame.Line);
            Assert.AreEqual(0, firstFrame.Column);
            Assert.AreEqual(15, firstFrame.Locals.Count);
            Assert.AreEqual(5, firstFrame.Parameters.Count);
            Assert.IsNotNull(backtraceCommand.Modules);
            Assert.AreEqual(3, backtraceCommand.Modules.Count);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Exactly(51));
        }
コード例 #2
0
        public void ProcessEvaluateResponseWithReferenceError()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()));
            const string expression      = "hello";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);
            Exception    exception       = null;

            // Act
            try
            {
                evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponseWithReferenceError());
            }
            catch (Exception e)
            {
                exception = e;
            }

            // Assert
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(DebuggerCommandException));
            Assert.AreEqual("ReferenceError: hello is not defined", exception.Message);
            Assert.IsNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Never);
        }
コード例 #3
0
        public void ProcessSetBreakpointResponse()
        {
            // Arrange
            const int    commandId            = 3;
            const int    moduleId             = 33;
            const int    line                 = 2;
            const int    column               = 0;
            const string fileName             = "module.js";
            var          module               = new NodeModule(moduleId, fileName);
            var          breakOn              = new BreakOn(BreakOnKind.Equal, 2);
            var          position             = new FilePosition(fileName, line, column);
            var          breakpoint           = new NodeBreakpoint(null, position, true, breakOn, null);
            var          setBreakpointCommand = new SetBreakpointCommand(commandId, module, breakpoint, false, false);
            JObject      breakpointResponse   = SerializationTestData.GetSetBreakpointResponse();

            // Act
            setBreakpointCommand.ProcessResponse(breakpointResponse);

            // Assert
            Assert.AreEqual(2, setBreakpointCommand.BreakpointId);
            Assert.AreEqual(0, setBreakpointCommand.Column);
            Assert.AreEqual(0, setBreakpointCommand.Line);
            Assert.AreEqual(false, setBreakpointCommand.Running);
            Assert.AreEqual(33, setBreakpointCommand.ScriptId);
        }
コード例 #4
0
        public void ProcessChangeLiveResponse()
        {
            // Arrange
            const int    commandId         = 3;
            const int    moduleId          = 5;
            const string fileName          = "fileName.js";
            var          module            = new NodeModule(moduleId, fileName);
            var          changeLiveCommand = new ChangeLiveCommand(commandId, module);

            // Act
            changeLiveCommand.ProcessResponse(SerializationTestData.GetChangeLiveResponse());

            // Assert
            Assert.AreEqual(commandId, changeLiveCommand.Id);
            Assert.IsTrue(changeLiveCommand.Updated);
            Assert.IsTrue(changeLiveCommand.StackModified);
        }
コード例 #5
0
        public void CanDeserializeClass()
        {
            var    nativeDeserializer       = new NativeDeserializerTestsBase(MI_SerializationFormat.MOF);
            var    originalClass            = SerializationTestData.GetSerializableTestClass();
            var    serializedRepresentation = nativeDeserializer.GetSerializedClass();
            string originalClassName;
            var    res = originalClass.GetClassName(out originalClassName);

            MIAssert.Succeeded(res);

            uint offset = 0;
            IEnumerable <CimClass> outClasses = this.deserializer.DeserializeClasses(serializedRepresentation, ref offset, new CimClass[0], null, null, null, null);

            Assert.NotNull(outClasses, "Expect the result object to be non-null");
            List <CimClass> classList = outClasses.ToList();

            Assert.Equal(1, classList.Count, "Expect only one class since that's all we serialized");
            Assert.Equal(originalClassName, classList[0].CimSystemProperties.ClassName, "Expect class name to survive unscathed at least");
        }
コード例 #6
0
        public void CreateBacktraceVariableWithNullStackFrame()
        {
            // Arrange
            JObject               json      = SerializationTestData.GetBacktraceJsonObject();
            Exception             exception = null;
            NodeBacktraceVariable result    = null;

            // Act
            try {
                result = new NodeBacktraceVariable(null, json);
            } catch (Exception e) {
                exception = e;
            }

            // Assert
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(ArgumentNullException));
        }
コード例 #7
0
        public void ProcessEvaluateResponse()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            const string expression      = "expression";
            var          stackFrame      = new NodeStackFrame(0);
            var          evaluateCommand = new EvaluateCommand(commandId, resultFactoryMock.Object, expression, stackFrame);

            // Act
            evaluateCommand.ProcessResponse(SerializationTestData.GetEvaluateResponse());

            // Assert
            Assert.AreEqual(commandId, evaluateCommand.Id);
            Assert.IsNotNull(evaluateCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
コード例 #8
0
        public void CreateLookupVariableWithNullJsonReferences()
        {
            // Arrange
            var                   parent    = new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null);
            JObject               json      = SerializationTestData.GetLookupJsonPrototype();
            Exception             exception = null;
            NodePrototypeVariable result    = null;

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

            // Assert
            Assert.IsNull(result);
            Assert.IsNotNull(exception);
            Assert.IsInstanceOfType(exception, typeof(ArgumentNullException));
        }
コード例 #9
0
        public void ProcessSetVariableValueResponse()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var          stackFrame              = new NodeStackFrame(0);
            const string variableName            = "port";
            const int    handle                  = 40;
            var          setVariableValueCommand = new SetVariableValueCommand(commandId, resultFactoryMock.Object, stackFrame, variableName, handle);

            // Act
            setVariableValueCommand.ProcessResponse(SerializationTestData.GetSetVariableValueResponse());

            // Assert
            Assert.AreEqual(commandId, setVariableValueCommand.Id);
            Assert.IsNotNull(setVariableValueCommand.Result);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
コード例 #10
0
        public void CreateBacktraceVariableWithNullName()
        {
            // Arrange
            JObject json       = SerializationTestData.GetBacktraceJsonObjectWithNullName();
            var     stackFrame = new NodeStackFrame(0);

            // Act
            var result = new NodeBacktraceVariable(stackFrame, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(21, result.Id);
            Assert.AreEqual(NodeVariableType.AnonymousVariable, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.IsNull(result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("boolean", result.TypeName);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        public void CreateLookupVariableWithNullParent()
        {
            // Arrange
            JObject json = SerializationTestData.GetLookupJsonProperty();
            Dictionary <int, JToken> references = SerializationTestData.GetLookupJsonReferences();

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

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(54, result.Id);
            Assert.AreEqual("first", result.Name);
            Assert.IsNull(result.Parent);
            Assert.IsNull(result.StackFrame);
            Assert.AreEqual("1", result.Text);
            Assert.AreEqual(NodePropertyType.Field, result.Type);
            Assert.AreEqual("number", result.TypeName);
            Assert.AreEqual("1", result.Value);
        }
コード例 #13
0
        public void ProcessLookupResponseWithPrimitiveObject()
        {
            // Arrange
            const int commandId         = 3;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            const int handle        = 9;
            var       handles       = new[] { handle };
            var       lookupCommand = new LookupCommand(commandId, resultFactoryMock.Object, handles);

            // Act
            lookupCommand.ProcessResponse(SerializationTestData.GetLookupResponseWithPrimitiveObject());

            // Assert
            Assert.AreEqual(commandId, lookupCommand.Id);
            Assert.IsNotNull(lookupCommand.Results);
            Assert.IsTrue(lookupCommand.Results.ContainsKey(handle));
            Assert.IsNotNull(lookupCommand.Results[handle]);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Once);
        }
コード例 #14
0
        public void ProcessScriptsResponse()
        {
            // Arrange
            const int    commandId      = 3;
            const bool   includeSource  = true;
            const string nodejs         = "node.js";
            var          scriptsCommand = new ScriptsCommand(commandId, includeSource);

            // Act
            scriptsCommand.ProcessResponse(SerializationTestData.GetScriptsResponse());

            // Assert
            Assert.AreEqual(commandId, scriptsCommand.Id);
            Assert.IsNotNull(scriptsCommand.Modules);
            Assert.AreEqual(17, scriptsCommand.Modules.Count);
            NodeModule module = scriptsCommand.Modules[0];

            Assert.AreEqual(nodejs, module.Name);
            Assert.AreEqual(nodejs, module.Source);
            Assert.AreEqual(nodejs, module.FileName);
            Assert.AreEqual(nodejs, module.JavaScriptFileName);
            Assert.AreEqual(17, module.Id);
        }
コード例 #15
0
        public void CreateEvaluationVariable()
        {
            // Arrange
            JObject      json       = SerializationTestData.GetEvaluationJsonObject();
            var          stackFrame = new NodeStackFrame(0);
            const string name       = "name";

            // Act
            var result = new NodeEvaluationVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(16, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("<tag>Value</tag>", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("string", result.TypeName);
            Assert.AreEqual("<tag>Value</tag>", result.Value);
        }
コード例 #16
0
        public void ProcessBacktraceForCallstackDepth()
        {
            // Arrange
            const int commandId         = 3;
            const int fromFrame         = 0;
            const int toFrame           = 7;
            var       resultFactoryMock = new Mock <IEvaluationResultFactory>();

            resultFactoryMock.Setup(factory => factory.Create(It.IsAny <INodeVariable>()))
            .Returns(() => new NodeEvaluationResult(0, null, null, null, null, null, NodeExpressionType.None, null));
            var     backtraceCommand = new BacktraceCommand(commandId, resultFactoryMock.Object, fromFrame, toFrame, true);
            JObject backtraceMessage = SerializationTestData.GetBacktraceResponse();

            // Act
            backtraceCommand.ProcessResponse(backtraceMessage);

            // Assert
            Assert.AreEqual(7, backtraceCommand.CallstackDepth);
            Assert.IsNotNull(backtraceCommand.Modules);
            Assert.AreEqual(0, backtraceCommand.Modules.Count);
            Assert.IsNotNull(backtraceCommand.StackFrames);
            Assert.AreEqual(0, backtraceCommand.StackFrames.Count);
            resultFactoryMock.Verify(factory => factory.Create(It.IsAny <INodeVariable>()), Times.Never);
        }
コード例 #17
0
        public void CreateSetVariableValue()
        {
            // Arrange
            JObject      json       = SerializationTestData.GetSetVariableValueResponse();
            const int    frameId    = 3;
            var          stackFrame = new NodeStackFrame(frameId);
            const string name       = "name";

            // Act
            var result = new NodeSetValueVariable(stackFrame, name, json);

            // Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(NodePropertyAttributes.None, result.Attributes);
            Assert.IsNull(result.Class);
            Assert.AreEqual(44, result.Id);
            Assert.AreEqual(name, result.Name);
            Assert.IsNull(result.Parent);
            Assert.AreEqual(stackFrame, result.StackFrame);
            Assert.AreEqual("55", result.Text);
            Assert.AreEqual(NodePropertyType.Normal, result.Type);
            Assert.AreEqual("number", result.TypeName);
            Assert.AreEqual("55", result.Value);
        }