public void should_return_account_name_and_ok_status_200()
        {
            var accountInformationXml = new GetAccountInformationSerialized(storageUrl, authToken, Format.XML);
            var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));
            Assert.That(getAccountInformationXmlResponse.Status, Is.EqualTo(HttpStatusCode.OK));

            var contentBody = "";
            foreach (var s in getAccountInformationXmlResponse.ContentBody)
            {
                contentBody += s;
            }

            getAccountInformationXmlResponse.Dispose();
            const string expectedSubString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><account name=\"MossoCloudFS_5d8f3dca-7eb9-4453-aa79-2eea1b980353\"></account>";
            Assert.That(contentBody, Is.EqualTo(expectedSubString));
        }
        public void should_return_account_information_in_json_format_including_name_count_and_bytes()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl, authToken, Format.JSON);
                    var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getAccountInformationJson));

                    if(getAccountInformationJsonResponse.ContentBody.Count == 0)
                        Assert.Fail("No content body returned in response");

            //                    foreach (string s in getAccountInformationJsonResponse.ContentBody)
            //                    {
            //                        Console.WriteLine(s);
            //                    }

                    var expectedSubString = "{\"name\": \"" + Constants.CONTAINER_NAME + "\", \"count\": 1, \"bytes\": 34}";
                    var contentBody = getAccountInformationJsonResponse.ContentBody;
                    getAccountInformationJsonResponse.Dispose();
                    foreach (var s in contentBody)
                    {
                        if (s.IndexOf(expectedSubString) > -1) return;
                    }

                    Assert.Fail("Expected value: " + expectedSubString + " not found");

                }
                finally
                {

                    testHelper.DeleteItemFromContainer();
                }
            }
        }
        public void should_return_empty_brackets_and_ok_status_200()
        {
            var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl, authToken, Format.JSON);
            var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(getAccountInformationJson));
            Assert.That(getAccountInformationJsonResponse.Status, Is.EqualTo(HttpStatusCode.OK));
            var contentBody = String.Join("",getAccountInformationJsonResponse.ContentBody.ToArray());
            getAccountInformationJsonResponse.Dispose();

            Assert.That(contentBody, Is.EqualTo("[]"));
        }
        public void should_return_account_information_in_xml_format_including_name_count_and_size()
        {
            using (TestHelper testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var accountInformationXml = new GetAccountInformationSerialized(storageUrl, authToken, Format.XML);
                    var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));

                    if (getAccountInformationXmlResponse.ContentBody.Count == 0)
                        Assert.Fail("No content body returned in response");

                    var contentBody = "";
                    foreach (var s in getAccountInformationXmlResponse.ContentBody)
                    {
                        contentBody += s;
                    }

                    getAccountInformationXmlResponse.Dispose();
                    var xmlDocument = new XmlDocument();
                    try
                    {
                        xmlDocument.LoadXml(contentBody);
                    }
                    catch(XmlException e)
                    {
                        Console.WriteLine(e.Message);
                    }

            //                    Console.WriteLine(xmlDocument.InnerXml);
                    var expectedSubString = "<container><name>"+ Constants.CONTAINER_NAME +"</name><count>1</count><bytes>34</bytes></container>";
                    Assert.That(contentBody.IndexOf(expectedSubString) > 0, Is.True);
                }
                finally
                {
                    testHelper.DeleteItemFromContainer();
                }
            }
        }
示例#5
0
        XmlDocument buildaccountxml()
        {
            var accountInformationXml = new GetAccountInformationSerialized(StorageUrl, Format.XML);
            var getAccountInformationXmlResponse = _requestfactory.Submit(accountInformationXml, AuthToken);

            if (getAccountInformationXmlResponse.ContentBody.Count == 0)
            {
                return new XmlDocument();

            }
            var contentBody = String.Join("", getAccountInformationXmlResponse.ContentBody.ToArray());

            getAccountInformationXmlResponse.Dispose();

            try
            {
                var doc = new XmlDocument();
                doc.LoadXml(contentBody);
                return doc;
            }
            catch (XmlException)
            {
                return new XmlDocument();

            }
        }
        public void should_return_empty_brackets_and_ok_status_200()
        {
            var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl,  Format.JSON);
            var getAccountInformationJsonResponse = new GenerateRequestByType().Submit(getAccountInformationJson, authToken);
            Assert.That(getAccountInformationJsonResponse.Status, Is.EqualTo(HttpStatusCode.OK));
            var contentBody = String.Join("",getAccountInformationJsonResponse.ContentBody.ToArray());
            getAccountInformationJsonResponse.Dispose();

            Assert.That(contentBody, Is.EqualTo("[]"));
        }
 public void setup()
 {
     getAccountInformationSerialized = new GetAccountInformationSerialized("http://storageurl", Format.XML);
     _mockrequest = new Mock<ICloudFilesRequest>();
 }
示例#8
0
        private string buildaccountjson()
        {
            string jsonResponse = "";
            var getAccountInformationJson = new GetAccountInformationSerialized(StorageUrl, Format.JSON);
            var getAccountInformationJsonResponse = _requestfactory.Submit(getAccountInformationJson, AuthToken);

            if (getAccountInformationJsonResponse.ContentBody.Count > 0)
                jsonResponse = String.Join("", getAccountInformationJsonResponse.ContentBody.ToArray());

            getAccountInformationJsonResponse.Dispose();
            return jsonResponse;
        }
示例#9
0
        /// <summary>
        /// Get account information in xml format
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// XmlDocument xmlReturnValue = connection.GetAccountInformationXml();
        /// </code>
        /// </example>
        /// <returns>XML serialized format of the account information</returns>
        public XmlDocument GetAccountInformationXml()
        {
            try
            {
                Log.Info(this, "Getting account information (XML format) for user " + UserCredentials.Username);
                var accountInformationXml = new GetAccountInformationSerialized(StorageUrl, AuthToken, Format.XML);
                var getAccountInformationXmlResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>().Create(new CloudFilesRequest(accountInformationXml));

                if (getAccountInformationXmlResponse.ContentBody.Count == 0) return new XmlDocument();

                var contentBody = String.Join("", getAccountInformationXmlResponse.ContentBody.ToArray());
                getAccountInformationXmlResponse.Dispose();

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

                return xmlDocument;
            }
            catch(Exception ex)
            {
                Log.Error(this, "Error getting account information (XML format) for user "
                    + UserCredentials.Username, ex);
                throw;
            }
        }
示例#10
0
        /// <summary>
        /// Get account information in json format
        /// </summary>
        /// <example>
        /// <code>
        /// UserCredentials userCredentials = new UserCredentials("username", "api key");
        /// IConnection connection = new Connection(userCredentials);
        /// string jsonReturnValue = connection.GetAccountInformationJson();
        /// </code>
        /// </example>
        /// <returns>JSON serialized format of the account information</returns>
        public string GetAccountInformationJson()
        {
            try
            {
                Log.Info(this, "Getting account information (JSON format) for user " + UserCredentials.Username);
                var getAccountInformationJson = new GetAccountInformationSerialized(StorageUrl, AuthToken, Format.JSON);
                var getAccountInformationJsonResponse = new ResponseFactoryWithContentBody<CloudFilesResponseWithContentBody>()
                    .Create(new CloudFilesRequest(getAccountInformationJson));

                if (getAccountInformationJsonResponse.ContentBody.Count == 0) return "";
                var jsonResponse = String.Join("", getAccountInformationJsonResponse.ContentBody.ToArray());

                getAccountInformationJsonResponse.Dispose();
                return jsonResponse;
            }
            catch (Exception ex)
            {
                Log.Error(this, "Error getting account information (JSON format) for user "
                                + UserCredentials.Username, ex);
                throw;
            }
        }
 public void setup()
 {
     getAccountInformationSerialized = new GetAccountInformationSerialized("http://storageurl", "authtoken", Format.JSON);
 }
        public void should_return_account_information_in_json_format_including_name_count_and_bytes()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var getAccountInformationJson = new GetAccountInformationSerialized(storageUrl,  Format.JSON);
                    var getAccountInformationJsonResponse = new GenerateRequestByType().Submit(getAccountInformationJson, authToken);

                    if(getAccountInformationJsonResponse.ContentBody.Count == 0)
                        Assert.Fail("No content body returned in response");

                    const string expectedSubString = "{\"name\":[ ]?\"" + Constants.CONTAINER_NAME + "\",[ ]?\"count\":[ ]?\\d+,[ ]?\"bytes\":[ ]?\\d+}";
                    var contentBody = getAccountInformationJsonResponse.ContentBody;
                    getAccountInformationJsonResponse.Dispose();
                    foreach (var s in contentBody)
                    {
                        if (Regex.Match(s, expectedSubString).Success) return;
                    }

                    Assert.Fail("Expected value: " + expectedSubString + " not found");

                }
                finally
                {

                    testHelper.DeleteItemFromContainer();
                }
            }
        }
        public void should_return_account_information_in_xml_format_including_name_count_and_size()
        {
            using (var testHelper = new TestHelper(authToken, storageUrl))
            {
                try
                {
                    testHelper.PutItemInContainer(Constants.StorageItemName);

                    var accountInformationXml = new GetAccountInformationSerialized(storageUrl,  Format.XML);
                    var getAccountInformationXmlResponse = new GenerateRequestByType().Submit(accountInformationXml,authToken);

                    if (getAccountInformationXmlResponse.ContentBody.Count == 0)
                        Assert.Ignore("No content body returned in response");

                    var contentBody = "";
                    foreach (var s in getAccountInformationXmlResponse.ContentBody)
                    {
                        contentBody += s;
                    }

                    getAccountInformationXmlResponse.Dispose();
                    var xmlDocument = new XmlDocument();
                    try
                    {
                        xmlDocument.LoadXml(contentBody);
                    }
                    catch(XmlException e)
                    {
                        Console.WriteLine(e.Message);
                    }

                    const string expectedSubString = "<container><name>"+ Constants.CONTAINER_NAME +"</name><count>\\d*</count><bytes>\\d+</bytes></container>";
                    Assert.That(Regex.Match(contentBody, expectedSubString).Success, Is.True);
                }
                finally
                {
                    testHelper.DeleteItemFromContainer();
                }
            }
        }