Beispiel #1
0
        /// <summary>
        ///     Asserts that a ControllerActionExpression maps to a specified url.
        /// </summary>
        /// <param name="expectedUrl">The expected url</param>
        /// <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 <ControllerActionExpressionAssertions <TController> > MapToUrl(string expectedUrl,
                                                                                            string because = "",
                                                                                            params object[] reasonArgs)
        {
            var generatedUrl = Subject.RouteContext().GetUrl(HelperFactory.UrlHelper());

            var isMatchingUrl =
                string.Compare(generatedUrl, expectedUrl, StringComparison.InvariantCultureIgnoreCase) == 0;

            Execute.Assertion
            .BecauseOf(because, reasonArgs)
            .ForCondition(isMatchingUrl)
            .FailWith("Expected {context:outboundurl} to resolve Url to {0}{reason}, but found {1}.",
                      expectedUrl,
                      generatedUrl);

            return(new AndConstraint <ControllerActionExpressionAssertions <TController> >(this));
        }