public async Task ExecuteAsync_WithBaseAddress_DoesNotSetHttpStateBaseAddress()
        {
            string response = @"{
  ""swagger"": ""2.0"",
  ""host"": ""localhost"",
  ""schemes"": [
    ""https""
  ],
  ""basePath"": ""/api/v2"",
  ""paths"": {
    ""/pets"": {
    }
  }
}";

            ArrangeInputs(commandText: "set swagger http://localhost/swagger.json",
                          baseAddress: "http://localhost/",
                          path: "/",
                          urlsWithResponse: new Dictionary <string, string> {
                { "http://localhost/swagger.json", response }
            },
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          out _,
                          out _);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

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

            Assert.NotEqual("https://localhost/api/v2/", httpState.BaseAddress.ToString(), StringComparer.Ordinal);
        }
        public async Task ExecuteAsync_WithExactlyTwoParseResultSections_SetsHttpStateSwaggerStructureToNull()
        {
            ArrangeInputs(parseResultSections: "section1 sections2",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

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

            Assert.Null(httpState.Structure);
        }
        public async Task ExecuteAsync_WhenThirdSectionIsNotAValidUri_WritesToConsoleManagerError()
        {
            ArrangeInputs(parseResultSections: "section1 sections2 section3",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

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

            VerifyErrorMessageWasWrittenToConsoleManagerError(shellState);
        }
Пример #4
0
        private async Task <IDirectoryStructure> GetDirectoryStructure(string response, string parseResultSections, string baseAddress)
        {
            MockedShellState             shellState       = new MockedShellState();
            IDictionary <string, string> urlsWithResponse = new Dictionary <string, string>();

            urlsWithResponse.Add(baseAddress, response);
            HttpState         httpState         = GetHttpState(out _, out _, urlsWithResponse: urlsWithResponse);
            ICoreParseResult  parseResult       = CoreParseResultHelper.Create(parseResultSections);
            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

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

            return(httpState.Structure);
        }