public ICloudBlob GetBlobReferenceFromServer(MemoryBlobStore store, FakeStorageBlobContainer parent, string blobName) { if (!_items.ContainsKey(blobName)) { throw StorageExceptionFactory.Create(404); } Blob blob = _items[blobName]; if (blob._hook != null) { return(blob._hook); } FakeStorageBlobProperties properties = new FakeStorageBlobProperties() { ETag = blob.ETag, LastModified = blob.LastModified, }; switch (blob.BlobType) { case BlobType.BlockBlob: return(new FakeStorageBlockBlob(blobName, parent, properties)); case BlobType.PageBlob: return(new FakeStoragePageBlob(blobName, parent, properties)); case BlobType.AppendBlob: return(new FakeStorageAppendBlob(blobName, parent, properties)); default: throw new InvalidOperationException(string.Format("Type '{0}' is not supported.", blob.BlobType)); } }
public FakeStorageAppendBlob(string blobName, FakeStorageBlobContainer parent, FakeStorageBlobProperties properties = null) : base(parent.GetBlobUri(blobName)) { _store = parent._store; _blobName = blobName; _parent = parent; _containerName = parent.Name; _metadata = new Dictionary <string, string>(); if (properties != null) { _properties = properties; ApplyProperties(); } else { _properties = new FakeStorageBlobProperties(); } // currentBlob.Properties.LastModified.Value.UtcDateTime; // CloudBlob.Properties { return this.attributes.Properties } // where attributes is internal BlobAttributes class. // return BlobProperties this.SetInternalProperty(nameof(ServiceClient), parent._client); }
public ICloudBlob GetBlobReferenceFromServer(FakeStorageBlobContainer parent, string containerName, string blobName) { if (!_items.ContainsKey(containerName)) { throw StorageExceptionFactory.Create(404); } return(_items[containerName].GetBlobReferenceFromServer(this, parent, blobName)); }
public FakeStoragePageBlob(string blobName, FakeStorageBlobContainer parent, FakeStorageBlobProperties properties = null) : base(parent.GetBlobUri(blobName)) { _store = parent._store; _blobName = blobName; _parent = parent; _containerName = parent.Name; _metadata = new Dictionary <string, string>(); if (properties != null) { _properties = properties; ApplyProperties(); } else { _properties = new FakeStorageBlobProperties(); } this.SetInternalProperty(nameof(ServiceClient), parent._client); }
public IEnumerable <ICloudBlob> ListBlobs(MemoryBlobStore store, FakeStorageBlobContainer parent, BlobListingDetails blobListingDetails) { if (blobListingDetails != BlobListingDetails.None && blobListingDetails != BlobListingDetails.Metadata) { throw new NotImplementedException(); } List <ICloudBlob> results = new List <ICloudBlob>(); foreach (KeyValuePair <string, Blob> item in _items) { string blobName = item.Key; // Etag and LastModifiedTime is always passed in listBlobs FakeStorageBlobProperties properties = new FakeStorageBlobProperties() { ETag = item.Value.ETag, LastModified = item.Value.LastModified, }; ICloudBlob blob = new FakeStorageBlockBlob(blobName, parent, properties); if ((blobListingDetails | BlobListingDetails.Metadata) == BlobListingDetails.Metadata) { Blob storeBlob = item.Value; IReadOnlyDictionary <string, string> storeMetadata = storeBlob.Metadata; foreach (KeyValuePair <string, string> pair in storeMetadata) { blob.Metadata.Add(pair.Key, pair.Value); } } results.Add(blob); } return(results); }
public BlobResultSegment ListBlobsSegmented(Func <string, FakeStorageBlobContainer> containerFactory, string prefix, bool useFlatBlobListing, BlobListingDetails blobListingDetails, int?maxResults, BlobContinuationToken currentToken) { if (prefix == null) { throw new ArgumentNullException("prefix"); } if (!useFlatBlobListing) { throw new NotImplementedException(); } if (blobListingDetails != BlobListingDetails.None && blobListingDetails != BlobListingDetails.Metadata) { throw new NotImplementedException(); } if (prefix.StartsWith("$logs/")) { return(TestExtensions.NewBlobResultSegment(null, new List <ICloudBlob>())); } if (prefix.Contains("/")) { throw new NotImplementedException(); } if (!_items.ContainsKey(prefix)) { // if there are no blobs with the criteria, azure storage return empty list not null object return(TestExtensions.NewBlobResultSegment(null, new List <ICloudBlob>())); } FakeStorageBlobContainer parent = containerFactory.Invoke(prefix); List <ICloudBlob> results = _items[prefix].ListBlobs(this, parent, blobListingDetails).ToList(); // handle token // in this mock up token.NextMarker is going to be assumed the last blob returned in the last // call, we will remove everything before and send the rest with a new token that is the last // element in the new list if (currentToken != null) { var edgeMarker = results.FindIndex(r => r.Name == currentToken.NextMarker); // if it is not the last element then filter all before the marker including the marker if (!(edgeMarker == results.Count - 1)) { results.RemoveRange(0, edgeMarker + 1); } } // handle maxResults if (maxResults.HasValue && results.ToList().Count > maxResults.Value) { int realMaxResults = maxResults.Value; List <ICloudBlob> filteredResult = (List <ICloudBlob>)results; filteredResult.RemoveRange(realMaxResults, (filteredResult.Count - realMaxResults)); BlobContinuationToken token = new BlobContinuationToken(); token.NextMarker = filteredResult.Last().Name; return(TestExtensions.NewBlobResultSegment(token, results)); } return(TestExtensions.NewBlobResultSegment(null, results)); }