예제 #1
0
        public void ExecuteAsync_KnownEndpointWithRequestMethods_NoWarning()
        {
            ChangeDirectoryCommand command = new ChangeDirectoryCommand();

            Setup(commandText: "cd AnEndpoint", out MockedShellState mockedShellState, out HttpState httpState, out ICoreParseResult parseResult);

            DirectoryStructure directoryStructure = new DirectoryStructure(null);
            DirectoryStructure childDirectory     = directoryStructure.DeclareDirectory("AnEndpoint");
            RequestInfo        childRequestInfo   = new RequestInfo();

            childRequestInfo.AddMethod("GET");
            childDirectory.RequestInfo = childRequestInfo;
            ApiDefinition apiDefinition = new ApiDefinition()
            {
                DirectoryStructure = directoryStructure
            };

            httpState.ApiDefinition = apiDefinition;

            string expectedOutput = "/AnEndpoint    [GET]";

            command.ExecuteAsync(mockedShellState, httpState, parseResult, CancellationToken.None);

            Assert.Single(mockedShellState.Output);
            Assert.Equal(expectedOutput, mockedShellState.Output[0]);
        }
예제 #2
0
        public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry)
        {
            entry = entry ?? throw new ArgumentNullException(nameof(entry));

            parent = parent ?? throw new ArgumentNullException(nameof(parent));

            string[] parts = entry.Path.Split('/');

            foreach (string part in parts)
            {
                if (!string.IsNullOrEmpty(part) && parent is object)
                {
                    parent = parent.DeclareDirectory(part);
                }
            }

            RequestInfo dirRequestInfo = new RequestInfo();

            foreach (KeyValuePair <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > requestInfo in entry.AvailableRequests)
            {
                string method = requestInfo.Key;

                foreach (KeyValuePair <string, IReadOnlyList <Parameter> > parameterSetsByContentType in requestInfo.Value)
                {
                    if (string.IsNullOrEmpty(parameterSetsByContentType.Key))
                    {
                        dirRequestInfo.SetFallbackRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value));
                    }

                    dirRequestInfo.SetRequestBody(method, parameterSetsByContentType.Key, SchemaDataGenerator.GetBodyString(parameterSetsByContentType.Value));
                }

                dirRequestInfo.AddMethod(method);
            }

            if (dirRequestInfo.Methods.Count > 0 && parent is object)
            {
                parent.RequestInfo = dirRequestInfo;
            }
        }
예제 #3
0
        public static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry)
        {
            entry = entry ?? throw new ArgumentNullException(nameof(entry));

            parent = parent ?? throw new ArgumentNullException(nameof(parent));

            string[] parts = entry.Path.Split('/');

            foreach (string part in parts)
            {
                if (!string.IsNullOrEmpty(part) && parent is object)
                {
                    parent = parent.DeclareDirectory(part);
                }
            }

            RequestInfo dirRequestInfo = new RequestInfo();

            foreach (RequestMetadata requestMetadata in entry.AvailableRequests)
            {
                string method = requestMetadata.Operation.ToString();

                foreach (RequestContentMetadata content in requestMetadata.Content)
                {
                    if (string.IsNullOrWhiteSpace(content.ContentType))
                    {
                        dirRequestInfo.SetFallbackRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema));
                    }

                    dirRequestInfo.SetRequestBody(method, content.ContentType, SchemaDataGenerator.GetBodyString(content.BodySchema));
                }

                dirRequestInfo.AddMethod(requestMetadata.Operation.ToString());
            }

            if (dirRequestInfo.Methods.Count > 0 && parent is object)
            {
                parent.RequestInfo = dirRequestInfo;
            }
        }
예제 #4
0
        private static void FillDirectoryInfo(DirectoryStructure parent, EndpointMetadata entry)
        {
            string[] parts = entry.Path.Split('/');

            foreach (string part in parts)
            {
                if (!string.IsNullOrEmpty(part))
                {
                    parent = parent.DeclareDirectory(part);
                }
            }

            RequestInfo dirRequestInfo = new RequestInfo();

            foreach (KeyValuePair <string, IReadOnlyDictionary <string, IReadOnlyList <Parameter> > > requestInfo in entry.AvailableRequests)
            {
                string method = requestInfo.Key;

                foreach (KeyValuePair <string, IReadOnlyList <Parameter> > parameterSetsByContentType in requestInfo.Value)
                {
                    if (string.IsNullOrEmpty(parameterSetsByContentType.Key))
                    {
                        dirRequestInfo.SetFallbackRequestBody(method, GetBodyString(null, parameterSetsByContentType.Value));
                    }

                    dirRequestInfo.SetRequestBody(method, parameterSetsByContentType.Key, GetBodyString(parameterSetsByContentType.Key, parameterSetsByContentType.Value));
                }

                dirRequestInfo.AddMethod(method);
            }

            if (dirRequestInfo.Methods.Count > 0)
            {
                parent.RequestInfo = dirRequestInfo;
            }
        }