summaryrefslogtreecommitdiff
path: root/external/aspnetwebstack/test/System.Web.Http.Test/Controllers/HttpActionContextTest.cs
blob: 2fedda3f8f2251f8d40527c4731ef5b028417887 (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.

using System.Web.Http.Controllers;
using Moq;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;

namespace System.Web.Http
{
    public class HttpActionContextTest
    {
        [Fact]
        public void Default_Constructor()
        {
            HttpActionContext actionContext = new HttpActionContext();

            Assert.Null(actionContext.ControllerContext);
            Assert.Null(actionContext.ActionDescriptor);
            Assert.Null(actionContext.Response);
            Assert.Null(actionContext.Request);
            Assert.NotNull(actionContext.ActionArguments);
            Assert.NotNull(actionContext.ModelState);
        }

        [Fact]
        public void Parameter_Constructor()
        {
            HttpControllerContext controllerContext = ContextUtil.CreateControllerContext();
            HttpActionDescriptor actionDescriptor = new Mock<HttpActionDescriptor>().Object;
            HttpActionContext actionContext = new HttpActionContext(controllerContext, actionDescriptor);

            Assert.Same(controllerContext, actionContext.ControllerContext);
            Assert.Same(actionDescriptor, actionContext.ActionDescriptor);
            Assert.Same(controllerContext.Request, actionContext.Request);
            Assert.Null(actionContext.Response);
            Assert.NotNull(actionContext.ActionArguments);
            Assert.NotNull(actionContext.ModelState);
        }

        [Fact]
        public void Constructor_Throws_IfControllerContextIsNull()
        {
            Assert.ThrowsArgumentNull(
                () => new HttpActionContext(null, new Mock<HttpActionDescriptor>().Object),
                "controllerContext");
        }

        [Fact]
        public void Constructor_Throws_IfActionDescriptorIsNull()
        {
            Assert.ThrowsArgumentNull(
                () => new HttpActionContext(ContextUtil.CreateControllerContext(), null),
                "actionDescriptor");
        }

        [Fact]
        public void ControllerContext_Property()
        {
            Assert.Reflection.Property<HttpActionContext, HttpControllerContext>(
                instance: new HttpActionContext(),
                propertyGetter: ac => ac.ControllerContext,
                expectedDefaultValue: null,
                allowNull: false,
                roundTripTestValue: ContextUtil.CreateControllerContext());
        }

        [Fact]
        public void ActionDescriptor_Property()
        {
            Assert.Reflection.Property<HttpActionContext, HttpActionDescriptor>(
                instance: new HttpActionContext(),
                propertyGetter: ac => ac.ActionDescriptor,
                expectedDefaultValue: null,
                allowNull: false,
                roundTripTestValue: new Mock<HttpActionDescriptor>().Object);
        }
    }
}