diff options
* Added some more tests to the GetAssetStreamHandlers
Diffstat (limited to 'OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs')
-rw-r--r-- | OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs b/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs new file mode 100644 index 0000000..593beae --- /dev/null +++ b/OpenSim/Tests/Common/Setup/GetAssetStreamHandlerTestHelpers.cs | |||
@@ -0,0 +1,64 @@ | |||
1 | using System; | ||
2 | using System.Collections.Generic; | ||
3 | using System.IO; | ||
4 | using System.Net; | ||
5 | using System.Text; | ||
6 | using System.Xml; | ||
7 | using System.Xml.Serialization; | ||
8 | using NUnit.Framework; | ||
9 | using OpenSim.Framework; | ||
10 | using OpenSim.Framework.Servers; | ||
11 | using OpenSim.Framework.Servers.HttpServer; | ||
12 | using OpenSim.Tests.Common.Mock; | ||
13 | |||
14 | namespace OpenSim.Tests.Common.Setup | ||
15 | { | ||
16 | public class GetAssetStreamHandlerTestHelpers | ||
17 | { | ||
18 | public static void BaseFetchExistingAssetXmlTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response) | ||
19 | { | ||
20 | byte[] expected = BaseGetAssetStreamHandler.GetXml(asset); | ||
21 | |||
22 | byte[] actual = handler.Handle("/assets/" + asset.ID , null, null, response); | ||
23 | |||
24 | Assert.Greater(actual.Length, 10, "Too short xml on fetching xml without trailing slash."); | ||
25 | Assert.AreEqual(expected, actual, "Failed on fetching xml without trailing slash."); | ||
26 | // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch."); | ||
27 | |||
28 | byte[] actual1 = handler.Handle("/assets/" + asset.ID + "/", null, null, response); | ||
29 | Assert.Greater(actual1.Length, 10, "Too short xml on fetching xml with trailing slash."); | ||
30 | Assert.AreEqual(expected, actual1, "Failed on fetching xml with trailing slash."); | ||
31 | // Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch."); | ||
32 | } | ||
33 | |||
34 | public static void BaseFetchExistingAssetDataTest(AssetBase asset, BaseGetAssetStreamHandler handler, OSHttpResponse response) | ||
35 | { | ||
36 | Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data", null, null, response), "Failed on fetching data without trailing slash."); | ||
37 | Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on first fetch."); | ||
38 | |||
39 | Assert.AreEqual(asset.Data, handler.Handle("/assets/" + asset.ID + "/data/", null, null, response), "Failed on fetching data with trailing slash."); | ||
40 | Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode, "Wrong http response code on second fetch."); | ||
41 | } | ||
42 | |||
43 | public static AssetBase CreateCommonTestResources(out OSHttpResponse response) | ||
44 | { | ||
45 | AssetBase asset = CreateTestAsset(); | ||
46 | response = new TestOSHttpResponse(); | ||
47 | return asset; | ||
48 | } | ||
49 | |||
50 | public static AssetBase CreateTestAsset() | ||
51 | { | ||
52 | byte[] expected = new byte[] { 1,2,3 }; | ||
53 | AssetBase asset = new AssetBase( ); | ||
54 | asset.ID = Guid.NewGuid().ToString(); | ||
55 | asset.Data = expected; | ||
56 | return asset; | ||
57 | } | ||
58 | |||
59 | public static void BaseFetchMissingAsset(BaseGetAssetStreamHandler handler) | ||
60 | { | ||
61 | Assert.AreEqual(BaseRequestHandlerTestHelper.EmptyByteArray, handler.Handle("/assets/" + Guid.NewGuid(), null, null, null), "Failed on bad guid."); | ||
62 | } | ||
63 | } | ||
64 | } | ||