public void AttemptToDecode_InvalidShortCode()
        {
            List <string> inputList = new List <string>()
            {
                "ag4j!",
                "asd-b",
                "zzzA",
                "hhh}j",
                "aBc3ff",
                "`fbse",
                "?hopd",
                "'gwno",
                "$bdf",
                "bs+4d",
                "-bar",
                "foo|",
            };

            inputList.Add("000!");
            inputList.Add("zzzA");
            inputList.Add("hhh}");
            inputList.Add("abc/");

            foreach (var input in inputList)
            {
                int testOutput = UrlMinimizer.Decode(input);

                Assert.AreEqual(-1, testOutput);
                Console.WriteLine(string.Format("Successfully processed string: {0} - Returned: {1}", input, testOutput.ToString()));
            }
        }
Ejemplo n.º 2
0
        public EncodeResponse Post(EncodeRequest request)
        {
            EncodeResponse response = new EncodeResponse();

            try
            {
                DataAccess.InsertUrl(request.Url);
                int returnCode = DataAccess.GetMostRecentRecordId();

                response.Code   = UrlMinimizer.Encode(returnCode);
                response.Status = "Success";
            }
            catch (Exception e)
            {
                if (e.Message.Contains("expects the parameter '@Url'"))
                {
                    response.Status = "The Parameters did not include a value for Url";
                }
                else
                {
                    response.Status = e.Message;
                }
            }

            return(response);
        }
        public void AttemptToDecode_ShortCodeStringTooLong()
        {
            string testInput = "0000000";

            int testOutput = UrlMinimizer.Decode(testInput);

            Assert.AreEqual(-1, testOutput);
        }
        public void AttemptToDecode_AboveValidShortCodeValues()
        {
            string testInput = "zzzzzz";

            int testOutput = UrlMinimizer.Decode(testInput);

            Assert.AreEqual(-1, testOutput);
        }
        public void AttemptToEncode_AboveValidIndexValues()
        {
            int testInput = 2147392739;

            string testOutput = UrlMinimizer.Encode(testInput);

            Assert.AreEqual("Invalid", testOutput);
        }
        public void AttemptToEncode_BelowValidIndexValues()
        {
            int testInput = 0;

            string testOutput = UrlMinimizer.Encode(testInput);

            Assert.AreEqual("Invalid", testOutput);
        }
        public void Decode_HighestestValidShortCodeValue()
        {
            string testInput = "zik0zj";

            int testOutput = UrlMinimizer.Decode(testInput);

            Assert.AreEqual(2147392738, testOutput);
        }
        public void Decode_LowestValidShortCodeValue()
        {
            string testInput = "1y5a";

            int testOutput = UrlMinimizer.Decode(testInput);

            Assert.AreEqual(1, testOutput);
        }
        public void Encode_LowestValidIndexValue()
        {
            int testInput = 1;

            string testOutput = UrlMinimizer.Encode(testInput);

            Assert.AreEqual("1y5a", testOutput);
        }
        public void Encode_HighestValidIndexValue()
        {
            //Assuming Offset is set to 90909
            int testInput = 2147392738; //limited to 2147483647 - UrlMinimizer.Offset because of index limitation

            string testOutput = UrlMinimizer.Encode(testInput);


            Assert.AreEqual("zik0zj", testOutput);
        }