public void AppendOrUpdateQueryStringTest() { // No existing querystring var actual = Urls.AppendOrUpdateQueryString("http://www.test.com", "testKey", "testValue"); Assert.AreEqual("http://www.test.com?testKey=testValue", actual); actual = Urls.AppendOrUpdateQueryString("http://www.test.com/", "testKey", "testValue"); Assert.AreEqual("http://www.test.com/?testKey=testValue", actual); // Existing QS but differing keys actual = Urls.AppendOrUpdateQueryString("http://www.test.com?existingKey=existingValue", "testKey", "testValue"); Assert.AreEqual("http://www.test.com?existingKey=existingValue&testKey=testValue", actual); actual = Urls.AppendOrUpdateQueryString("http://www.test.com?existingKey=existingValue&existingKey1=existingValue1", "testKey", "testValue"); Assert.AreEqual("http://www.test.com?existingKey=existingValue&existingKey1=existingValue1&testKey=testValue", actual); // Existing QS with same key actual = Urls.AppendOrUpdateQueryString("http://www.test.com/?testKey=oldValue", "testKey", "testValue"); Assert.AreEqual("http://www.test.com/?testKey=testValue", actual); // Same key mixed with other keys actual = Urls.AppendOrUpdateQueryString("http://www.test.com/?existingKey=existingValue&testKey=oldValue", "testKey", "testValue"); Assert.AreEqual("http://www.test.com/?existingKey=existingValue&testKey=testValue", actual); actual = Urls.AppendOrUpdateQueryString("http://www.test.com/?testKey=oldValue&existingKey=existingValue", "testKey", "testValue"); Assert.AreEqual("http://www.test.com/?testKey=testValue&existingKey=existingValue", actual); }