Esempio n. 1
0
        public void GetHelpSummary_ReturnsDescription()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult _);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            string           result           = setBearerCommand.GetHelpSummary(shellState, httpState);

            Assert.Equal(setBearerCommand.Description, result);
        }
Esempio n. 2
0
        public void CanHandle_WithSecondParseResultSectionNotEqualToSubCommand_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "set base token",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            bool?            result           = setBearerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
Esempio n. 3
0
        public void CanHandle_WithValidInput_ReturnsTrue()
        {
            ArrangeInputs(parseResultSections: "set bearer token",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            bool?            result           = setBearerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.True(result);
        }
Esempio n. 4
0
        public void CanHandle_WithParseResultSectionsLessThanTwo_ReturnsNull()
        {
            ArrangeInputs(parseResultSections: "set",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            bool?            result           = setBearerCommand.CanHandle(shellState, httpState, parseResult);

            Assert.Null(result);
        }
Esempio n. 5
0
        public async Task ExecuteAsync_WithMoreThanThreeValidParseResultSections_SetsThirdSectionAsToken()
        {
            ArrangeInputs(parseResultSections: "set bearer aSampleJwtToken token token2 token3",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            await setBearerCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Equal("aSampleJwtToken", httpState.BearerToken);
        }
Esempio n. 6
0
        public async Task ExecuteAsync_WithExactlyTwoValidParseResultSections_DoesNotSetToken()
        {
            ArrangeInputs(parseResultSections: "set bearer",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            await setBearerCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            Assert.Null(httpState.BearerToken);
        }
Esempio n. 7
0
        public void Suggest_WithNoParseResultSections_ReturnsName()
        {
            ArrangeInputs(parseResultSections: string.Empty,
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            SetBearerCommand     setBearerCommand = new SetBearerCommand();
            IEnumerable <string> suggestions      = setBearerCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(suggestions);
            Assert.Equal("set", suggestions.First());
        }
Esempio n. 8
0
        public void Suggest_WithMoreThanOneParseResultSectionAndSelectedSectionGreaterThanZero_ReturnsName()
        {
            ArrangeInputs(parseResultSections: "set bearer",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult,
                          caretPosition: 10);

            SetBearerCommand     setBearerCommand = new SetBearerCommand();
            IEnumerable <string> suggestions      = setBearerCommand.Suggest(shellState, httpState, parseResult);

            Assert.Single(suggestions);
            Assert.Equal("bearer", suggestions.First());
        }
Esempio n. 9
0
        public void GetHelpDetails_ReturnsHelpDetails()
        {
            ArrangeInputs(parseResultSections: "set bearer",
                          out MockedShellState shellState,
                          out HttpState httpState,
                          out ICoreParseResult parseResult);

            string expected = "\u001b[1mUsage: \u001b[39mset bearer [token]"
                              + Environment.NewLine
                              + Environment.NewLine
                              + "Sets or clears the bearer authorization header. When [token] is empty the bearer authorization is cleared."
                              + Environment.NewLine;

            SetBearerCommand setBearerCommand = new SetBearerCommand();
            string           result           = setBearerCommand.GetHelpDetails(shellState, httpState, parseResult);

            Assert.Equal(expected, result);
        }