public void CanParseValidJsonPayloadWithMultipleObjects() { var validMultipleObjectJson = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }, { ""hash"": ""97cdd4bb45c3d5d652c0079901fb4eec"", ""last_modified"": ""2014-03-05T01:10:22.786140"", ""bytes"": 2147483649, ""name"": ""LargeFile.bin"", ""content_type"": ""application/octet-stream"" } ]"; var converter = new StorageObjectPayloadConverter(); var objects = converter.Convert("TestContainer", validMultipleObjectJson).ToList(); Assert.AreEqual(2,objects.Count()); var obj1 = objects.First(o => string.Equals(o.Name, "BLAH", StringComparison.InvariantCultureIgnoreCase)); var obj2 = objects.First(o => string.Equals(o.Name, "LargeFile.bin", StringComparison.InvariantCultureIgnoreCase)); Assert.IsNotNull(obj1); Assert.IsNotNull(obj2); Assert.AreEqual(0,obj1.Length); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", obj1.ETag); Assert.AreEqual("application/octet-stream", obj1.ContentType); Assert.AreEqual(DateTime.Parse("2014-03-07T21:31:31.588170"), obj1.LastModified); Assert.AreEqual("BLAH", obj1.Name); Assert.AreEqual("TestContainer", obj1.ContainerName); Assert.AreEqual(2147483649, obj2.Length); Assert.AreEqual("97cdd4bb45c3d5d652c0079901fb4eec", obj2.ETag); Assert.AreEqual("application/octet-stream", obj2.ContentType); Assert.AreEqual(DateTime.Parse("2014-03-05T01:10:22.786140"), obj2.LastModified); Assert.AreEqual("LargeFile.bin", obj2.Name); Assert.AreEqual("TestContainer", obj2.ContainerName); }
public void CannotParseWithNullHeaders() { var containerName = "TestContainer"; var objectName = "TestObject"; var converter = new StorageObjectPayloadConverter(); converter.Convert(containerName, objectName, null); }
public void CanParseDynamicManifestFromHeadersWithMetadata() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "1234"}, {"Content-Type", "application/octet-stream"}, {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"}, {"ETag", "d41d8cd98f00b204e9800998ecf8427e"}, {"X-Object-Meta-Test1","Test1"}, {"X-Object-Manifest","a/b"} }; var converter = new StorageObjectPayloadConverter(); var obj = converter.Convert(containerName, objectName, headers); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(DynamicLargeObjectManifest)); Assert.AreEqual(1234, obj.Length); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", obj.ETag); Assert.AreEqual("application/octet-stream", obj.ContentType); Assert.AreEqual(DateTime.Parse("Wed, 12 Mar 2014 23:42:23 GMT"), obj.LastModified); Assert.AreEqual(objectName, obj.Name); Assert.AreEqual(containerName, obj.ContainerName); Assert.AreEqual(1, obj.Metadata.Count()); Assert.IsTrue(obj.Metadata.ContainsKey("Test1")); Assert.AreEqual("Test1", obj.Metadata["Test1"]); var manifest = obj as DynamicLargeObjectManifest; Assert.AreEqual("a/b", manifest.SegmentsPath); }
public void CanParseObjectFromHeadersAndSpecificObjectLength() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "1234"}, {"Content-Type", "application/octet-stream"}, {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"}, {"ETag", "d41d8cd98f00b204e9800998ecf8427e"} }; var converter = new StorageObjectPayloadConverter(); var obj = converter.Convert(containerName, objectName, headers, 100); Assert.IsNotNull(obj); Assert.IsInstanceOfType(obj, typeof(StorageObject)); Assert.AreEqual(100, obj.Length); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", obj.ETag); Assert.AreEqual("application/octet-stream", obj.ContentType); Assert.AreEqual(DateTime.Parse("Wed, 12 Mar 2014 23:42:23 GMT"), obj.LastModified); Assert.AreEqual(objectName, obj.Name); Assert.AreEqual(containerName, obj.ContainerName); }
public void CanParseAnEmptyPayload() { var payload = string.Empty; var converter = new StorageObjectPayloadConverter(); var objects = converter.Convert("TestContainer", payload).ToList(); Assert.AreEqual(0, objects.Count()); }
public void CanConvertEmptyStorageObjectsToJson() { var converter = new StorageObjectPayloadConverter(); var payload = converter.Convert(new List<StorageObject>()); var result = JArray.Parse(payload); Assert.AreEqual(0, result.Count); }
public void CanParseValidJsonPayloadWithSingleObject() { var validSingleObjectJson = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); var objects = converter.Convert("TestContainer", validSingleObjectJson).ToList(); Assert.AreEqual(1, objects.Count()); var obj1 = objects.First(o => string.Equals(o.Name, "BLAH", StringComparison.InvariantCultureIgnoreCase)); Assert.IsNotNull(obj1); Assert.AreEqual(0, obj1.Length); Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", obj1.ETag); Assert.AreEqual("application/octet-stream", obj1.ContentType); Assert.AreEqual(DateTime.Parse("2014-03-07T21:31:31.588170"), obj1.LastModified); Assert.AreEqual("BLAH", obj1.Name); Assert.AreEqual("TestContainer", obj1.ContainerName); }
public void CannotParseWithMissingContentTypeHeader() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "1234"}, {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"}, {"Etag", "d41d8cd98f00b204e9800998ecf8427e"} }; var converter = new StorageObjectPayloadConverter(); converter.Convert(containerName, objectName, headers); }
public void ParseExceptionIncludesNameWhenPossible() { string InvalidJsonWithoutHash = @"[ { ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); try { converter.Convert("TestContainer", InvalidJsonWithoutHash); Assert.Fail("Parsing did not fail as expected."); } catch (FormatException ex) { Assert.IsTrue(ex.Message.StartsWith("Storage Object 'BLAH'")); } }
public void CannotParseJsonPayloadWithMissingNameProperty() { string InvalidJsonWithoutName = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); try { converter.Convert("TestContainer", InvalidJsonWithoutName); Assert.Fail("Parsing did not fail as expected."); } catch (FormatException ex) { Assert.IsTrue(ex.Message.StartsWith("Storage Object payload could not be parsed.")); } }
public void CannotParseJsonPayloadWithMissingModifiedProperty() { string InvalidJsonWithoutLastModified = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", InvalidJsonWithoutLastModified); }
public void CannotParseJsonPayloadWithMissingHashProperty() { string InvalidJsonWithoutHash = @"[ { ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", InvalidJsonWithoutHash); }
public void CannotParseInvalidPayload() { var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", "NOT JSON"); }
public void CannotParseInvalidJsonPayload() { var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", "[ { \"SomeAtrib\" }]"); }
public void CannotParseANullPayload() { var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", null); }
public void CannotParseWithMissingETagHeader() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "1234"}, {"Content-Type", "application/octet-stream"}, {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"} }; var converter = new StorageObjectPayloadConverter(); converter.Convert(containerName, objectName, headers); }
public void CannotParseWithMissingModifiedHeader() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "1234"}, {"Content-Type", "application/octet-stream"}, {"Etag", "d41d8cd98f00b204e9800998ecf8427e"} }; var converter = new StorageObjectPayloadConverter(); converter.Convert(containerName, objectName, headers); }
public void CannotParseJsonPayloadWithMissingContentTypeProperty() { string InvalidJsonWithoutContentType = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": 0, ""name"": ""BLAH"" }]"; var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", InvalidJsonWithoutContentType); }
public void CannotParseWithBadBytesHeader() { var containerName = "TestContainer"; var objectName = "TestObject"; var headers = new HttpHeadersAbstraction() { {"Content-Length", "This is not a number"}, {"Content-Type", "application/octet-stream"}, {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"}, {"Etag", "d41d8cd98f00b204e9800998ecf8427e"} }; var converter = new StorageObjectPayloadConverter(); converter.Convert(containerName, objectName, headers); }
public void CannotParseJsonPayloadWithBadModifiedDate() { string InvalidJsonWithBadDateType = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""This is not a date"", ""bytes"": 0, ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", InvalidJsonWithBadDateType); }
public void CanConvertMultipleStorageObjectToJson() { var obj = new StorageObject("a/b/c", "TestContainer", DateTime.UtcNow, "12345", 54321, string.Empty, new Dictionary<string, string>()); var obj2 = new StorageObject("a/b/d", "TestContainer", DateTime.UtcNow, "00000", 11111, string.Empty, new Dictionary<string, string>()); var converter = new StorageObjectPayloadConverter(); var payload = converter.Convert(new List<StorageObject>() { obj, obj2 }); var result = JArray.Parse(payload); Assert.AreEqual(2, result.Count); var item = result[0]; Assert.AreEqual("TestContainer/a/b/c", item["path"]); Assert.AreEqual(54321, item["size_bytes"]); Assert.AreEqual("12345", item["etag"]); var item2 = result[1]; Assert.AreEqual("TestContainer/a/b/d", item2["path"]); Assert.AreEqual(11111, item2["size_bytes"]); Assert.AreEqual("00000", item2["etag"]); }
public void CannotParseJsonPayloadWithBadBytesValue() { string InvalidJsonWithBadBytesValue = @"[ { ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"", ""last_modified"": ""2014-03-07T21:31:31.588170"", ""bytes"": ""This is not a number"", ""name"": ""BLAH"", ""content_type"": ""application/octet-stream"" }]"; var converter = new StorageObjectPayloadConverter(); converter.Convert("TestContainer", InvalidJsonWithBadBytesValue); }
public void CannotConvertNullStorageObjectsToJson() { var converter = new StorageObjectPayloadConverter(); converter.Convert(null); }
public void CanParseValidEmptyJsonArrayPayload() { var emptyJsonArray = @"[]"; var converter = new StorageObjectPayloadConverter(); var objects = converter.Convert("TestContainer", emptyJsonArray).ToList(); Assert.AreEqual(0, objects.Count()); }