public async Task CannotGetStorageFolderWithEmptyContainerName()
 {
     var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
     await client.GetStorageFolder(string.Empty, "a/b/c/");
 }
        public async Task ExceptionthrownWhenGettingAStorageFolderThatDoesNotExistAndCannotBeInferred()
        {
            var containerName = "TestContainer";
            var folderName = "a/b/c/";
            var headers = new HttpHeadersAbstraction()
            {
                {"X-Container-Bytes-Used", "1234"},
                {"X-Container-Object-Count", "1"}
            };

            var payload = @"[]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var resp = await client.GetStorageFolder(containerName, folderName);
        }
 public async Task CannotGetStorageFolderWithNullFolderName()
 {
     var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
     await client.GetStorageFolder("container", null);
 }
        public async Task CanGetStorageFolderWithNoContentResponse()
        {
            var containerName = "TestContainer";
            var folderName = "a/b/c/";
            var headers = new HttpHeadersAbstraction()
            {
                {"X-Container-Bytes-Used", "1234"},
                {"X-Container-Object-Count", "1"}
            };

            var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var result = await client.GetStorageFolder(containerName, folderName);

            Assert.IsNotNull(result);
            Assert.AreEqual("a/b/c/", result.FullName);
            Assert.AreEqual("c", result.Name);
            Assert.IsNotNull(result.Objects);
            Assert.AreEqual(0, result.Objects.Count());
            Assert.IsNotNull(result.Folders);
            Assert.AreEqual(0, result.Folders.Count());
        }
        public async Task CanGetStorageFolderWithOkResponseAndSubFolders()
        {
            var containerName = "TestContainer";
            var folderName = "a/b/c/";
            var headers = new HttpHeadersAbstraction()
            {
                {"X-Container-Bytes-Used", "1234"},
                {"X-Container-Object-Count", "1"}
            };

            var payload = @"[
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""a/b/c/"",
                                    ""content_type"": ""application/octet-stream""
                                },
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""a/b/c/BLAH"",
                                    ""content_type"": ""application/octet-stream""
                                },
                                {
                                        ""subdir"": ""a/b/c/d/""
                                },
                                {
                                        ""subdir"": ""a/b/c/x/""
                                }
                            ]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var resp = await client.GetStorageFolder(containerName, folderName);

            Assert.AreEqual("c", resp.Name);
            Assert.AreEqual("a/b/c/", resp.FullName);
            Assert.AreEqual(1, resp.Objects.Count);
            Assert.AreEqual(2, resp.Folders.Count);

            var obj = resp.Objects.First();
            Assert.AreEqual("a/b/c/BLAH", obj.FullName);

            var dNode = resp.Folders.First(f => f.FullName == "a/b/c/d/");
            var xNode = resp.Folders.First(f => f.FullName == "a/b/c/x/");

            Assert.AreEqual("d", dNode.Name);
            Assert.AreEqual(0, dNode.Folders.Count);
            Assert.AreEqual(0, dNode.Objects.Count);

            Assert.AreEqual("x", xNode.Name);
            Assert.AreEqual(0, xNode.Folders.Count);
            Assert.AreEqual(0, xNode.Objects.Count);
        }
 public async Task CannotGetStorageManifestWithNullContainerName()
 {
     var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
     await client.GetStorageManifest(null, "a/b/c/manifest");
 }
 public async Task CannotGetStorageManifestWithEmptyFolderName()
 {
     var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
     await client.GetStorageManifest("container", string.Empty);
 }
        public async Task CanGetStorageContainerWithOkResponse()
        {
            var containerName = "TestContainer";
            var headers = new HttpHeadersAbstraction()
            {
                {"X-Container-Bytes-Used", "1234"},
                {"X-Container-Object-Count", "1"}
            };

            var payload = @"[
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""BLAH"",
                                    ""content_type"": ""application/octet-stream""
                                }]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var result = await client.GetStorageContainer(containerName);
            
            Assert.IsNotNull(result);
            Assert.AreEqual(containerName, result.Name);
            Assert.AreEqual(1234, result.TotalBytesUsed);
            Assert.AreEqual(1, result.TotalObjectCount);
            Assert.IsNotNull(result.Objects);
            Assert.AreEqual(1, result.Objects.Count());
        }
        public async Task CannotGetStaticStorageManifestWhenObjectIsNotManifest()
        {
            var containerName = "TestContainer";
            var manifestName = "a/b/c/manifest";

            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-Static-Large-Object","False"}
            };

            var payload = @"[
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""a/b/c/BLAH"",
                                    ""content_type"": ""application/octet-stream""
                                }]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            await client.GetStorageManifest(containerName, manifestName);
        }
        public async Task CanGetStaticStorageManifestWithOkResponseAndPayload()
        {
            var containerName = "TestContainer";
            var manifestName = "a/b/c/manifest";

            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-Static-Large-Object","True"}
            };

            var payload = @"[
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""a/b/c/BLAH"",
                                    ""content_type"": ""application/octet-stream""
                                }]";

            var content = TestHelper.CreateStream(payload);

            var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var result = await client.GetStorageManifest(containerName, manifestName);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(StaticLargeObjectManifest));
            Assert.AreEqual(manifestName, result.FullName);
            Assert.AreEqual("manifest", result.Name);

            var manifest = result as StaticLargeObjectManifest;
            Assert.IsNotNull(manifest.Objects);
            Assert.AreEqual(1, manifest.Objects.Count());
            Assert.AreEqual("a/b/c/BLAH", manifest.Objects.First().FullName);
        }
        public async Task CanGetDynamicStorageManifestWithOkResponseAndPayload()
        {
            var containerName = "TestContainer";
            var manifestName = "a/b/c/manifest";

            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 restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
            this.StorageServiceRestClient.Responses.Enqueue(restResp);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
            var result = await client.GetStorageManifest(containerName, manifestName);

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DynamicLargeObjectManifest));
            Assert.AreEqual(manifestName, result.FullName);
            Assert.AreEqual("manifest", result.Name);
            var manifest = result as DynamicLargeObjectManifest;
            Assert.AreEqual("a/b", manifest.SegmentsPath);
        }
        public async Task CannotCreateManifestWithNullManifest()
        {
            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;

           await client.CreateStorageManifest(null);
        }
        public async Task CannotCreateManifestWithEmptyManifestName()
        {
            var containerName = "TestContainer";

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;

            var manifest = new TestStorageManifest(containerName, string.Empty);

            await client.CreateStorageManifest(manifest);
        }
        public async Task CannotCreateManifestWithNullContainerName()
        {
            var manifestName = "a/b/c/manifest";

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;

            var manifest = new TestStorageManifest(null, manifestName);

            await client.CreateStorageManifest(manifest);
        }
        public async Task CanCreateDynamicManifestWithCreatedResponse()
        {
            var containerName = "TestContainer";
            var manifestName = "a/b/c/manifest";
            var segPath = "TestContainer/a/b/c";

            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 headers2 = new HttpHeadersAbstraction()
            {
                {"Content-Length", "1234"},
                {"Content-Type", "application/octet-stream"},
                {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"},
                {"ETag", "d41d8cd98f00b204e9800998ecf8427e"},
                {"X-Object-Manifest",segPath}
            };

            var restResp1 = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.Created);
            var restResp2 = new HttpResponseAbstraction(new MemoryStream(), headers2, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp1);
            this.StorageServiceRestClient.Responses.Enqueue(restResp2);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;

            var manifest = new DynamicLargeObjectManifest(containerName, manifestName, segPath);
                
            var result = await client.CreateStorageManifest(manifest);

            Assert.IsTrue(this.StorageServiceRestClient.CreatedDynamicManifestCalled);
            Assert.IsInstanceOfType(result, typeof(DynamicLargeObjectManifest));
            Assert.AreEqual(manifestName, result.FullName);
            Assert.AreEqual(containerName, result.ContainerName);
            Assert.AreEqual(segPath, ((DynamicLargeObjectManifest)result).SegmentsPath);
        }
        public async Task CanCreateStaticManifestWithCreatedResponse()
        {
            var containerName = "TestContainer";
            var manifestName = "a/b/c/manifest";

            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 headers2 = new HttpHeadersAbstraction()
            {
                {"Content-Length", "1234"},
                {"Content-Type", "application/octet-stream"},
                {"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"},
                {"ETag", "d41d8cd98f00b204e9800998ecf8427e"},
                {"X-Static-Large-Object","True"}
            };

            var payload = @"[
                                {
                                    ""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
                                    ""last_modified"": ""2014-03-07T21:31:31.588170"",
                                    ""bytes"": 0,
                                    ""name"": ""a/b/c/BLAH"",
                                    ""content_type"": ""application/octet-stream""
                                }]";

            var content = TestHelper.CreateStream(payload);

            var restResp1 = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.Created);
            var restResp2 = new HttpResponseAbstraction(content, headers2, HttpStatusCode.OK);
            this.StorageServiceRestClient.Responses.Enqueue(restResp1);
            this.StorageServiceRestClient.Responses.Enqueue(restResp2);

            var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;

            var manifest = new StaticLargeObjectManifest(containerName, manifestName,
                new List<StorageObject>()
                {
                    new StorageObject("a/b/c/BLAH", containerName, new Dictionary<string, string>())
                });

            var result = await client.CreateStorageManifest(manifest);

            Assert.IsTrue(this.StorageServiceRestClient.CreateStaticManifestCalled);
            Assert.IsInstanceOfType(result, typeof(StaticLargeObjectManifest));
            Assert.AreEqual(manifestName, result.FullName);
            Assert.AreEqual(containerName, result.ContainerName);
            Assert.AreEqual(1, ((StaticLargeObjectManifest)result).Objects.Count);
            Assert.AreEqual("a/b/c/BLAH", ((StaticLargeObjectManifest)result).Objects.First().FullName);
        }