コード例 #1
0
        public static IRouteContext RouteContext <TController>(this Expression <Func <TController, ActionResult> > action)
            where TController : Controller
        {
            var controllerName = RouteDataFactory.ControllerName <TController>();
            var actionName     = action.ActionName();

            var routeValues = new RouteValueDictionary();

            action.GetMethodArgumentValues()
            .ForEach(arg =>
                     routeValues.Add(arg.Key.Name, arg.Value)
                     );

            return(new DerivedRouteContext(controllerName, actionName, routeValues));
        }
コード例 #2
0
        /// <summary>
        ///     Asserts that a <see cref="RedirectToRouteResult">redirectResult</see> redirects to a specified
        ///     <typeparamref name="TController">controller</typeparamref>.
        /// </summary>
        /// <typeparam name="TController">The type of controller.</typeparam>
        /// <param name="because">
        ///     A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
        ///     is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="reasonArgs">
        ///     Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public AndConstraint <RedirectToRouteResultAssertions> RedirectToController <TController>(string because = "",
                                                                                                  params object[]
                                                                                                  reasonArgs)
            where TController : IController
        {
            const string key = "Controller";
            var          expectedController = RouteDataFactory.ControllerName <TController>();

            if (ReferenceEquals(Subject, null))
            {
                Execute.Assertion
                .BecauseOf(because, reasonArgs)
                .FailWith(
                    "Expected {context:redirecttorouteresult} to redirect to controller {0}{reason}, but {context:redirecttorouteresult} was <null>.",
                    expectedController);
            }


            Execute.Assertion
            .BecauseOf(because, reasonArgs)
            .ForCondition(Subject.RouteValues.ContainsKey(key))
            .FailWith(
                "Expected {context:redirecttorouteresult} to to have route parameter {0}{reason}, but parameter {0} was not found.",
                key
                );

            var actualController = Subject.RouteValues.ContainsKey(key) &&
                                   !string.IsNullOrEmpty(Subject.RouteValues[key].IfExists(val => val.ToString()))
                ? Subject.RouteValues[key].IfExists(val => val.ToString())
                : null;

            Execute.Assertion
            .BecauseOf(because, reasonArgs)
            .ForCondition(
                string.Compare(expectedController,
                               actualController,
                               StringComparison.InvariantCultureIgnoreCase) ==
                0)
            .FailWith(
                "Expected {context:redirecttorouteresult} to redirect to controller {0}{reason}, but was {1}.",
                expectedController,
                actualController
                );

            return(new AndConstraint <RedirectToRouteResultAssertions>(this));
        }
コード例 #3
0
        /// <summary>
        ///     Asserts that a <see cref="RouteValueDictionary">routeValueDictionary</see> maps to a specified
        ///     <typeparamref name="TController">controller</typeparamref>.
        /// </summary>
        /// <typeparam name="TController">The type of Controller.</typeparam>
        /// <param name="because">
        ///     A formatted phrase as is supported by <see cref="string.Format(string,object[])" /> explaining why the assertion
        ///     is needed. If the phrase does not start with the word <i>because</i>, it is prepended automatically.
        /// </param>
        /// <param name="reasonArgs">
        ///     Zero or more objects to format using the placeholders in <see cref="because" />.
        /// </param>
        public AndConstraint <RouteValueDictionaryAssertions> MapTo <TController>(string because = "",
                                                                                  params object[] reasonArgs)
            where TController : IController
        {
            if (ReferenceEquals(Subject, null))
            {
                Execute.Assertion
                .BecauseOf(because, reasonArgs)
                .FailWith("Expected {context:routevalues} to not be <null>{reason}.");
            }

            var expectedController = RouteDataFactory.ControllerName <TController>();

            Subject.Should().MapToController(expectedController, because, reasonArgs);

            return(new AndConstraint <RouteValueDictionaryAssertions>(this));
        }
コード例 #4
0
 public void EntregaEfectivo_EditEntregaEfectivoTest()
 {
     using (PexDisposableContext disposables = PexDisposableContext.Create())
     {
         RouteData routeData;
         SolicitudEfectivoController solicitudEfectivoController;
         ActionResult actionResult;
         routeData = RouteDataFactory.Create((RouteBase)null, (IRouteHandler)null);
         ControllerContext s0 = new ControllerContext();
         s0.Controller               = (ControllerBase)null;
         s0.HttpContext              = (HttpContextBase)null;
         s0.RequestContext           = (RequestContext)null;
         s0.RouteData                = routeData;
         solicitudEfectivoController = SolicitudEfectivoControllerFactory.Create
                                           ((IDependencyResolver)null, (IActionInvoker)null,
                                           (ITempDataProvider)null, (UrlHelper)null, (ViewEngineCollection)null,
                                           s0, (TempDataDictionary)null,
                                           false, (IValueProvider)null, (ViewDataDictionary)null);
         disposables.Add((IDisposable)solicitudEfectivoController);
         actionResult =
             this.EditEntregaEfectivoTest(solicitudEfectivoController, default(int?));
         disposables.Dispose();
         Assert.IsNotNull((object)actionResult);
         Assert.IsNotNull((object)solicitudEfectivoController);
         Assert.IsNotNull(((Controller)solicitudEfectivoController).AsyncManager);
         Assert.IsNotNull(((Controller)solicitudEfectivoController).AsyncManager
                          .OutstandingOperations);
         Assert.IsNotNull
             (((Controller)solicitudEfectivoController).AsyncManager.Parameters);
         Assert.AreEqual <int>
             (45000, ((Controller)solicitudEfectivoController).AsyncManager.Timeout);
         Assert.IsNull(((Controller)solicitudEfectivoController).Url);
         Assert.IsNotNull
             (((ControllerBase)solicitudEfectivoController).ControllerContext);
         Assert.IsNull(
             ((ControllerBase)solicitudEfectivoController).ControllerContext.Controller
             );
         Assert.AreEqual <bool>
             (false, ((ControllerBase)solicitudEfectivoController).ValidateRequest);
     }
 }