public void Should_return_not_found_when_the_container_does_not_exist() { var getContainerInformation = new GetContainerInformation(storageUrl, "Idonthasacontainer"); new GenerateRequestByType().Submit(getContainerInformation, authToken); Assert.Fail("Expecting a 404 error when trying to retrieve data about a non-existent container"); }
/// <summary> /// This method retrieves the number of storage objects in a container, and the total size, in bytes, of the container /// </summary> /// <example> /// <code> /// UserCredentials userCredentials = new UserCredentials("username", "api key"); /// IConnection connection = new Connection(userCredentials); /// Container container = connection.GetContainerInformation("container name"); /// </code> /// </example> /// <param name="containerName">The name of the container to query about</param> /// <returns>An instance of container, with the number of storage objects contained and total byte allocation</returns> /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception> public Container GetContainerInformation(string containerName) { if (string.IsNullOrEmpty(containerName)) throw new ArgumentNullException(); Log.Info(this, "Getting container information for container '" + containerName + "' for user " + _usercreds.Username); try { var getContainerInformation = new GetContainerInformation(StorageUrl, containerName); var getContainerInformationResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials); var container = new Container(containerName) { ByteCount = long.Parse( getContainerInformationResponse.Headers[Constants.X_CONTAINER_BYTES_USED]), ObjectCount = long.Parse( getContainerInformationResponse.Headers[ Constants.X_CONTAINER_STORAGE_OBJECT_COUNT]) }; var url = getContainerCDNUri(container); if (!string.IsNullOrEmpty(url)) url += "/"; container.CdnUri = url; return container; } catch (WebException we) { Log.Error(this, "Error getting container information for container '" + containerName + "' for user " + _usercreds.Username, we); var response = (HttpWebResponse)we.Response; if (response != null && response.StatusCode == HttpStatusCode.NotFound) throw new ContainerNotFoundException("The requested container does not exist"); if (response != null && response.StatusCode == HttpStatusCode.Unauthorized) throw new AuthenticationFailedException(we.Message); throw; } }
public void setup() { getContainerInformation = new GetContainerInformation("http://storageurl", "authtoken", "containername"); }
public void Should_return_no_content_when_the_container_exists_and_the_name_contains_spaces() { const string containerName = "I am making a funky container"; using(var testHelper = new TestHelper(authToken, storageUrl, containerName)) { testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName); var getContainerInformation = new GetContainerInformation(storageUrl, containerName); var informationResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken); Assert.That(informationResponse.Status, Is.EqualTo(HttpStatusCode.NoContent)); Assert.That(informationResponse.Headers[Constants.XContainerObjectCount], Is.EqualTo("1")); Assert.That(informationResponse.Headers[Constants.XContainerBytesUsed], (Is.Not.Null)); testHelper.DeleteItemFromContainer(Constants.StorageItemName); } }
public void Should_throw_an_exception_when_the_container_name_exceeds_the_maximum_allowed_length() { var getContainerInformation = new GetContainerInformation(storageUrl, new string('a', Constants.MaximumContainerNameLength + 1)); new GenerateRequestByType().Submit(getContainerInformation, authToken); Assert.Fail("Expecting a ContainerNameException"); }
public void Should_return_no_content_when_the_container_exists() { using (TestHelper testHelper = new TestHelper(authToken, storageUrl)) { testHelper.PutItemInContainer(Constants.StorageItemName, Constants.StorageItemName); GetContainerInformation getContainerInformation = new GetContainerInformation(storageUrl, Constants.CONTAINER_NAME); var informationResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken); Assert.That(informationResponse.Status, Is.EqualTo(HttpStatusCode.NoContent)); Assert.That(informationResponse.Headers[Constants.XContainerObjectCount], Is.EqualTo("1")); Assert.That(informationResponse.Headers[Constants.XContainerBytesUsed], (Is.Not.Null)); testHelper.DeleteItemFromContainer(Constants.StorageItemName); } }
private Container getContainerInformation(string containerName) { var getContainerInformation = new GetContainerInformation(StorageUrl, containerName); var getContainerInformationResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials); var container = new Container(containerName) { ByteCount = long.Parse( getContainerInformationResponse.Headers[Constants.X_CONTAINER_BYTES_USED]), ObjectCount = long.Parse( getContainerInformationResponse.Headers[ Constants.X_CONTAINER_STORAGE_OBJECT_COUNT]) }; var url = GetContainerCdnUri(container); if (!string.IsNullOrEmpty(url)) url += "/"; container.CdnUri = url; return container; }