Beispiel #1
0
        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       = UmbracoHelper.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()));
        }
Beispiel #2
0
        public void Create_Encrypted_RouteString_From_Dictionary()
        {
            var additionalRouteValues = new Dictionary <string, object>()
            {
                { "key1", "value1" },
                { "key2", "value2" },
                { "Key3", "Value3" },
                { "keY4", "valuE4" }
            };
            var encryptedRouteString = UmbracoHelper.CreateEncryptedRouteString("FormController", "FormAction", "", additionalRouteValues);
            var result         = encryptedRouteString.DecryptWithMachineKey();
            var expectedResult = "c=FormController&a=FormAction&ar=&key1=value1&key2=value2&Key3=Value3&keY4=valuE4";

            Assert.AreEqual(expectedResult, result);
        }
Beispiel #3
0
        public void Create_Encrypted_RouteString_From_Anonymous_Object()
        {
            var additionalRouteValues = new
            {
                key1 = "value1",
                key2 = "value2",
                Key3 = "Value3",
                keY4 = "valuE4"
            };
            var encryptedRouteString = UmbracoHelper.CreateEncryptedRouteString("FormController", "FormAction", "", additionalRouteValues);
            var result         = encryptedRouteString.DecryptWithMachineKey();
            var expectedResult = "c=FormController&a=FormAction&ar=&key1=value1&key2=value2&Key3=Value3&keY4=valuE4";

            Assert.AreEqual(expectedResult, result);
        }