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 void CanHandle_WithFirstSectionNotEqualToName_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "section1 section2 section3",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            bool?result = setSwaggerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
        public void CanHandle_WithNoParseResultSections_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            bool?result = setSwaggerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
        public void GetHelpSummary_ReturnsDescription()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult _);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            string result = setSwaggerCommand.GetHelpSummary(shellState, httpState);

            Assert.Equal(Strings.SetSwaggerCommand_Description, result);
        }
        public void GetHelpDetails_WithFirstParseResultSectionNotEqualToName_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "section1 section2 section3",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            string result = setSwaggerCommand.GetHelpDetails(shellState, httpState, parseResult);

            Assert.Null(result);
        }
        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);
        }
        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 void CanHandle_WithValidInput_ReturnsTrue()
        {
            ArrangeInputs(parseResultSections: "set swagger https://localhost:44366/swagger/v1/swagger.json",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            bool?result = setSwaggerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.True(result.Value);
        }
Beispiel #9
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);
        }
        public void GetHelpDetails_WithValidInput_ReturnsHelpDetails()
        {
            string parseResultSections = "set swagger https://localhost:44366/swagger/v1/swagger.json";

            ArrangeInputs(parseResultSections,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            string result = setSwaggerCommand.GetHelpDetails(shellState, httpState, parseResult);

            Assert.Equal(Strings.SetSwaggerCommand_Description, result);
        }
        public void Suggest_WithNoParseResultSections_ReturnsName()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            string expected             = "set";
            IEnumerable <string> result = setSwaggerCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(result);
            Assert.Equal(expected, result.First());
        }
        public void Suggest_WithSelectedSectionAtOne_ReturnsSubCommand()
        {
            ArrangeInputs(parseResultSections: "set swagger",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          caretPosition: 10);

            SetSwaggerCommand setSwaggerCommand = new SetSwaggerCommand();

            string expected             = "swagger";
            IEnumerable <string> result = setSwaggerCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(result);
            Assert.Equal(expected, result.First());
        }