Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/corelib/Core/Domain/Container.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
17 changes: 17 additions & 0 deletions src/corelib/Core/IObjectStoreProvider.cs
Original file line number Diff line number Diff line change
@@ -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<Container> ListContainers(CloudIdentity identity, int? limit = null, string markerId = null, string markerEnd = null, string format = "json", string region = null);

#endregion
}
}
63 changes: 63 additions & 0 deletions src/corelib/Providers/Rackspace/ObjectStoreProvider.cs
Original file line number Diff line number Diff line change
@@ -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<Container> 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<string, string>();
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<Container []>(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
}
}
2 changes: 1 addition & 1 deletion src/corelib/Providers/Rackspace/ProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected ProviderBase(IIdentityProvider identityProvider, IRestService restServ
_restService = restService;
}

protected Response<T> ExecuteRESTRequest<T>(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary<string, string> queryStringParameter = null, Dictionary<string, string> headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null)
protected Response<T> ExecuteRESTRequest<T>(CloudIdentity identity, Uri absoluteUri, HttpMethod method, object body = null, Dictionary<string, string> queryStringParameter = null, Dictionary<string, string> headers = null, bool isRetry = false, JsonRequestSettings requestSettings = null)
{
if (requestSettings == null)
requestSettings = BuildDefaultRequestSettings();
Expand Down
4 changes: 4 additions & 0 deletions src/corelib/corelib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
<ItemGroup>
<Compile Include="Core\Domain\Address.cs" />
<Compile Include="Core\Domain\CloudIdentity.cs" />
<Compile Include="Core\Domain\Container.cs" />
<Compile Include="Core\Domain\Flavor.cs" />
<Compile Include="Core\Domain\FlavorDetails.cs" />
<Compile Include="Core\Domain\ImageType.cs" />
Expand All @@ -68,6 +69,9 @@
<Compile Include="Core\Exceptions\Response\ServiceLimitReachedException.cs" />
<Compile Include="Core\Exceptions\Response\ServiceUnavailableException.cs" />
<Compile Include="Core\Exceptions\Response\UserNotAuthorizedException.cs" />
<Compile Include="Core\IObjectStoreProvider.cs" />
<Compile Include="Providers\Rackspace\ObjectStoreProvider.cs" />

<Compile Include="Providers\Rackspace\ComputeProvider.cs" />
<Compile Include="Core\Exceptions\InvalidCloudIdentityException.cs" />
<Compile Include="Providers\Rackspace\Objects\Request\AddRoleRequest.cs" />
Expand Down
6 changes: 3 additions & 3 deletions src/testing/integration/App.config
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="TestIdentityUserName" value="cloud2"/>
<add key="TestIdentityUserName" value=""/>
<add key="TestIdentityAPIKey" value=""/>
<add key="TestIdentityPassword" value="Hybr1d99"/>
<add key="TestIdentityGeo" value="DFW"/>
<add key="TestIdentityPassword" value=""/>
<add key="TestIdentityGeo" value=""/>
</appSettings>
</configuration>
113 changes: 113 additions & 0 deletions src/testing/integration/Providers/Rackspace/ObjectStoreTests.cs
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
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());
}


}
}
1 change: 1 addition & 0 deletions src/testing/integration/integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Providers\Rackspace\ComputeTests.cs" />
<Compile Include="Providers\Rackspace\IdentityTests.cs" />
<Compile Include="Providers\Rackspace\ObjectStoreTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\corelib\corelib.csproj">
Expand Down