コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
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);
        }
コード例 #4
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);
        }