public void Should_get_serialized_json_format()
        {
            var testHelper = new TestHelper(authToken, storageUrl);
            testHelper.PutItemInContainer(Constants.StorageItemNameJpg);
            var getContainerInformation = new GetContainerInformationSerialized(storageUrl,  Constants.CONTAINER_NAME, Format.JSON);

            var jsonResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken);
            Assert.That(jsonResponse.Status, Is.EqualTo(HttpStatusCode.OK));
            var jsonReturnValue = String.Join("", jsonResponse.ContentBody.ToArray());
            jsonResponse.Dispose();
            var expectedSubString = "[{\"name\":[ ]?\"" + Constants.StorageItemNameJpg + "\",[ ]?\"hash\":[ ]?\"b44a59383b3123a747d139bd0e71d2df\",[ ]?\"bytes\":[ ]?\\d+,[ ]?\"content_type\":[ ]?\"image.*jpeg\",[ ]?\"last_modified\":[ ]?\"" + String.Format("{0:yyyy-MM}", DateTime.Now);

            Assert.That(Regex.Match(jsonReturnValue, expectedSubString).Success, Is.True);
            testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
            testHelper.Dispose();
        }
        public void Should_get_serialized_xml_format()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                testHelper.PutItemInContainer(Constants.StorageItemNameJpg);
                var getContainerInformation = new GetContainerInformationSerialized(storageUrl,  Constants.CONTAINER_NAME, Format.XML);

                var xmlResponse = new GenerateRequestByType().Submit(getContainerInformation, authToken);
                Assert.That(xmlResponse.Status, Is.EqualTo(HttpStatusCode.OK));
                var xmlReturnValue = String.Join("", xmlResponse.ContentBody.ToArray());
                xmlResponse.Dispose();
                var expectedSubString = "<container name=\"" + Constants.CONTAINER_NAME + "\"><object><name>" + Constants.StorageItemNameJpg + "<\\/name><hash>b44a59383b3123a747d139bd0e71d2df<\\/hash><bytes>\\d+<\\/bytes><content_type>image.*jpeg<\\/content_type><last_modified>" + String.Format("{0:yyyy-MM}", DateTime.Now);

                Assert.That(Regex.Match(xmlReturnValue, expectedSubString).Success || string.IsNullOrEmpty(xmlReturnValue), Is.True);
                testHelper.DeleteItemFromContainer(Constants.StorageItemNameJpg);
            }
        }
 public void setup()
 {
     GetContainerInformationSerialized = new GetContainerInformationSerialized("http://storageurl", "authtoken", "containername", Format.XML);
 }
        /// <summary>
        /// XML serialized format of the container's objects
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// XmlDocument xmlResponse = connection.GetContainerInformationXml("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">name of the container to get information</param>
        /// <returns>xml document of object information inside the container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public XmlDocument GetContainerInformationXml(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting container information (XML format) for container '"
                + containerName + "' for user "
                + _usercreds.Username);

            try
            {
                var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, containerName, Format.XML);
                var getSerializedResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
                var xmlResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
                getSerializedResponse.Dispose();

                if (xmlResponse == null) return new XmlDocument();

                var xmlDocument = new XmlDocument();
                try
                {
                    xmlDocument.LoadXml(xmlResponse);

                }
                catch (XmlException)
                {
                    return xmlDocument;
                }

                return xmlDocument;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information (XML format) 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");

                throw;
            }
        }
        /// <summary>
        /// JSON serialized format of the container's objects
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// string jsonResponse = connection.GetContainerInformationJson("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">name of the container to get information</param>
        /// <param name="parameters">Parameters to feed to the request to filter the returned list</param>
        /// <returns>json string of object information inside the container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public string GetContainerInformationJson(string containerName, Dictionary<GetItemListParameters, string> parameters)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting container information (JSON format) for container '"
                + containerName + "' for user "
                + _usercreds.Username);

            try
            {
                var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, containerName, Format.JSON, parameters);
                var getSerializedResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
                var jsonResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
                getSerializedResponse.Dispose();
                return jsonResponse;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information (JSON format) 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");

                throw;
            }
        }
        /// <summary>
        /// JSON serialized format of the container's objects
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// string jsonResponse = connection.GetContainerInformationJson("container name");
        /// </code>
        /// </example>
        /// <param name="containerName">name of the container to get information</param>
        /// <returns>json string of object information inside the container</returns>
        /// <exception cref="ArgumentNullException">Thrown when any of the reference parameters are null</exception>
        public string GetContainerInformationJson(string containerName)
        {
            if (string.IsNullOrEmpty(containerName))
                throw new ArgumentNullException();

            Log.Info(this, "Getting container information (JSON format) for container '"
                + containerName + "' for user "
                + UserCredentials.Username);

            try
            {
                var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, AuthToken, containerName, Format.JSON);
                var getSerializedResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getContainerInformation, UserCredentials.ProxyCredentials));
                var jsonResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
                getSerializedResponse.Dispose();
                return jsonResponse;
            }
            catch (WebException we)
            {
                Log.Error(this, "Error getting container information (JSON format) for container '"
                    + containerName + "' for user "
                    + UserCredentials.Username, we);

                var response = (HttpWebResponse)we.Response;
                if (response != null && response.StatusCode == HttpStatusCode.NotFound)
                    throw new ContainerNotFoundException("The requested container does not exist");

                throw;
            }
        }
        private XmlDocument getContainerInformationXml(string containerName)
        {
            var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, containerName, Format.XML);
            var getSerializedResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
            var xmlResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
            getSerializedResponse.Dispose();

            var xmlDocument = new XmlDocument();
            try
            {
                xmlDocument.LoadXml(xmlResponse);
            }
            catch (XmlException)
            {
                return xmlDocument;
            }

            return xmlDocument;
        }
 private string getContainerInformationJson(string containerName)
 {
     var getContainerInformation = new GetContainerInformationSerialized(StorageUrl, containerName, Format.JSON);
     var getSerializedResponse = _requestfactory.Submit(getContainerInformation, AuthToken, _usercreds.ProxyCredentials);
     var jsonResponse = String.Join("", getSerializedResponse.ContentBody.ToArray());
     getSerializedResponse.Dispose();
     return jsonResponse;
 }