summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres G. Aragoneses <knocte@gmail.com>2013-02-15 22:46:48 +0000
committerAndres G. Aragoneses <knocte@gmail.com>2013-02-15 22:46:48 +0000
commit0035c5e1647c04f19e1c709a9ea8e53a3ad3f40b (patch)
tree1e382ee8bb91fe3abd5e4b6c32845bbd7b73cfe9 /src
parentc53d258466ccaf82b70ba28c68528a8f01497188 (diff)
Lastfm: refactor LastfmRequest tests to not rely on params order
http://xyz/?foo=bar&bar=baz should be equal to http://xyz/?bar=baz&foo=bar No change of behaviour in this commit.
Diffstat (limited to 'src')
-rw-r--r--src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs b/src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs
index 51f4fd0fe..b65d54f0c 100644
--- a/src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs
+++ b/src/Libraries/Lastfm/Lastfm/Tests/LastfmRequestTests.cs
@@ -30,6 +30,7 @@
using System;
using System.Net;
+using System.Collections.Generic;
using NUnit.Framework;
namespace Lastfm.Tests
@@ -54,7 +55,7 @@ namespace Lastfm.Tests
var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&format=json";
var creator = new FakeWebRequestCreator ();
new LastfmRequest ("someMethod", RequestType.Read, ResponseFormat.Json, creator).Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
}
[Test]
@@ -66,7 +67,7 @@ namespace Lastfm.Tests
req.AddParameter ("x", "y");
req.AddParameter ("a", "b");
req.Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
}
[Test]
@@ -75,7 +76,7 @@ namespace Lastfm.Tests
var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&raw=true";
var creator = new FakeWebRequestCreator ();
new LastfmRequest ("someMethod", RequestType.Read, ResponseFormat.Raw, creator).Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
}
[Test]
@@ -84,7 +85,7 @@ namespace Lastfm.Tests
var expected = "http://ws.audioscrobbler.com/2.0/?method=someMethod&api_key=344e9141fffeb02201e1ae455d92ae9f&format=json&sk=&api_sig=33ca04b6d45c54eb1405b3d7cb7735ea";
var creator = new FakeWebRequestCreator ();
new LastfmRequest ("someMethod", RequestType.Write, ResponseFormat.Json, creator).Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
}
[Test]
@@ -96,7 +97,7 @@ namespace Lastfm.Tests
req.AddParameter ("x", "y");
req.AddParameter ("a", "b");
req.Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
}
[Test]
@@ -108,10 +109,39 @@ namespace Lastfm.Tests
req.AddParameter ("x", "y");
req.AddParameter ("a", "b");
req.Send ();
- Assert.AreEqual (expected, creator.Uri.ToString ());
+ UrisAreEquivalent (expected, creator.Uri.ToString ());
+ }
+
+ public void UrisAreEquivalent (string expected, string actual)
+ {
+ if (String.IsNullOrEmpty (expected)) {
+ throw new ArgumentNullException ("expected");
+ }
+
+ if (String.IsNullOrEmpty (actual)) {
+ throw new ArgumentNullException ("actual");
+ }
+
+ if (!expected.Contains ("?") || !actual.Contains ("?")) {
+ throw new ArgumentException ("uris must contain parameters, so a ? char to beging the querystring should be present");
+ }
+
+ string expected_without_querystring = expected.Substring (0, expected.IndexOf ("?"));
+ string actual_without_querystring = actual.Substring (0, actual.IndexOf ("?"));
+
+ Assert.AreEqual (expected_without_querystring, actual_without_querystring);
+
+ var expected_parameters = expected.Substring (expected.IndexOf ("?")).Split (new [] {'&'});
+ var actual_parameters = new List<string> (actual.Substring (actual.IndexOf ("?")).Split (new [] {'&'}));
+
+ Assert.AreEqual (expected_parameters.Length, actual_parameters.Count);
+ foreach (var expected_param in expected_parameters) {
+ Assert.IsTrue (actual_parameters.Contains (expected_param),
+ String.Format ("URI {0} is missing parameter '{1}'", actual, expected_param));
+ }
}
}
}
-#endif \ No newline at end of file
+#endif