public void Validate_Route_String()
        {
            var attribute = new ValidateUmbracoFormRouteStringAttribute();

            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(null, null, null, null));

            const string ControllerName   = "Test";
            const string ControllerAction = "Index";
            const string Area             = "MyArea";
            var          validUfprt       = UrlHelperRenderExtensions.CreateEncryptedRouteString(ControllerName, ControllerAction, Area);

            var invalidUfprt = validUfprt + "z";

            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(invalidUfprt, null, null, null));

            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, ControllerName, ControllerAction, "doesntMatch"));
            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, ControllerName, ControllerAction, null));
            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, ControllerName, "doesntMatch", Area));
            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, ControllerName, null, Area));
            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, "doesntMatch", ControllerAction, Area));
            Assert.Throws <HttpUmbracoFormRouteStringException>(() => attribute.ValidateRouteString(validUfprt, null, ControllerAction, Area));

            Assert.DoesNotThrow(() => attribute.ValidateRouteString(validUfprt, ControllerName, ControllerAction, Area));
            Assert.DoesNotThrow(() => attribute.ValidateRouteString(validUfprt, ControllerName.ToLowerInvariant(), ControllerAction.ToLowerInvariant(), Area.ToLowerInvariant()));
        }
コード例 #2
0
        public static void Create_Encrypted_RouteString_From_Dictionary()
        {
            var additionalRouteValues = new Dictionary <string, object>()
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "Key3", "Value3" },
                { "keY4", "valuE4" }
            };

            var encryptedRouteString = UrlHelperRenderExtensions.CreateEncryptedRouteString(
                "FormController",
                "FormAction",
                "",
                additionalRouteValues
                );

            var result = encryptedRouteString.DecryptWithMachineKey();

            const string expectedResult = "c=FormController&a=FormAction&ar=&key1=value1&key2=value2&Key3=Value3&keY4=valuE4";

            Assert.AreEqual(expectedResult, result);
        }
コード例 #3
0
        public static void Create_Encrypted_RouteString_From_Anonymous_Object()
        {
            var additionalRouteValues = new
            {
                key1 = "value1",
                key2 = "value2",
                Key3 = "Value3",
                keY4 = "valuE4"
            };

            var encryptedRouteString = UrlHelperRenderExtensions.CreateEncryptedRouteString(
                "FormController",
                "FormAction",
                "",
                additionalRouteValues
                );

            var result = encryptedRouteString.DecryptWithMachineKey();

            const string expectedResult = "c=FormController&a=FormAction&ar=&key1=value1&key2=value2&Key3=Value3&keY4=valuE4";

            Assert.AreEqual(expectedResult, result);
        }