Пример #1
0
        protected void ArrangeInputs(string commandText,
                                     string baseAddress,
                                     string path,
                                     IDictionary <string, string> urlsWithResponse,
                                     out MockedShellState shellState,
                                     out HttpState httpState,
                                     out ICoreParseResult parseResult,
                                     out MockedFileSystem fileSystem,
                                     out IPreferences preferences,
                                     string header         = "",
                                     bool readBodyFromFile = false,
                                     string fileContents   = "",
                                     string contentType    = "")
        {
            parseResult = CoreParseResultHelper.Create(commandText);
            shellState  = new MockedShellState();

            httpState = GetHttpState(out fileSystem,
                                     out preferences,
                                     baseAddress,
                                     header,
                                     path,
                                     urlsWithResponse,
                                     readBodyFromFile,
                                     fileContents,
                                     contentType);
        }
Пример #2
0
        public async Task ExecuteAsync_SetCommandNoValue_SetToDefault()
        {
            IFileSystem fileSystem = new MockedFileSystem();
            IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider();
            UserFolderPreferences         preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, TestDefaultPreferences.GetDefaultPreferences());
            HttpClient       httpClient = new HttpClient();
            HttpState        httpState  = new HttpState(fileSystem, preferences, httpClient);
            MockedShellState shellState = new MockedShellState();
            PrefCommand      command    = new PrefCommand(preferences);

            // First, set it to something other than the default and make sure that works.
            string           firstCommandExpectedValue = "BoldMagenta";
            string           firstCommandText          = $"pref set {WellKnownPreference.ProtocolColor} {firstCommandExpectedValue}";
            ICoreParseResult firstParseResult          = CoreParseResultHelper.Create(firstCommandText);

            await command.ExecuteAsync(shellState, httpState, firstParseResult, CancellationToken.None);

            Assert.Empty(shellState.Output);
            Assert.Equal(firstCommandExpectedValue, preferences.CurrentPreferences[WellKnownPreference.ProtocolColor]);

            // Then, set it to nothing and make sure it goes back to the default
            string           secondCommandText = $"pref set {WellKnownPreference.ProtocolColor}";
            ICoreParseResult secondParseResult = CoreParseResultHelper.Create(secondCommandText);

            await command.ExecuteAsync(shellState, httpState, secondParseResult, CancellationToken.None);

            Assert.Empty(shellState.Output);
            Assert.Equal(preferences.DefaultPreferences[WellKnownPreference.ProtocolColor], preferences.CurrentPreferences[WellKnownPreference.ProtocolColor]);
        }
Пример #3
0
        private void Setup(string commandText, out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult)
        {
            mockedShellState = new MockedShellState();
            IFileSystem fileSystem = new RealFileSystem();
            IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider();
            IPreferences preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, null);

            parseResult = CoreParseResultHelper.Create(commandText);
            HttpClient httpClient = new HttpClient();

            httpState = new HttpState(preferences, httpClient);
        }
Пример #4
0
        private static void Arrange(string commandText, out HttpState httpState, out MockedShellState shellState, out ICoreParseResult parseResult, out PrefCommand command, out UserFolderPreferences preferences)
        {
            IFileSystem fileSystem = new MockedFileSystem();
            IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider();

            preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, TestDefaultPreferences.GetDefaultPreferences());
            HttpClient httpClient = new HttpClient();

            httpState   = new HttpState(fileSystem, preferences, httpClient);
            shellState  = new MockedShellState();
            parseResult = CoreParseResultHelper.Create(commandText);
            command     = new PrefCommand(preferences);
        }
Пример #5
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);
        }
Пример #6
0
        public async Task ExecuteAsync_WithHttpStateBaseAddressSetToNull_WritesToConsoleManagerError()
        {
            MockedShellState shellState  = new MockedShellState();
            ICoreParseResult parseResult = CoreParseResultHelper.Create("ui");
            HttpState        httpState   = GetHttpState(out _, out _);

            httpState.BaseAddress = null;

            Mock <IUriLauncher> mockLauncher = new Mock <IUriLauncher>();
            UICommand           uiCommand    = new UICommand(mockLauncher.Object);

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

            VerifyErrorMessageWasWrittenToConsoleManagerError(shellState);
        }
Пример #7
0
        protected static void ArrangeInputs(string parseResultSections,
                                            out MockedShellState shellState,
                                            out HttpState httpState,
                                            out ICoreParseResult parseResult,
                                            string baseAddress     = "",
                                            int caretPosition      = -1,
                                            string responseContent = "")
        {
            parseResult = CoreParseResultHelper.Create(parseResultSections, caretPosition);
            shellState  = new MockedShellState();
            IDictionary <string, string> urlsWithResponse = new Dictionary <string, string>();

            urlsWithResponse.Add(baseAddress, responseContent);

            httpState = GetHttpState(out _, out _, urlsWithResponse: urlsWithResponse);
        }
Пример #8
0
        public async Task ExecuteAsync_WithNoParameterAndAbsolutePreference_VerifyLaunchUriAsyncWasCalledOnce()
        {
            string                commandText = "ui";
            ICoreParseResult      parseResult = CoreParseResultHelper.Create(commandText);
            MockedShellState      shellState  = new MockedShellState();
            MockedFileSystem      fileSystem  = new MockedFileSystem();
            UserFolderPreferences preferences = new UserFolderPreferences(fileSystem, new UserProfileDirectoryProvider(), null);

            preferences.SetValue(WellKnownPreference.SwaggerUIEndpoint, "https://localhost:12345/mySwaggerPath");
            HttpState httpState = new HttpState(fileSystem, preferences, new HttpClient());

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

            Mock <IUriLauncher> mockLauncher = new Mock <IUriLauncher>();
            UICommand           uiCommand    = new UICommand(mockLauncher.Object, preferences);

            mockLauncher.Setup(s => s.LaunchUriAsync(It.IsAny <Uri>()))
            .Returns(Task.CompletedTask);

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

            mockLauncher.Verify(l => l.LaunchUriAsync(It.Is <Uri>(u => u.AbsoluteUri == "https://localhost:12345/mySwaggerPath")), Times.Once());
        }
Пример #9
0
        public async Task ExecuteAsync_WithEditorDoesNotExist_VerifyResponse()
        {
            // Arrange
            string editorPath  = "FileThatDoesNotExist.exe";
            string commandText = "POST https://localhost/";

            MockedShellState shellState = new MockedShellState();
            IFileSystem      fileSystem = new MockedFileSystem();
            IUserProfileDirectoryProvider userProfileDirectoryProvider = new UserProfileDirectoryProvider();
            IPreferences     preferences = new UserFolderPreferences(fileSystem, userProfileDirectoryProvider, null);
            ICoreParseResult parseResult = CoreParseResultHelper.Create(commandText);
            HttpClient       httpClient  = new HttpClient();
            HttpState        httpState   = new HttpState(fileSystem, preferences, httpClient);
            PostCommand      postCommand = new PostCommand(fileSystem, preferences);

            preferences.SetValue(WellKnownPreference.DefaultEditorCommand, editorPath);

            // Act
            await postCommand.ExecuteAsync(shellState, httpState, parseResult, CancellationToken.None);

            // Execute
            Assert.Empty(shellState.Output);
            Assert.Contains(string.Format(Strings.BaseHttpCommand_Error_DefaultEditorDoesNotExist, editorPath), shellState.ErrorMessage);
        }
Пример #10
0
 protected ICoreParseResult CreateCoreParseResult(string commandText)
 {
     return(CoreParseResultHelper.Create(commandText));
 }