예제 #1
0
        public void CreateScriptsCommand() {
            // Arrange
            const int commandId = 3;
            const bool includeSource = true;

            // Act
            var scriptsCommand = new ScriptsCommand(commandId, includeSource);

            // Assert
            Assert.AreEqual(commandId, scriptsCommand.Id);
            Assert.AreEqual(
                string.Format(
                    "{{\"command\":\"scripts\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"includeSource\":{1}}}}}",
                    commandId, includeSource.ToString().ToLower()),
                scriptsCommand.ToString());
        }
예제 #2
0
        public void CreateScriptsCommandWithOptionalParameters() {
            // Arrange
            const int commandId = 3;
            const int moduleId = 5;
            const bool includeSource = false;

            // Act
            var scriptsCommand = new ScriptsCommand(commandId, includeSource, moduleId);

            // Assert
            Assert.AreEqual(commandId, scriptsCommand.Id);
            Assert.AreEqual(
                string.Format(
                    "{{\"command\":\"scripts\",\"seq\":{0},\"type\":\"request\",\"arguments\":{{\"includeSource\":{1},\"ids\":[{2}]}}}}",
                    commandId, includeSource.ToString().ToLower(CultureInfo.InvariantCulture), moduleId),
                scriptsCommand.ToString());
        }
예제 #3
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);
        }
 private async Task GetScriptsAsync(CancellationToken cancellationToken = new CancellationToken()) {
     var scriptsCommand = new ScriptsCommand(CommandId);
     if (await TrySendRequestAsync(scriptsCommand, cancellationToken).ConfigureAwait(false)) {
         AddModules(scriptsCommand.Modules);
     }
 }
        internal async Task<string> GetScriptTextAsync(int moduleId, CancellationToken cancellationToken = new CancellationToken()) {
            DebugWriteCommand("GetScriptText: " + moduleId);

            var scriptsCommand = new ScriptsCommand(CommandId, true, moduleId);
            if (!await TrySendRequestAsync(scriptsCommand, cancellationToken).ConfigureAwait(false) ||
                scriptsCommand.Modules.Count == 0) {
                return null;
            }

            return scriptsCommand.Modules[0].Source;
        }