Exemplo n.º 1
0
        public async Task ExecuteAsync_WithOnlyRoot_SendsTelemetry()
        {
            string rootAddress = "https://localhost/";

            ArrangeInputs($"connect {rootAddress}",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          out IPreferences preferences,
                          fileContents: "");

            TelemetryCollector telemetry = new TelemetryCollector();

            ConnectCommand connectCommand = new ConnectCommand(preferences, telemetry);

            await connectCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(telemetry.Telemetry);
            TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0];
            Assert.Equal("connect", collectedTelemetry.EventName, ignoreCase: true);
            Assert.Equal("True", collectedTelemetry.Properties["RootSpecified"]);
            Assert.Equal("False", collectedTelemetry.Properties["BaseSpecified"]);
            Assert.Equal("False", collectedTelemetry.Properties["OpenApiSpecified"]);
            Assert.Equal("False", collectedTelemetry.Properties["OpenApiFound"]);
        }
Exemplo n.º 2
0
        public async Task ExecuteAsync_WithUnknownHeader_SendsTelemetryWithHashedHeaderName()
        {
            ArrangeInputs(parseResultSections: "set header name value",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            TelemetryCollector telemetry = new TelemetryCollector();

            SetHeaderCommand setHeaderCommand = new SetHeaderCommand(telemetry);
            await setHeaderCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(telemetry.Telemetry);
            TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0];
            Assert.Equal("SetHeader", collectedTelemetry.EventName);
            Assert.Equal(Sha256Hasher.Hash("name"), collectedTelemetry.Properties["HeaderName"]);
            Assert.Equal("False", collectedTelemetry.Properties["IsValueEmpty"]);
        }
Exemplo n.º 3
0
        public async Task ExecuteAsync_WithGetAndUnknownName_SendsTelemetryWithHashedName()
        {
            Arrange("pref set preferenceName value",
                    out HttpState httpState,
                    out MockedShellState shellState,
                    out ICoreParseResult parseResult,
                    out UserFolderPreferences preferences);

            TelemetryCollector telemetry = new TelemetryCollector();

            PrefCommand command = new PrefCommand(preferences, telemetry);

            await command.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(telemetry.Telemetry);
            TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0];
            Assert.Equal("Preference", collectedTelemetry.EventName);
            Assert.Equal("Set", collectedTelemetry.Properties["GetOrSet"]);
            Assert.Equal(Sha256Hasher.Hash("preferenceName"), collectedTelemetry.Properties["PreferenceName"]);
        }
Exemplo n.º 4
0
        public async Task ExecuteAsync_WithSet_SendsTelemetry()
        {
            Arrange($"pref set {WellKnownPreference.DefaultEditorCommand} value",
                    out HttpState httpState,
                    out MockedShellState shellState,
                    out ICoreParseResult parseResult,
                    out UserFolderPreferences preferences);

            TelemetryCollector telemetry = new TelemetryCollector();

            PrefCommand command = new PrefCommand(preferences, telemetry);

            await command.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(telemetry.Telemetry);
            TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0];
            Assert.Equal("Preference", collectedTelemetry.EventName);
            Assert.Equal("Set", collectedTelemetry.Properties["GetOrSet"]);
            Assert.Equal(WellKnownPreference.DefaultEditorCommand, collectedTelemetry.Properties["PreferenceName"]);
        }
Exemplo n.º 5
0
        public async Task ExecuteAsync_WithPathAndOptions_SendsTelemetry()
        {
            // Arrange
            string expectedPath   = "/path";
            string expectedMethod = "GET";

            ArrangeInputs(commandText: $"{expectedMethod} {expectedPath} --no-formatting --header Content-Length=20",
                          baseAddress: _baseAddress,
                          path: _path,
                          urlsWithResponse: _urlsWithResponse,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          out MockedFileSystem fileSystem,
                          out IPreferences preferences);

            TelemetryCollector telemetry  = new TelemetryCollector();
            GetCommand         getCommand = new GetCommand(fileSystem, preferences, telemetry);

            // Act
            await getCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            // Assert
            Assert.Single(telemetry.Telemetry);
            TelemetryCollector.CollectedTelemetry collectedTelemetry = telemetry.Telemetry[0];
            Assert.Equal(TelemetryEventNames.HttpCommand, collectedTelemetry.EventName, ignoreCase: true);
            Assert.Equal(expectedMethod, collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_Method]);
            Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_PathSpecified]);
            Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_NoFormattingSpecified]);
            Assert.Equal("True", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_HeaderSpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_ResponseHeadersFileSpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_StreamingSpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_NoBodySpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_RequestBodyContentSpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_RequestBodyFileSpecified]);
            Assert.Equal("False", collectedTelemetry.Properties[TelemetryPropertyNames.HttpCommand_ResponseBodyFileSpecified]);
        }