Пример #1
0
        public void GetHelpSummary_ReturnsDescription()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult _);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            string         result         = setBaseCommand.GetHelpSummary(shellState, httpState);

            Assert.Equal(setBaseCommand.Description, result);
        }
Пример #2
0
        public void CanHandle_WithSecondParseResultSectionNotEqualToSubCommand_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "set header name",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            bool?          result         = setBaseCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
Пример #3
0
        public void CanHandle_WithValidInput_ReturnsTrue()
        {
            ArrangeInputs(parseResultSections: "set base \"https://localhost:44366/\"",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            bool?          result         = setBaseCommand.CanHandle(shellState, httpState, parseResult);

            Assert.True(result);
        }
Пример #4
0
        public async Task ExecuteAsync_WithInvalidUri_WritesErrorToConsole()
        {
            ArrangeInputs(parseResultSections: "set base invalidUri",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            await setBaseCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            VerifyErrorMessageWasWrittenToConsoleManagerError(shellState);
        }
Пример #5
0
        public void CanHandle_WithParseResultSectionsLessThanTwo_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "set",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            bool?          result         = setBaseCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
Пример #6
0
        public async Task ExecuteAsync_WithExactlyTwoParseResultSections_SetsBaseAddressAndSwaggerStructureToNull()
        {
            ArrangeInputs(parseResultSections: "set base",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            await setBaseCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Null(httpState.BaseAddress);
            Assert.Null(httpState.Structure);
        }
Пример #7
0
        public void GetHelpDetails_ReturnsHelpDetails()
        {
            ArrangeInputs(parseResultSections: "set base",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            string expected = "\u001b[1mUsage: \u001b[39mset base [uri]" + Environment.NewLine + Environment.NewLine + "Set the base URI. e.g. `set base http://locahost:5000`" + Environment.NewLine;

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            string         result         = setBaseCommand.GetHelpDetails(shellState, httpState, parseResult);

            Assert.Equal(expected, result);
        }
Пример #8
0
        public void Suggest_WithNoParseResultSections_ReturnsName()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            string expected = "set";

            SetBaseCommand       setBaseCommand = new SetBaseCommand();
            IEnumerable <string> result         = setBaseCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(result);
            Assert.Equal(expected, result.First());
        }
Пример #9
0
        public async Task ExecuteAsync_WithValidInput_CreatesDirectoryStructureForSwaggerEndpoint()
        {
            string response = @"{
  ""swagger"": ""2.0"",
  ""paths"": {
    ""/api"": {
      ""get"": {
        ""tags"": [ ""Employees"" ],
        ""operationId"": ""GetEmployee"",
        ""consumes"": [],
        ""produces"": [ ""text/plain"", ""application/json"", ""text/json"" ],
        ""parameters"": [],
        ""responses"": {
          ""200"": {
            ""description"": ""Success"",
            ""schema"": {
              ""uniqueItems"": false,
              ""type"": ""array""
            }
          }
        }
      }
    }
  }
}";

            ArrangeInputs(parseResultSections: "set base \"https://localhost:44366/\"",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          responseContent: response,
                          baseAddress: "https://localhost:44366/swagger.json");

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            await setBaseCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            IDirectoryStructure directoryStructure = httpState.Structure;

            List <string> directoryNames        = directoryStructure.DirectoryNames.ToList();
            string        expectedDirectoryName = "api";

            Assert.Single(directoryNames);
            Assert.Equal(expectedDirectoryName, directoryNames.First());

            IDirectoryStructure childDirectoryStructure = directoryStructure.GetChildDirectory(expectedDirectoryName);

            Assert.Empty(childDirectoryStructure.DirectoryNames);
        }
Пример #10
0
        public void Suggest_WithNameParseResultSectionAndSelectedSectionAtOne_ReturnsSubCommand()
        {
            ArrangeInputs(parseResultSections: "set ",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          caretPosition: 4);

            string expected = "base";

            SetBaseCommand       setBaseCommand = new SetBaseCommand();
            IEnumerable <string> result         = setBaseCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(result);
            Assert.Equal(expected, result.First());
        }
Пример #11
0
        public async Task ExecuteAsync_IfCancellationIsRequested_SetsSwaggerStructureToNull()
        {
            string response = @"{
  ""swagger"": ""2.0"",
  ""paths"": {
    ""/api"": {
      ""get"": {
        ""tags"": [ ""Employees"" ],
        ""operationId"": ""GetEmployee"",
        ""consumes"": [],
        ""produces"": [ ""text/plain"", ""application/json"", ""text/json"" ],
        ""parameters"": [],
        ""responses"": {
          ""200"": {
            ""description"": ""Success"",
            ""schema"": {
              ""uniqueItems"": false,
              ""type"": ""array""
            }
          }
        }
      }
    }
  }
}";

            ArrangeInputs(parseResultSections: "set base \"https://localhost:44366/\"",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          responseContent: response,
                          baseAddress: "https://localhost:44366/");

            CancellationTokenSource cts = new CancellationTokenSource();

            cts.Cancel();

            httpState.BaseAddress = new Uri("https://localhost:44366/");

            SetBaseCommand setBaseCommand = new SetBaseCommand();
            await setBaseCommand.ExecuteAsync(shellState, httpState, parseResult, cts.Token);

            Assert.Null(httpState.Structure);
        }