diff --git a/src/corelib/Core/Domain/Container.cs b/src/corelib/Core/Domain/Container.cs new file mode 100644 index 000000000..26736b89d --- /dev/null +++ b/src/corelib/Core/Domain/Container.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; + +namespace net.openstack.Core.Domain +{ + [DataContract] + public class Container + { + [DataMember] + public string Name { get; set; } + + [DataMember] + public int Count { get; set; } + + [DataMember] + public long Bytes { get; set; } + } +} diff --git a/src/corelib/Core/IObjectStoreProvider.cs b/src/corelib/Core/IObjectStoreProvider.cs new file mode 100644 index 000000000..fbf35e46a --- /dev/null +++ b/src/corelib/Core/IObjectStoreProvider.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using net.openstack.Core.Domain; + +namespace net.openstack.Core +{ + public interface IObjectStoreProvider + { + #region Container + + IEnumerable ListContainers(CloudIdentity identity, int? limit = null, string markerId = null, string markerEnd = null, string format = "json", string region = null); + + #endregion + } +} diff --git a/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs b/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs new file mode 100644 index 000000000..73ebc2596 --- /dev/null +++ b/src/corelib/Providers/Rackspace/ObjectStoreProvider.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using SimpleRestServices.Client; +using SimpleRestServices.Client.Json; +using net.openstack.Core; +using net.openstack.Core.Domain; +using net.openstack.Providers.Rackspace.Objects.Request; +using net.openstack.Providers.Rackspace.Objects.Response; + +namespace net.openstack.Providers.Rackspace +{ + public class ObjectStoreProvider : ProviderBase, IObjectStoreProvider + { + #region Constructors + + public ObjectStoreProvider() + : this(new IdentityProvider(), new JsonRestServices()) { } + + public ObjectStoreProvider(IIdentityProvider identityProvider, IRestService restService) + : base(identityProvider, restService) { } + + #endregion + + #region Containers + + public IEnumerable ListContainers(CloudIdentity identity, int? limit = null, string marker = null, string markerEnd = null, string format = "json", string region = null) + { + var urlPath = new Uri(string.Format("{0}", GetServiceEndpoint(identity, region))); + + var queryStringParameter = new Dictionary(); + queryStringParameter.Add("format", format); + + if (limit != null) + queryStringParameter.Add("limit", limit.ToString()); + + if (!string.IsNullOrWhiteSpace(marker)) + queryStringParameter.Add("marker", marker); + + if (!string.IsNullOrWhiteSpace(markerEnd)) + queryStringParameter.Add("end_marker", markerEnd); + + var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.GET, null, queryStringParameter); + + if (response == null || response.Data == null) + return null; + + return response.Data; + + } + + #endregion + + #region Private methods + + protected string GetServiceEndpoint(CloudIdentity identity, string region = null) + { + return base.GetServiceEndpoint(identity, "cloudFiles", region); + } + + #endregion + } +} diff --git a/src/corelib/Providers/Rackspace/ProviderBase.cs b/src/corelib/Providers/Rackspace/ProviderBase.cs index 485d9f1e4..acc28f135 100644 --- a/src/corelib/Providers/Rackspace/ProviderBase.cs +++ b/src/corelib/Providers/Rackspace/ProviderBase.cs @@ -23,7 +23,7 @@ protected ProviderBase(IIdentityProvider identityProvider, IRestService restServ _restService = restService; } - protected Response ExecuteRESTRequest(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary queryStringParameter = null, Dictionary headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null) + protected Response ExecuteRESTRequest(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary queryStringParameter = null, Dictionary headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null) { if (requestSettings == null) requestSettings = BuildDefaultRequestSettings(); diff --git a/src/corelib/corelib.csproj b/src/corelib/corelib.csproj index b21772cc1..e6ebf80c5 100644 --- a/src/corelib/corelib.csproj +++ b/src/corelib/corelib.csproj @@ -49,6 +49,7 @@ + @@ -68,6 +69,9 @@ + + + diff --git a/src/testing/integration/App.config b/src/testing/integration/App.config index 5fcc05c56..f2783bae1 100644 --- a/src/testing/integration/App.config +++ b/src/testing/integration/App.config @@ -1,9 +1,9 @@  - + - - + + \ No newline at end of file diff --git a/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs b/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs new file mode 100644 index 000000000..c2ff1ad5b --- /dev/null +++ b/src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs @@ -0,0 +1,113 @@ +using System; +using System.Configuration; +using System.Text; +using System.Collections.Generic; +using System.Linq; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using net.openstack.Core.Domain; +using net.openstack.Providers.Rackspace; + +namespace Net.OpenStack.Testing.Integration.Providers.Rackspace +{ + [TestClass] + public class ObjectStoreTests + { + + public ObjectStoreTests() + { + CloudInstance cloudInstance; + CloudInstance.TryParse(ConfigurationManager.AppSettings["TestIdentityGeo"], true, out cloudInstance); + + _testIdentity = new RackspaceCloudIdentity + { + APIKey = ConfigurationManager.AppSettings["TestIdentityAPIKey"], + Password = ConfigurationManager.AppSettings["TestIdentityPassword"], + CloudInstance = cloudInstance, + Username = ConfigurationManager.AppSettings["TestIdentityUserName"], + }; + } + + private TestContext testContextInstance; + private static CloudIdentity _testIdentity; + + /// + ///Gets or sets the test context which provides + ///information about and functionality for the current test run. + /// + public TestContext TestContext + { + get + { + return testContextInstance; + } + set + { + testContextInstance = value; + } + } + + + [TestMethod] + public void Should_Return_Container_List() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity); + + Assert.IsNotNull(containerList); + Assert.IsTrue(containerList.Any()); + } + + [TestMethod] + public void Should_Return_Container_List_With_Limit() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity,1); + + Assert.IsNotNull(containerList); + Assert.AreEqual(1, containerList.Count()); + } + + [TestMethod] + public void Should_Return_Container_List_With_Start_Marker_Lower_Case() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity, null,"a"); + + Assert.IsNotNull(containerList); + Assert.IsTrue(containerList.Any()); + } + + [TestMethod] + public void Should_Return_Container_List_With_Start_Marker_Upper_Case() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity, null, "A"); + + Assert.IsNotNull(containerList); + Assert.IsTrue(containerList.Any()); + } + + + [TestMethod] + public void Should_Return_Container_List_With_End_Marker_Upper_Case() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity, null, null,"L"); + + Assert.IsNotNull(containerList); + Assert.IsTrue(containerList.Any()); + } + + [TestMethod] + public void Should_Return_Container_List_With_End_Marker_Lower_Case() + { + var provider = new ObjectStoreProvider(); + var containerList = provider.ListContainers(_testIdentity, null, null, "l"); + + Assert.IsNotNull(containerList); + Assert.IsTrue(containerList.Any()); + } + + + } +} diff --git a/src/testing/integration/integration.csproj b/src/testing/integration/integration.csproj index a84cfd613..fa18f8442 100644 --- a/src/testing/integration/integration.csproj +++ b/src/testing/integration/integration.csproj @@ -55,6 +55,7 @@ +