Welcome to mirror list, hosted at ThFree Co, Russian Federation.

HttpMethodslTests.cs « test « Http.Abstractions « Http « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 10c8e32a996c7e58ee081e4675a8694dd9ce51e4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Text;
using Xunit;

namespace Microsoft.AspNetCore.Http.Abstractions
{
    public class HttpMethodslTests
    {
        [Fact]
        public void CanonicalizedValue_Success()
        {
            var testCases = new List<(string[] methods, string expectedMethod)>
            {
                (new string[] { "GET", "Get", "get" }, HttpMethods.Get),
                (new string[] { "POST", "Post", "post" }, HttpMethods.Post),
                (new string[] { "PUT", "Put", "put" }, HttpMethods.Put),
                (new string[] { "DELETE", "Delete", "delete" }, HttpMethods.Delete),
                (new string[] { "HEAD", "Head", "head" }, HttpMethods.Head),
                (new string[] { "CONNECT", "Connect", "connect" }, HttpMethods.Connect),
                (new string[] { "OPTIONS", "Options", "options" }, HttpMethods.Options),
                (new string[] { "PATCH", "Patch", "patch" }, HttpMethods.Patch),
                (new string[] { "TRACE", "Trace", "trace" }, HttpMethods.Trace)
            };

            for (int i = 0; i < testCases.Count; i++)
            {
                var testCase = testCases[i];
                for (int j = 0; j < testCase.methods.Length; j++)
                {
                    CanonicalizedValueTest(testCase.methods[j], testCase.expectedMethod);
                }
            }
        }


        private void CanonicalizedValueTest(string method, string expectedMethod)
        {
            string inputMethod = CreateStringAtRuntime(method);
            var canonicalizedValue = HttpMethods.GetCanonicalizedValue(inputMethod);

            Assert.Same(expectedMethod, canonicalizedValue);
        }

        private string CreateStringAtRuntime(string input)
        {
            return new StringBuilder(input).ToString();
        }
    }
}