Ejemplo n.º 1
0
        public void GetApplicableContentTypes_NoMethod_ReturnsAll()
        {
            DirectoryStructure directoryStructure = new DirectoryStructure(null);
            RequestInfo        requestInfo        = new RequestInfo();

            requestInfo.SetRequestBody("GET", "application/json", "");
            requestInfo.SetRequestBody("PUT", "application/xml", "");
            directoryStructure.RequestInfo = requestInfo;

            HttpState httpState = SetupHttpState();

            httpState.BaseAddress = new Uri("https://localhost/");
            ApiDefinition apiDefinition = new ApiDefinition();

            apiDefinition.DirectoryStructure = directoryStructure;
            httpState.ApiDefinition          = apiDefinition;

            IEnumerable <string> result = httpState.GetApplicableContentTypes(null, "");

            Assert.NotNull(result);

            Assert.Equal(2, result.Count());
            Assert.Contains("application/json", result, StringComparer.OrdinalIgnoreCase);
            Assert.Contains("application/xml", result, StringComparer.OrdinalIgnoreCase);
        }
Ejemplo n.º 2
0
        public void GetApplicableContentTypes_WithPath_ReturnsCorrectOne()
        {
            DirectoryStructure parentDirectoryStructure = new DirectoryStructure(null);
            RequestInfo        parentRequestInfo        = new RequestInfo();

            parentRequestInfo.SetRequestBody("GET", "application/json", "");
            parentDirectoryStructure.RequestInfo = parentRequestInfo;
            DirectoryStructure childDirectoryStructure = parentDirectoryStructure.DeclareDirectory("child");
            RequestInfo        childRequestInfo        = new RequestInfo();

            childRequestInfo.SetRequestBody("GET", "application/xml", "");
            childDirectoryStructure.RequestInfo = childRequestInfo;

            HttpState httpState = SetupHttpState();

            httpState.BaseAddress = new Uri("https://localhost/");
            ApiDefinition apiDefinition = new ApiDefinition();

            apiDefinition.DirectoryStructure = parentDirectoryStructure;
            httpState.ApiDefinition          = apiDefinition;

            IEnumerable <string> result = httpState.GetApplicableContentTypes("GET", "child");

            Assert.Single(result);
            Assert.Contains("application/xml", result, StringComparer.OrdinalIgnoreCase);
        }
Ejemplo n.º 3
0
        public void GetApplicableContentTypes_NoBaseAddress_ReturnsNull()
        {
            HttpState httpState = SetupHttpState();

            httpState.BaseAddress = null;

            IEnumerable <string> result = httpState.GetApplicableContentTypes(null, string.Empty);

            Assert.Null(result);
        }
Ejemplo n.º 4
0
        public void GetApplicableContentTypes_NoStructure_ReturnsNull()
        {
            HttpState httpState = SetupHttpState();

            httpState.BaseAddress = new Uri("https://localhost/");
            httpState.Structure   = null;

            IEnumerable <string> result = httpState.GetApplicableContentTypes(null, string.Empty);

            Assert.Null(result);
        }
Ejemplo n.º 5
0
        public static IEnumerable <string> GetValueCompletions(string method, string path, string header, string prefix, HttpState programState)
        {
            switch (header.ToUpperInvariant())
            {
            case "CONTENT-TYPE":
                IEnumerable <string> results = programState.GetApplicableContentTypes(method, path);

                return(results?.Where(x => !string.IsNullOrEmpty(x) && x.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)));

            default:
                return(null);
            }
        }
Ejemplo n.º 6
0
        public void GetApplicableContentTypes_GetMethod_ReturnsCorrectOne()
        {
            DirectoryStructure directoryStructure = new DirectoryStructure(null);
            RequestInfo        requestInfo        = new RequestInfo();

            requestInfo.SetRequestBody("GET", "application/json", "");
            requestInfo.SetRequestBody("PUT", "application/xml", "");
            directoryStructure.RequestInfo = requestInfo;

            HttpState httpState = SetupHttpState();

            httpState.BaseAddress = new Uri("https://localhost/");
            httpState.Structure   = directoryStructure;

            IEnumerable <string> result = httpState.GetApplicableContentTypes("GET", "");

            Assert.Single(result);
            Assert.Contains("application/json", result, StringComparer.OrdinalIgnoreCase);
        }