Exemple #1
0
        public void ShouldSetUpControllerContext()
        {
            //--------------- Arrange -------------------

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.ControllerContext).Not.To.Be.Null();
        }
Exemple #2
0
        public void Build_Default_ShouldBuild()
        {
            //--------------- Arrange -------------------

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            Expect(() =>
                   ControllerWithContextBuilder <SomeController> .Create().Build()
                   )
            .Not.To.Throw();

            //--------------- Assert -----------------------
        }
Exemple #3
0
        public void Build_WhenNoControllerFactoryAndControllerHasConstructorParameters_ShouldThrow()
        {
            //--------------- Arrange -------------------

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            Expect(() => ControllerWithContextBuilder <HasConstructorArgumentsController>
                   .Create()
                   .Build()
                   ).To.Throw().With.Message.Containing("no parameterless constructor");

            //--------------- Assert -----------------------
        }
Exemple #4
0
        public void Build_GivenPrincipal_ShouldSetUpUser()
        {
            //--------------- Arrange -------------------
            var principal = Substitute.For <IPrincipal>();

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithPrincipal(principal)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.User).To.Equal(principal);
        }
Exemple #5
0
        public void Build_GivenControllerFactory_ShouldUseItToInstantiateController()
        {
            //--------------- Arrange -------------------
            var expected = new SomeController();

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithControllerFactory(() => expected)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller).To.Equal(expected);
        }
Exemple #6
0
        public void Build_GivenFormParametersCollection_ShouldSetFormParameters()
        {
            //--------------- Arrange -------------------
            var expected = new NameValueCollection();

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithFormParameters(expected)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.Request.Form == expected).To.Be.True();
        }
Exemple #7
0
        public void Build_GivenRouteData_ShouldSetRouteData()
        {
            //--------------- Arrange -------------------
            var expected = new RouteData();

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithRouteData(expected)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.RouteData).To.Equal(expected);
        }
Exemple #8
0
        public void Build_GivenFormParameter_ShouldSetFormParameter()
        {
            //--------------- Arrange -------------------
            var key   = GetRandomString(5);
            var value = GetRandomString(5);

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithFormParameter(key, value)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.Request.Form[key]).To.Equal(value);
        }
Exemple #9
0
        public void Build_GivenCookieData_ShouldSetCookie()
        {
            //--------------- Arrange -------------------
            var key   = GetRandomString(5);
            var value = GetRandomString(5);

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithCookie(key, value)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.Request.Cookies[key]?.Value).To.Equal(value);
        }
Exemple #10
0
        public void Build_GivenSessionItem_ShouldSetSessionItemValue()
        {
            //--------------- Arrange -------------------
            var key   = GetRandomString(5);
            var value = GetRandomString(5);

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithSessionItem(key, value)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.Session[key]).To.Equal(value);
        }
Exemple #11
0
        public void Build_GivenAndQueryStringParameters_ShouldSetUpQueryString()
        {
            //--------------- Arrange -------------------
            var action    = GetRandomString(5);
            var parameter = GetRandomString(5);
            var value     = GetRandomString(5);

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .ForAction(action)
                             .WithQueryStringParameter(parameter, value)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.Request.QueryString[parameter]).To.Equal(value);
        }
Exemple #12
0
        public void Build_GivenRouteValues_ShouldSetRouteDataValues()
        {
            //--------------- Arrange -------------------
            var expected = new RouteValueDictionary();
            var key      = GetRandomString(5);
            var value    = GetRandomString();

            expected[key] = value;

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .WithRouteValues(expected)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.RouteData.Values[key]).To.Equal(expected[key]);
        }
Exemple #13
0
        public void Build_GivenAction_ShouldSetUpRouteData()
        {
            //--------------- Arrange -------------------
            var action    = GetRandomString(5);
            var parameter = GetRandomString(5);
            var value     = GetRandomString(5);

            //--------------- Assume ----------------

            //--------------- Act ----------------------
            var controller = ControllerWithContextBuilder <SomeController>
                             .Create()
                             .ForAction(action)
                             .WithQueryStringParameter(parameter, value)
                             .Build();

            //--------------- Assert -----------------------
            Expect(controller.RouteData.Values["action"]).To.Equal(action);
            Expect(controller.RouteData.Values["controller"])
            .To.Equal(nameof(SomeController).Replace("Controller", ""));
        }