public void Execute_BlockListWithAllHeaders_AllHeadersSetProperly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary<string, string>(){ {"ETag", "\"123\""}, {"Date", DateTime.UtcNow.ToString() }, {"Last-Modified", DateTime.UtcNow.ToString() }, {"Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var expectedData = new BlockListBlockIdList(); var expectedContentMD5 = expectedData.AsXmlByteArrayWithMd5Hash().MD5Hash; var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, expectedData, "cache/control", "content/type", "content/encoding", "content/language", "blobContent/md5"); request.Execute(); Assert.AreEqual(expectedContentMD5, expectedRawRequest.Headers["Content-MD5"]); Assert.AreEqual("cache/control", expectedRawRequest.Headers["x-ms-blob-cache-control"]); Assert.AreEqual("content/type", expectedRawRequest.Headers["x-ms-blob-content-type"]); Assert.AreEqual("content/encoding", expectedRawRequest.Headers["x-ms-blob-content-encoding"]); Assert.AreEqual("content/language", expectedRawRequest.Headers["x-ms-blob-content-language"]); Assert.AreEqual("blobContent/md5", expectedRawRequest.Headers["x-ms-blob-content-md5"]); }
public void Execute_BlockListWithContent_ContentSetProperly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary<string, string>(){ {"ETag", "\"123\""}, {"Date", DateTime.UtcNow.ToString() }, {"Last-Modified", DateTime.UtcNow.ToString() }, {"Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var id1 = Base64Converter.ConvertToBase64("id1"); var id2 = Base64Converter.ConvertToBase64("id2"); var id3 = Base64Converter.ConvertToBase64("id3"); var expectedData = string.Format( @"<?xml version=""1.0"" encoding=""utf-8""?><BlockList><Committed>{0}</Committed><Uncommitted>{1}</Uncommitted><Latest>{2}</Latest></BlockList>", id1, id2, id3); var givenData = new BlockListBlockIdList { new BlockListBlockId { Id = id1, ListType = PutBlockListListType.Committed}, new BlockListBlockId { Id = id2, ListType = PutBlockListListType.Uncommitted}, new BlockListBlockId { Id = id3, ListType = PutBlockListListType.Latest} }; var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, givenData); request.Execute(); Assert.AreEqual(expectedData, Encoding.UTF8.GetString(givenData.AsXMLByteArray())); }
public void Execute_BlockListWithAllHeaders_AllHeadersSetProperly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary <string, string>() { { "ETag", "\"123\"" }, { "Date", DateTime.UtcNow.ToString() }, { "Last-Modified", DateTime.UtcNow.ToString() }, { "Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var expectedData = new BlockListBlockIdList(); var expectedContentMD5 = expectedData.AsXmlByteArrayWithMd5Hash().MD5Hash; var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, expectedData, "cache/control", "content/type", "content/encoding", "content/language", "blobContent/md5"); request.Execute(); Assert.AreEqual(expectedContentMD5, expectedRawRequest.Headers["Content-MD5"]); Assert.AreEqual("cache/control", expectedRawRequest.Headers["x-ms-blob-cache-control"]); Assert.AreEqual("content/type", expectedRawRequest.Headers["x-ms-blob-content-type"]); Assert.AreEqual("content/encoding", expectedRawRequest.Headers["x-ms-blob-content-encoding"]); Assert.AreEqual("content/language", expectedRawRequest.Headers["x-ms-blob-content-language"]); Assert.AreEqual("blobContent/md5", expectedRawRequest.Headers["x-ms-blob-content-md5"]); }
public void Execute_BlockList_ResponseParsesHeadersCorrectly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedDate = DateTime.UtcNow.AddDays(-2345); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary <string, string>() { { "ETag", "\"123\"" }, { "Date", expectedDate.ToString() }, { "Last-Modified", expectedDate.ToString() }, { "Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var expectedData = new BlockListBlockIdList(); var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, expectedData); var response = request.Execute(); Assert.AreEqual("123", response.Payload.ETag); Assert.IsTrue(Math.Abs(expectedDate.Subtract(response.Payload.Date).TotalMinutes) < 1); Assert.IsTrue(Math.Abs(expectedDate.Subtract(response.Payload.LastModified).TotalMinutes) < 1); Assert.AreEqual("123-MD5", response.Payload.ContentMD5); }
protected BlockListBlockIdList CreateBlockIdList(int idCount, PutBlockListListType listType) { var idList = new BlockListBlockIdList(); for (var i = 0; i < idCount; i++) { idList.Add(new BlockListBlockId { Id = Base64Converter.ConvertToBase64(Guid.NewGuid().ToString()), ListType = listType }); } return(idList); }
public void Execute_BlockListWithContent_ContentSetProperly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary <string, string>() { { "ETag", "\"123\"" }, { "Date", DateTime.UtcNow.ToString() }, { "Last-Modified", DateTime.UtcNow.ToString() }, { "Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var id1 = Base64Converter.ConvertToBase64("id1"); var id2 = Base64Converter.ConvertToBase64("id2"); var id3 = Base64Converter.ConvertToBase64("id3"); var expectedData = string.Format( @"<?xml version=""1.0"" encoding=""utf-8""?><BlockList><Committed>{0}</Committed><Uncommitted>{1}</Uncommitted><Latest>{2}</Latest></BlockList>", id1, id2, id3); var givenData = new BlockListBlockIdList { new BlockListBlockId { Id = id1, ListType = PutBlockListListType.Committed }, new BlockListBlockId { Id = id2, ListType = PutBlockListListType.Uncommitted }, new BlockListBlockId { Id = id3, ListType = PutBlockListListType.Latest } }; var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, givenData); request.Execute(); Assert.AreEqual(expectedData, Encoding.UTF8.GetString(givenData.AsXMLByteArray())); }
/// <summary> /// BlockBlob Type /// </summary> public PutBlockListRequest(StorageAccountSettings settings, string containerName, string blobName, BlockListBlockIdList data, string cacheControl = null, string contentType = null, string contentEncoding = null, string contentLanguage = null, string blobContentMD5 = null, Dictionary <string, string> metadata = null, string leaseId = null) : base(settings) { if (!string.IsNullOrEmpty(leaseId)) { Guard.ArgumentIsAGuid("leaseId", leaseId); } if (metadata != null) { IdentifierValidation.EnsureNamesAreValidIdentifiers(metadata.Keys); } var dataAndHash = data.AsXmlByteArrayWithMd5Hash(); _data = dataAndHash.XmlBytes; _requestContentMD5 = dataAndHash.MD5Hash; _containerName = containerName; _blobName = blobName; _contentType = contentType; _contentEncoding = contentEncoding; _contentLanguage = contentLanguage; _blobContentMD5 = blobContentMD5; _cacheControl = cacheControl; _metadata = metadata; _leaseId = leaseId; }
public async Task <PutBlockListResponse> PutBlockListAsync(string containerName, string blobName, BlockListBlockIdList data, string cacheControl = null, string contentType = null, string contentEncoding = null, string contentLanguage = null, string blobContentMD5 = null, Dictionary <string, string> metadata = null, string leaseId = null) { var request = new PutBlockListRequest(_account, containerName, blobName, data, cacheControl, contentType, contentEncoding, contentLanguage, blobContentMD5, metadata, leaseId); var response = await request.ExecuteAsync(); return(response.Payload); }
public void Execute_BlockList_ResponseParsesHeadersCorrectly() { var expectedContainer = "test-container"; var expectedBlob = "test-blob"; var expectedUri = String.Format("{0}/{1}/{2}?comp=blocklist", _settings.BlobEndpoint, expectedContainer, expectedBlob); var expectedDate = DateTime.UtcNow.AddDays(-2345); var expectedRawRequest = new TestableWebRequest(new Uri(expectedUri)) .EnqueueResponse(new HttpResponseSettings((HttpStatusCode)201, "Created", "", false, new Dictionary<string, string>(){ {"ETag", "\"123\""}, {"Date", expectedDate.ToString() }, {"Last-Modified", expectedDate.ToString() }, {"Content-MD5", "123-MD5" } })); TestableWebRequestCreateFactory.GetFactory().AddRequest(expectedRawRequest); var expectedData = new BlockListBlockIdList(); var request = new PutBlockListRequest(_settings, expectedContainer, expectedBlob, expectedData); var response = request.Execute(); Assert.AreEqual("123", response.Payload.ETag); Assert.IsTrue(Math.Abs(expectedDate.Subtract(response.Payload.Date).TotalMinutes) < 1); Assert.IsTrue(Math.Abs(expectedDate.Subtract(response.Payload.LastModified).TotalMinutes) < 1); Assert.AreEqual("123-MD5", response.Payload.ContentMD5); }
protected List <string> GetIdsFromBlockIdList(BlockListBlockIdList list) { return(list.Select(bid => bid.Id).ToList()); }
protected List<string> GetIdsFromBlockIdList(BlockListBlockIdList list) { return list.Select(bid => bid.Id).ToList(); }
protected BlockListBlockIdList CreateBlockIdList(int idCount, BlockListListType listType) { var idList = new BlockListBlockIdList(); for (var i = 0; i < idCount; i++) { idList.Add(new BlockListBlockId { Id = Base64Converter.ConvertToBase64("id" + idCount), ListType = listType }); } return idList; }