public void BindPathKeys() { Dictionary <string, string> expected = new Dictionary <string, string>() { { "one", "1" }, { "list", "List(foo,2,3)" }, { "complex", String.Format("(deeper:List(found,it,{0}))", complexEscapedStringPath) } }; IReadOnlyDictionary <string, object> pathKeys = new Dictionary <string, object>() { { "one", 1 }, { "list", new List <object>() { "foo", 2, 3 } }, { "complex", new Dictionary <string, object>() { { "deeper", new List <object>() { "found", "it", complexString } } } } }; Dictionary <string, string> actual = UrlParamUtil.EncodePathKeysForUrl(pathKeys); CollectionAssert.AreEqual(expected, actual); }
public void EncodeString() { string input = complexString; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(complexEscapedStrings[encodingContext], actual); } }
public void EncodeEmptyString() { const string expected = UrlConstants.kEmptyStrRep; const string input = ""; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeDouble() { string expected = "12.3456789"; double input = 12.3456789; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeFloat() { string expected = "1.23"; float input = 1.23F; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeBytes() { string expected = bytesEncoded; Bytes input = bytes; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeRecord() { string expected = greetingEncoded; Greeting input = greeting; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeDataList() { string expectedTemplate = "List(one,2,3,{0})"; List <object> input = new List <object>() { "one", 2, 3, complexString }; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(String.Format(expectedTemplate, complexEscapedStrings[encodingContext]), actual); } }
public void EncodeDataMap() { string expectedTemplate = "(one:foo,three:{0},two:2)"; Dictionary <string, object> input = new Dictionary <string, object>() { { "one", "foo" }, { "two", 2 }, { "three", complexString } }; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(String.Format(expectedTemplate, complexEscapedStrings[encodingContext]), actual); } }
public void EncodeBool() { string expected = "true"; bool input = true; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } expected = "false"; input = false; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(expected, actual); } }
public void EncodeComplexObject() { string expectedTemplate = string.Format("(one:foo,three:{1},two:List(one,2,{3},(bytes:{4},record:{2},zero:{0})))", UrlConstants.kEmptyStrRep, "{0}", greetingEncoded, toneEncoded, bytesEncoded); Dictionary <string, object> input = new Dictionary <string, object>() { { "one", "foo" }, { "two", new List <object>() { "one", 2, tone, new Dictionary <string, object>() { { "zero", "" }, { "record", greeting }, { "bytes", bytes } } } }, { "three", complexString } }; foreach (UrlConstants.EncodingContext encodingContext in Enum.GetValues(typeof(UrlConstants.EncodingContext))) { string actual = UrlParamUtil.EncodeDataObject(input, encodingContext); Assert.AreEqual(String.Format(expectedTemplate, complexEscapedStrings[encodingContext]), actual); } }
public void EncodeQueryParams() { string expected = String.Format("complex=(deeper:List(found,it,{0}))&list=List(foo,2,3)&one=1", complexEscapedStringQuery); Dictionary <string, object> queryParams = new Dictionary <string, object>() { { "one", 1 }, { "list", new List <object>() { "foo", 2, 3 } }, { "complex", new Dictionary <string, object>() { { "deeper", new List <object>() { "found", "it", complexString } } } } }; string actual = UrlParamUtil.EncodeQueryParams(queryParams); Assert.AreEqual(expected, actual); }