Пример #1
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);
        }
Пример #2
0
        public void CreateChangeLiveCommand() {
            // Arrange
            const int commandId = 3;
            const int moduleId = 5;
            const string fileName = "fileName.js";
            const string source = "source";
            string wrappedSource = string.Format("{0}{1}{2}", NodeConstants.ScriptWrapBegin, source, NodeConstants.ScriptWrapEnd.Replace("\n", @"\n"));
            var module = new NodeModule(moduleId, fileName) { Source = source };

            // Act
            var changeLiveCommand = new ChangeLiveCommand(commandId, module);

            // Assert
            Assert.AreEqual(commandId, changeLiveCommand.Id);
            Assert.AreEqual(
                string.Format(
                    "{{\"command\":\"changelive\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"script_id\":{1},\"new_source\":\"{2}\",\"preview_only\":false}}}}",
                    commandId, moduleId, wrappedSource),
                changeLiveCommand.ToString());
        }
        /// <summary>
        /// Updates a module content while debugging.
        /// </summary>
        /// <param name="module">Node module.</param>
        /// <returns>Operation result.</returns>
        internal async Task<bool> UpdateModuleSourceAsync(NodeModule module) {
            module.Source = File.ReadAllText(module.JavaScriptFileName);

            var changeLiveCommand = new ChangeLiveCommand(CommandId, module);

            // Check whether update was successfull
            if (!await TrySendRequestAsync(changeLiveCommand).ConfigureAwait(false) ||
                !changeLiveCommand.Updated) {
                return false;
            }

            // Make step into and update stacktrace if required
            if (changeLiveCommand.StackModified) {
                var continueCommand = new ContinueCommand(CommandId, SteppingKind.Into);
                await TrySendRequestAsync(continueCommand).ConfigureAwait(false);
                await CompleteSteppingAsync(false).ConfigureAwait(false);
            }

            return true;
        }