Adding support for per-client-instance extensibility. See: https://wiki.openstack.org/wiki/OpenStack-SDK-DotNet/HighLevelArch for more details.

Updated the example code project to be in sync with the api.
Cleaned up a few style/comment issues, and move around a few bits of code to make things a little cleaner.

Partially implements blueprint consider-removing-composition
Change-Id: Ibb3946f1033bd37f8850e68ed0f8b7ef77acaeb2
This commit is contained in:
Wayne Foley
2014-04-29 14:02:13 -07:00
parent b81511caaf
commit 0feeedb1c1
57 changed files with 962 additions and 735 deletions

View File

@@ -1,7 +1,20 @@
using System;
using System.Linq;
using System.Security;
using System.Threading;
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using OpenStack;
using OpenStack.Identity;
using OpenStack.Storage;
@@ -19,19 +32,12 @@ namespace SimpleStorageExample
var password = "password";
var tenantId = "tenant Id"; // e.g. XXXXXXXXXXXXX-Project
//Convert the plain text password into a SecureString.
//Ideally you should never store your passwords in plain text, but for this example we will.
var securePassword = new SecureString();
password.ToCharArray().ToList().ForEach(securePassword.AppendChar);
//Construct an OpenStackCredential object that will be used to authenticate.
//The credential will also be useful later as it contains a reference to the service catalog, and access token.
var credential = new OpenStackCredential(authUri, userName, securePassword, tenantId);
var credential = new OpenStackCredential(authUri, userName, password, tenantId);
//Create a new OpenStackClient object using the credentials you just created.
//A cancellation token can also be supplied, this will allow you to cancel any long running tasks
//that the client may make.
var client = new OpenStackClient(credential, CancellationToken.None);
var client = OpenStackClientFactory.CreateClient(credential);
//Connect the client to OpenStack. This will authenticate you, as well as construct the service catalog,
//and retrieve the access token that will be used in future calls to OpenStack services.

View File

@@ -35,12 +35,10 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\Bin\Debug\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="OpenStack">
<Reference Include="OpenStack, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\Bin\Debug\OpenStack.dll</HintPath>
</Reference>
<Reference Include="OpenStack.Common">
<HintPath>..\..\Bin\Debug\OpenStack.Common.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />

View File

@@ -28,14 +28,15 @@ namespace OpenStack.Test.Identity
public class IdentityServiceClientTests
{
internal TestIdentityServicePocoClient pocoClient;
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.ServiceLocator = new ServiceLocator();
this.pocoClient = new TestIdentityServicePocoClient();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IIdentityServicePocoClientFactory), new TestIdentityServicePocoClientFactory(pocoClient));
}
@@ -43,7 +44,7 @@ namespace OpenStack.Test.Identity
public void TestCleanup()
{
this.pocoClient = new TestIdentityServicePocoClient();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
public IOpenStackCredential GetValidCredentials()
@@ -68,7 +69,7 @@ namespace OpenStack.Test.Identity
return Task.Factory.StartNew(() => creds);
};
var client = new IdentityServiceClientDefinition().Create(GetValidCredentials(),CancellationToken.None) as IdentityServiceClient;
var client = new IdentityServiceClientDefinition().Create(GetValidCredentials(), CancellationToken.None, this.ServiceLocator) as IdentityServiceClient;
var resp = await client.Authenticate();
Assert.AreEqual(creds, resp);

View File

@@ -33,14 +33,16 @@ namespace OpenStack.Test.Identity
{
internal TestIdentityServiceRestClient RestClient;
internal string defaultRegion = "region-a.geo-1";
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.RestClient = new TestIdentityServiceRestClient();
this.ServiceLocator = new ServiceLocator();
this.ServiceLocator.EnsureAssemblyRegistration(typeof(ServiceLocator).Assembly);
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IIdentityServiceRestClientFactory), new TestIdentityServiceRestClientFactory(RestClient));
manager.RegisterServiceInstance(typeof(IOpenStackRegionResolver), new TestOpenStackRegionResolver(defaultRegion));
}
@@ -49,7 +51,7 @@ namespace OpenStack.Test.Identity
public void TestCleanup()
{
this.RestClient = new TestIdentityServiceRestClient();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
public IOpenStackCredential GetValidCredentials()
@@ -111,7 +113,7 @@ namespace OpenStack.Test.Identity
this.RestClient.Response = restResp;
var client =
new IdentityServicePocoClientFactory().Create(creds, CancellationToken.None) as
new IdentityServicePocoClientFactory().Create(creds, CancellationToken.None, this.ServiceLocator) as
IdentityServicePocoClient;
var result = await client.Authenticate();
@@ -170,7 +172,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
var result = await client.Authenticate();
Assert.IsNotNull(result);
@@ -227,7 +229,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
var result = await client.Authenticate();
Assert.AreEqual(expectedRegion, result.Region);
@@ -242,7 +244,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -255,7 +257,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.BadRequest);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -268,7 +270,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -281,7 +283,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Forbidden);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -294,7 +296,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.MethodNotAllowed);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -307,7 +309,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.RequestEntityTooLarge);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -320,7 +322,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.ServiceUnavailable);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
@@ -333,7 +335,7 @@ namespace OpenStack.Test.Identity
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.RestClient.Response = restResp;
var client = new IdentityServicePocoClient(creds, CancellationToken.None);
var client = new IdentityServicePocoClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
}
}

View File

@@ -31,14 +31,15 @@ namespace OpenStack.Test.Identity
public class IdentityServiceRestClientTests
{
internal IdentityRestServiceSimulator simulator;
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.simulator = new IdentityRestServiceSimulator();
this.ServiceLocator = new ServiceLocator();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IHttpAbstractionClientFactory), new IdentityRestServiceSimulatorFactory(simulator));
}
@@ -46,7 +47,7 @@ namespace OpenStack.Test.Identity
public void TestCleanup()
{
this.simulator = new IdentityRestServiceSimulator();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
public IOpenStackCredential GetValidCredentials()
@@ -63,7 +64,7 @@ namespace OpenStack.Test.Identity
public async Task AuthenticationMethodAndUriAreValid()
{
var creds = GetValidCredentials();
var client = new IdentityServiceRestClientFactory().Create(creds,CancellationToken.None);
var client = new IdentityServiceRestClientFactory().Create(creds,CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
@@ -75,7 +76,7 @@ namespace OpenStack.Test.Identity
public async Task AuthenticateIncludesCorrectHeaders()
{
var creds = GetValidCredentials();
var client = new IdentityServiceRestClient(creds, CancellationToken.None);
var client = new IdentityServiceRestClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();
@@ -88,7 +89,7 @@ namespace OpenStack.Test.Identity
public async Task AuthenticateIncludesPayload()
{
var creds = GetValidCredentials();
var client = new IdentityServiceRestClient(creds, CancellationToken.None);
var client = new IdentityServiceRestClient(creds, CancellationToken.None, this.ServiceLocator);
await client.Authenticate();

View File

@@ -16,8 +16,8 @@
using System;
using System.Linq;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test.Identity
@@ -57,7 +57,7 @@ namespace OpenStack.Test.Identity
]
}]}}";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
var serviceDefs = converter.Convert(serviceCatalogPayload).ToList();
Assert.AreEqual(1, serviceDefs.Count());
@@ -118,7 +118,7 @@ namespace OpenStack.Test.Identity
]
}]}}";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
var serviceDefs = converter.Convert(serviceCatalogPayload).ToList();
Assert.AreEqual(2, serviceDefs.Count());
@@ -145,7 +145,7 @@ namespace OpenStack.Test.Identity
}}";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
converter.Convert(serviceCatalogPayload);
}
@@ -155,7 +155,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @" { }";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -163,7 +163,7 @@ namespace OpenStack.Test.Identity
[ExpectedException(typeof(ArgumentNullException))]
public void CannotConvertWithNullJsonPayload()
{
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
converter.Convert(null);
}
@@ -173,7 +173,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @" { NOT JSON";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -183,7 +183,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @"[]";
var converter = new OpenStackServiceCatalogPayloadConverter();
var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
}

View File

@@ -25,103 +25,9 @@ namespace OpenStack.Test.Identity
[TestClass]
public class OpenStackServiceCatalogTests
{
[TestMethod]
public void CanGetPublicEndpointForService()
{
var expectedEndpoint = new Uri("http://public.endpoint.org");
var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
});
var catalog = new OpenStackServiceCatalog {serviceDef};
var endpoint = catalog.GetPublicEndpoint("Test Service", "some region");
Assert.AreEqual(expectedEndpoint,endpoint);
}
[TestMethod]
public void CanGetPublicEndpointForServiceWithMultipleServicesInCatalog()
{
var expectedEndpoint = new Uri("http://public.endpoint.org");
var catalog = new OpenStackServiceCatalog();
catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint("http://other.endpoint.org", "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
var endpoint = catalog.GetPublicEndpoint("Test Service", "some region");
Assert.AreEqual(expectedEndpoint, endpoint);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void CannotGetPublicEndpointWithNoMatchingService()
{
var catalog = new OpenStackServiceCatalog();
catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint("http://some.endpoint.org", "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint("http://other.endpoint.org", "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
catalog.GetPublicEndpoint("Missing Service", "some region");
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void CannotGetPublicEndpointWithServiceAndNoEndpoints()
{
var catalog = new OpenStackServiceCatalog();
catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()));
catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint("http://other.endpoint.org", "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
catalog.GetPublicEndpoint("Test Service", "some region");
}
[TestMethod]
public void CanGetPublicEndpointWithServiceAndMultipleEndpoints()
{
var expectedEndpoint = new Uri("http://public.endpoint.org");
var catalog = new OpenStackServiceCatalog();
catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint("http://public.endpoint.org", "some region", "1.0",
"http://www.someplace.com", "http://www.someplace.com"),
new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
"http://www.someplace.com", "http://www.someplace.com")
}));
var endpoint = catalog.GetPublicEndpoint("Test Service", "some region");
Assert.AreEqual(expectedEndpoint, endpoint);
}
[TestMethod]
public void IfAServiceExistsCatalogReturnsTrue()

View File

@@ -18,6 +18,7 @@ using System;
using System.Linq;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test.Identity
@@ -54,7 +55,7 @@ namespace OpenStack.Test.Identity
]
}";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
var service = converter.Convert(serviceDefPayload);
Assert.IsNotNull(service);
@@ -89,7 +90,7 @@ namespace OpenStack.Test.Identity
]
}";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -119,7 +120,7 @@ namespace OpenStack.Test.Identity
]
}";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -132,7 +133,7 @@ namespace OpenStack.Test.Identity
""type"": ""object-store"",
}";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -142,7 +143,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @" { }";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -150,7 +151,7 @@ namespace OpenStack.Test.Identity
[ExpectedException(typeof(ArgumentNullException))]
public void CannotConvertWithNullJsonPayload()
{
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(null);
}
@@ -160,7 +161,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @" { NOT JSON";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
@@ -170,7 +171,7 @@ namespace OpenStack.Test.Identity
{
var serviceDefPayload = @"[]";
var converter = new OpenStackServiceDefinitionPayloadConverter();
var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
converter.Convert(serviceDefPayload);
}
}

View File

@@ -17,6 +17,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test.Identity
@@ -40,7 +41,7 @@ namespace OpenStack.Test.Identity
this.client = client;
}
public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token)
public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator)
{
return client;
}

View File

@@ -17,6 +17,7 @@
using System.Threading;
using System.Threading.Tasks;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test.Identity
@@ -40,7 +41,7 @@ namespace OpenStack.Test.Identity
this.Client = client;
}
public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken)
public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
return Client;
}

View File

@@ -17,8 +17,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test
@@ -56,6 +58,11 @@ namespace OpenStack.Test
public IOpenStackCredential Credential { get; private set; }
public TestOpenStackClient(ICredential cred, CancellationToken token, IServiceLocator locator)
{
}
public Task Connect()
{
throw new NotImplementedException();
@@ -175,7 +182,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanRegisterANewClient()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.RegisterClient<TestOpenStackClient>();
Assert.AreEqual(1, manager.clients.Count);
@@ -186,7 +193,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterTheSameClientTwice()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.RegisterClient<TestOpenStackClient>();
manager.RegisterClient<TestOpenStackClient>();
}
@@ -194,7 +201,8 @@ namespace OpenStack.Test
[TestMethod]
public void CanRegisterMultipleClients()
{
var manager = new OpenStackClientManager();
//var manager = OpenStackClientManager.Instance as OpenStackClientManager;
var manager = new OpenStackClientManager(new ServiceLocator());
manager.RegisterClient<TestOpenStackClient>();
manager.RegisterClient<OtherTestOpenStackClient>();
@@ -206,7 +214,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanListAvailableClients()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(TestOpenStackClient));
manager.clients.Add(typeof(OtherTestOpenStackClient));
@@ -220,7 +228,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanCreateAClient()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(TestOpenStackClient));
var client = manager.CreateClient(new TestCredential());
@@ -233,7 +241,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAClientIfCredentialIsNotSupported()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(OtherTestOpenStackClient));
manager.CreateClient(new TestCredential());
@@ -243,7 +251,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAClientIfNoClientsAreRegistered()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.CreateClient(new TestCredential());
}
@@ -251,7 +259,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CannotCreateAClientWithNullCredential()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(TestOpenStackClient));
manager.CreateClient((ICredential)null);
@@ -261,7 +269,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CannotCreateAClientWithNullCredentialAndVersion()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(TestOpenStackClient));
manager.CreateClient(null, "1.0.0..0");
@@ -271,7 +279,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CannotCreateAClientWithCredentialAndNullVersion()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
manager.clients.Add(typeof(TestOpenStackClient));
manager.CreateClient(new TestCredential(), null);
@@ -280,9 +288,10 @@ namespace OpenStack.Test
[TestMethod]
public void CanCreateAnInstanceOfAClient()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
var creds = new OpenStackCredential(new Uri("http://someurl.com"), "user", "password", "12345");
var client = manager.CreateClient(typeof (TestOpenStackClient));
var client = manager.CreateClientInstance(typeof(TestOpenStackClient), creds, CancellationToken.None);
Assert.IsNotNull(client);
Assert.IsInstanceOfType(client, typeof(TestOpenStackClient));
}
@@ -291,26 +300,29 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CanCreateAnInstanceOfAClientWithNullType()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
var creds = new OpenStackCredential(new Uri("http://someurl.com"), "user", "password", "12345");
manager.CreateClient((Type)null);
manager.CreateClientInstance((Type)null, creds, CancellationToken.None);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAnInstanceOfANonOpenStackClient()
{
var manager = new OpenStackClientManager();
manager.CreateClient(typeof(Object));
var manager = new OpenStackClientManager(new ServiceLocator());
var creds = new OpenStackCredential(new Uri("http://someurl.com"), "user", "password", "12345");
manager.CreateClientInstance(typeof(Object), creds, CancellationToken.None);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAnInstanceOfAOpenStackClientWithoutADefaultCtor()
{
var manager = new OpenStackClientManager();
var manager = new OpenStackClientManager(new ServiceLocator());
var creds = new OpenStackCredential(new Uri("http://someurl.com"), "user", "password", "12345");
manager.CreateClient(typeof(NonDefaultTestOpenStackClient));
manager.CreateClientInstance(typeof(NonDefaultTestOpenStackClient), creds, CancellationToken.None);
}
}
}

View File

@@ -29,6 +29,8 @@ namespace OpenStack.Test
[TestClass]
public class OpenStackClientTests
{
internal IServiceLocator ServiceLocator;
internal class TestIdentityServiceClient : IIdentityServiceClient
{
internal IOpenStackCredential cred;
@@ -54,7 +56,7 @@ namespace OpenStack.Test
{
public string Name { get; private set; }
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken)
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
return new TestIdentityServiceClient((IOpenStackCredential)credential, cancellationToken);
}
@@ -73,11 +75,10 @@ namespace OpenStack.Test
[TestInitialize]
public void TestSetup()
{
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var serviceManager = new OpenStackServiceClientManager();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
var serviceManager = new OpenStackServiceClientManager(this.ServiceLocator);
serviceManager.RegisterServiceClient<TestIdentityServiceClient>(new TestIdentityServiceClientDefinition());
manager.RegisterServiceInstance(typeof(IOpenStackServiceClientManager), serviceManager);
}
@@ -85,7 +86,7 @@ namespace OpenStack.Test
[TestCleanup]
public void TestCleanup()
{
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
[TestMethod]
@@ -94,7 +95,7 @@ namespace OpenStack.Test
var client =
new OpenStackClient(
new OpenStackCredential(new Uri("http://someplace.org"), "someuser", "password",
"sometenant"), CancellationToken.None);
"sometenant"), CancellationToken.None, this.ServiceLocator);
await client.Connect();
Assert.AreEqual("12345", client.Credential.AccessTokenId);
}
@@ -105,7 +106,7 @@ namespace OpenStack.Test
var expectedRegion = "newregion";
var client = new OpenStackClient(
new OpenStackCredential(new Uri("http://someplace.org"), "someuser", "password",
"sometenant","oldregion"), CancellationToken.None);
"sometenant", "oldregion"), CancellationToken.None, this.ServiceLocator);
client.SetRegion(expectedRegion);
Assert.AreEqual(expectedRegion, client.Credential.Region);
@@ -117,7 +118,7 @@ namespace OpenStack.Test
{
var client = new OpenStackClient(
new OpenStackCredential(new Uri("http://someplace.org"), "someuser", "password",
"sometenant", "oldregion"), CancellationToken.None);
"sometenant", "oldregion"), CancellationToken.None, this.ServiceLocator);
client.SetRegion(null);
}
@@ -127,7 +128,7 @@ namespace OpenStack.Test
{
var client = new OpenStackClient(
new OpenStackCredential(new Uri("http://someplace.org"), "someuser", "password",
"sometenant", "oldregion"), CancellationToken.None);
"sometenant", "oldregion"), CancellationToken.None, this.ServiceLocator);
client.SetRegion(string.Empty);
}

View File

@@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Test
@@ -38,7 +39,7 @@ namespace OpenStack.Test
{
public string Name { get; private set; }
public IOpenStackServiceClient Create(ICredential credential, CancellationToken token)
public IOpenStackServiceClient Create(ICredential credential, CancellationToken token, IServiceLocator serviceLocator)
{
return new TestOpenStackServiceClient(credential, token);
}
@@ -81,7 +82,7 @@ namespace OpenStack.Test
{
public string Name { get; private set; }
public IOpenStackServiceClient Create(ICredential credential, CancellationToken token)
public IOpenStackServiceClient Create(ICredential credential, CancellationToken token, IServiceLocator serviceLocator)
{
return new OtherTestOpenStackServiceClient(credential, token);
}
@@ -113,7 +114,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanRegisterANewService()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.RegisterServiceClient<TestOpenStackServiceClient>(new TestOpenStackServiceClientDefinition());
Assert.AreEqual(1, manager.serviceClientDefinitions.Count);
@@ -124,7 +125,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterTheSameServiceTwice()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.RegisterServiceClient<TestOpenStackServiceClient>(new TestOpenStackServiceClientDefinition());
manager.RegisterServiceClient<TestOpenStackServiceClient>(new TestOpenStackServiceClientDefinition());
}
@@ -132,7 +133,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanRegisterMultipleServices()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.RegisterServiceClient<TestOpenStackServiceClient>(new TestOpenStackServiceClientDefinition());
manager.RegisterServiceClient<OtherTestOpenStackServiceClient>(new OtherTestOpenStackServiceClientDefinition());
@@ -144,7 +145,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanListAvailableClients()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(TestOpenStackServiceClient), new TestOpenStackServiceClientDefinition());
manager.serviceClientDefinitions.Add(typeof(OtherTestOpenStackServiceClient), new OtherTestOpenStackServiceClientDefinition());
@@ -158,7 +159,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanCreateAClient()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(TestOpenStackServiceClient), new TestOpenStackServiceClientDefinition());
var service = manager.CreateServiceClient<TestOpenStackServiceClient>(new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
@@ -171,7 +172,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAServiceIfVersionIsNotSupported()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(OtherTestOpenStackServiceClient), new OtherTestOpenStackServiceClientDefinition());
manager.CreateServiceClient<OtherTestOpenStackServiceClient>(new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
@@ -181,7 +182,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAClientIfNoServicesAreRegistered()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.CreateServiceClient<OtherTestOpenStackServiceClient>(new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
}
@@ -189,7 +190,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CannotCreateAServiceWithNullCredential()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(TestOpenStackServiceClient), new TestOpenStackServiceClientDefinition());
manager.CreateServiceClient<TestOpenStackServiceClient>((ICredential)null, CancellationToken.None);
@@ -199,7 +200,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CannotCreateAServiceWithNullCredentialAndVersion()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(TestOpenStackServiceClient), new TestOpenStackServiceClientDefinition());
manager.CreateServiceClient<TestOpenStackServiceClient>((ICredential)null, CancellationToken.None);
@@ -209,7 +210,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(InvalidOperationException))]
public void CannotCreateAServiceWithCredentialAndNullFactory()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.serviceClientDefinitions.Add(typeof(TestOpenStackServiceClient), null);
manager.CreateServiceClient<TestOpenStackServiceClient>(new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
@@ -218,7 +219,7 @@ namespace OpenStack.Test
[TestMethod]
public void CanCreateAnInstanceOfAService()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
var service = manager.CreateServiceClientInstance(new TestOpenStackServiceClientDefinition(), new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
Assert.IsNotNull(service);
@@ -229,7 +230,7 @@ namespace OpenStack.Test
[ExpectedException(typeof(ArgumentNullException))]
public void CanCreateAnInstanceOfAServiceWithNullFactory()
{
var manager = new OpenStackServiceClientManager();
var manager = new OpenStackServiceClientManager(new ServiceLocator());
manager.CreateServiceClientInstance(null, new OpenStackClientManagerTests.TestCredential(), CancellationToken.None);
}
}

View File

@@ -119,25 +119,24 @@ namespace OpenStack.Test.ServiceLocation
[TestInitialize]
public void Initialize()
{
ServiceLocator.Reset();
}
[TestCleanup]
public void TestCleanup()
{
ServiceLocator.Reset();
}
[TestMethod]
public void CanRegisterAndLocateAService()
{
var locator = new ServiceLocator();
var myServiceInstance = new TestEchoService();
var manager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var manager = locator.Locate<IServiceLocationRuntimeManager>();
Assert.IsNotNull(manager);
manager.RegisterServiceInstance<ITestEchoService>(myServiceInstance);
var service = ServiceLocator.Instance.Locate<ITestEchoService>();
var service = locator.Locate<ITestEchoService>();
Assert.IsNotNull(service);
Assert.AreEqual("Works", service.Echo("Works"));
@@ -147,25 +146,27 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotLocateAServiceThatHasNotBeenRegistered()
{
ServiceLocator.Instance.Locate<ITestEchoService>();
var locator = new ServiceLocator();
locator.Locate<ITestEchoService>();
}
[TestMethod]
public void CanOverrideAndLocateAService()
{
var locator = new ServiceLocator();
var echoServiceInstance = new TestEchoService();
var reverseEchoServiceInstance = new TestReverseEchoService();
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var overrrideManager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
var overrrideManager = locator.Locate<IServiceLocationOverrideManager>();
Assert.IsNotNull(runtimeManager);
Assert.IsNotNull(overrrideManager);
runtimeManager.RegisterServiceInstance<ITestEchoService>(echoServiceInstance);
overrrideManager.RegisterServiceInstance<ITestEchoService>(reverseEchoServiceInstance);
var service = ServiceLocator.Instance.Locate<ITestEchoService>();
var service = locator.Locate<ITestEchoService>();
Assert.IsNotNull(service);
Assert.IsInstanceOfType(service, typeof(TestReverseEchoService));
@@ -176,7 +177,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterNullService()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance<ITestEchoService>(null);
}
@@ -185,7 +187,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterNullType()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance(null,new TestEchoService());
}
@@ -194,7 +197,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterNonInterface()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance<string>("Hello!");
}
@@ -203,7 +207,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterAServiceLocator()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance<IServiceLocator>(new TestServiceLocator());
}
@@ -212,7 +217,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterAServiceManager()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance<IServiceLocationRuntimeManager>(new TestServiceManager());
}
@@ -221,7 +227,8 @@ namespace OpenStack.Test.ServiceLocation
[ExpectedException(typeof(InvalidOperationException))]
public void CannotRegisterAnOverrideManager()
{
var runtimeManager = ServiceLocator.Instance.Locate<IServiceLocationRuntimeManager>();
var locator = new ServiceLocator();
var runtimeManager = locator.Locate<IServiceLocationRuntimeManager>();
runtimeManager.RegisterServiceInstance<IServiceLocationOverrideManager>(new TestServiceOverrideManager());
}

View File

@@ -16,9 +16,9 @@
using System;
using System.Linq;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Storage;
namespace OpenStack.Test.Storage
@@ -44,7 +44,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
var account = converter.Convert(accountName, headers, validSingleContainerJson);
Assert.IsNotNull(account);
@@ -73,7 +73,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -95,7 +95,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -117,7 +117,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Object-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -140,7 +140,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -163,7 +163,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -186,7 +186,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "NOT A NUMBER"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, validSingleContainerJson);
}
@@ -208,7 +208,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, invalidSingleContainerJson);
}
@@ -230,7 +230,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(null, headers, validSingleContainerJson);
}
@@ -246,7 +246,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, null, validSingleContainerJson);
}
@@ -263,7 +263,7 @@ namespace OpenStack.Test.Storage
{"X-Account-Container-Count", "1"}
};
var converter = new StorageAccountPayloadConverter();
var converter = new StorageAccountPayloadConverter(new ServiceLocator());
converter.Convert(accountName, headers, null);
}
}

View File

@@ -16,9 +16,9 @@
using System;
using System.Linq;
using System.Web;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Storage;
namespace OpenStack.Test.Storage
@@ -42,7 +42,7 @@ namespace OpenStack.Test.Storage
}
]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var containers = converter.Convert(validMultipleContainerJson).ToList();
Assert.AreEqual(2, containers.Count());
@@ -72,7 +72,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var containers = converter.Convert(validSingleContainerJson).ToList();
Assert.AreEqual(1, containers.Count());
@@ -90,7 +90,7 @@ namespace OpenStack.Test.Storage
{
var emptyJsonArray = @"[]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var containers = converter.Convert(emptyJsonArray).ToList();
Assert.AreEqual(0, containers.Count());
@@ -101,7 +101,7 @@ namespace OpenStack.Test.Storage
{
var payload = string.Empty;
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var containers = converter.Convert(payload).ToList();
Assert.AreEqual(0, containers.Count());
@@ -111,7 +111,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public void CannotParseANullPayload()
{
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(null);
}
@@ -119,7 +119,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(FormatException))]
public void CannotParseInvalidJsonPayload()
{
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert("[ { \"SomeAtrib\" }]");
}
@@ -127,7 +127,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(FormatException))]
public void CannotParseInvalidPayload()
{
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert("NOT JSON");
}
@@ -141,7 +141,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(InvalidJsonWithoutBytes);
}
@@ -155,7 +155,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(InvalidJsonWithoutCount);
}
@@ -169,7 +169,7 @@ namespace OpenStack.Test.Storage
""bytes"": 7
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(InvalidJsonWithoutName);
}
@@ -182,7 +182,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
try
{
converter.Convert(InvalidJsonWithoutBytes);
@@ -206,7 +206,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(InvalidJsonWithBadBytesValue);
}
@@ -221,7 +221,7 @@ namespace OpenStack.Test.Storage
""name"": ""TestContainer""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert(InvalidJsonWithBadCountValue);
}
@@ -238,7 +238,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"},
@@ -316,7 +316,7 @@ namespace OpenStack.Test.Storage
}
]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "45"},
@@ -372,7 +372,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Object-Count", "1"}
@@ -395,7 +395,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"}
@@ -418,7 +418,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "This is not a number"},
@@ -442,7 +442,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"},
@@ -461,8 +461,8 @@ namespace OpenStack.Test.Storage
{
""hash"": ""d41d8cd98f00b204e9800998ecf8427e"",
""last_modified"":";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"},
@@ -485,7 +485,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"},
@@ -508,7 +508,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
converter.Convert("Name", null, validObjectJson);
}
@@ -517,7 +517,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public void CannotParseContainerWithNullPayload()
{
var converter = new StorageContainerPayloadConverter();
var converter = new StorageContainerPayloadConverter(new ServiceLocator());
var headers = new HttpHeadersAbstraction
{
{"X-Container-Bytes-Used", "12345"},

View File

@@ -19,6 +19,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Storage;
namespace OpenStack.Test.Storage
@@ -30,7 +31,7 @@ namespace OpenStack.Test.Storage
public void CanAddFolderWithNestedFolders()
{
var objects = new List<StorageObject>() { new StorageObject("a/b/c/d/","a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1,folders.Count);
@@ -47,7 +48,7 @@ namespace OpenStack.Test.Storage
public void CanAddFolderWithNestedFoldersAndDuplicateNames()
{
var objects = new List<StorageObject>() { new StorageObject("a/c/c/c/", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -64,7 +65,7 @@ namespace OpenStack.Test.Storage
public void CanAddSingleFolder()
{
var objects = new List<StorageObject>() { new StorageObject("a/", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -77,7 +78,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public void CanAddFolderWithNullObjectList()
{
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
converter.Convert(null);
}
@@ -86,7 +87,7 @@ namespace OpenStack.Test.Storage
{
var objects = new List<StorageObject>() { new StorageObject("a/", "a"), new StorageObject("a/b/c/d/", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -104,7 +105,7 @@ namespace OpenStack.Test.Storage
{
var objects = new List<StorageObject>() { new StorageObject("a/b/c/d/foo", "a"), new StorageObject("a/b/c/d/bar", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -127,7 +128,7 @@ namespace OpenStack.Test.Storage
{
var objects = new List<StorageObject>() { new StorageObject("a/b/c/d/foo", "a"), new StorageObject("a/b/c/d/bar", "a"), new StorageObject("xyz", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -150,7 +151,7 @@ namespace OpenStack.Test.Storage
{
var objects = new List<StorageObject>() { new StorageObject("a/b/c/d/foo", "a"), new StorageObject("a/b/c/d/bar", "a"), new StorageObject("thiswillsorttothetopofthelist", "a") };
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
Assert.AreEqual(1, folders.Count);
@@ -180,7 +181,7 @@ namespace OpenStack.Test.Storage
new StorageObject("a/", "a")
};
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var folders = converter.Convert(objects).ToList();
var aNode = folders[0];
@@ -225,7 +226,7 @@ namespace OpenStack.Test.Storage
new StorageObject("a/b/", "a", DateTime.Now, "12345", 100, "application/directory")
};
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(objects).ToList();
Assert.AreEqual(1, resp.Count);
@@ -248,8 +249,8 @@ namespace OpenStack.Test.Storage
public void CanConvertFoldersWithNoInputObjects()
{
var objects = new List<StorageObject>();
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(objects).ToList();
Assert.AreEqual(0, resp.Count);
@@ -259,7 +260,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public void CannotConvertFoldersWithNullObjectList()
{
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(null);
}
@@ -277,7 +278,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(containerName, folderName, payload);
Assert.AreEqual(1, resp.Objects.Count);
@@ -297,7 +298,7 @@ namespace OpenStack.Test.Storage
var folderName = "a/b/c/";
var payload = @"[]";
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
converter.Convert(containerName, folderName, payload);
}
@@ -322,7 +323,7 @@ namespace OpenStack.Test.Storage
""content_type"": ""application/octet-stream""
}]";
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(containerName, folderName, payload);
Assert.AreEqual(1, resp.Objects.Count);
@@ -354,7 +355,7 @@ namespace OpenStack.Test.Storage
""subdir"": ""a/b/c/x/""
}]";
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(containerName, folderName, payload);
Assert.AreEqual(1, resp.Objects.Count);
@@ -405,7 +406,7 @@ namespace OpenStack.Test.Storage
}
]";
var converter = new StorageFolderPayloadConverter();
var converter = new StorageFolderPayloadConverter(new ServiceLocator());
var resp = converter.Convert(containerName, folderName, payload);
Assert.AreEqual("c", resp.Name);

View File

@@ -38,16 +38,18 @@ namespace OpenStack.Test.Storage
internal string authId = "12345";
internal string endpoint = "http://teststorageendpoint.com/v1/1234567890";
internal ServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.ServicePocoClient = new TestStorageServicePocoClient();
this.resovler = new TestOpenStackServiceEndpointResolver();
this.resovler.Endpoint = new Uri(endpoint);
this.loCreator = new TestLargeStorageObjectCreator();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
this.ServiceLocator = new ServiceLocator();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IStorageServicePocoClientFactory), new TestStorageServicePocoClientFactory(this.ServicePocoClient));
manager.RegisterServiceInstance(typeof(IOpenStackServiceEndpointResolver), resovler);
manager.RegisterServiceInstance(typeof(ILargeStorageObjectCreatorFactory), new TestLargeStorageObjectCreatorFactory(this.loCreator));
@@ -59,7 +61,7 @@ namespace OpenStack.Test.Storage
this.resovler = new TestOpenStackServiceEndpointResolver();
this.ServicePocoClient = new TestStorageServicePocoClient();
this.loCreator = new TestLargeStorageObjectCreator();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
IOpenStackCredential GetValidCreds()
@@ -75,7 +77,7 @@ namespace OpenStack.Test.Storage
var expectedUri = new Uri(endpoint);
this.resovler.Endpoint = expectedUri;
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
Assert.AreEqual(expectedUri, client.GetPublicEndpoint());
}
@@ -102,7 +104,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.ListStorageObjects(containerName);
Assert.AreEqual(1,numberObjCalls);
@@ -127,7 +129,7 @@ namespace OpenStack.Test.Storage
throw new InvalidOperationException("Cannot get storage object. '" +HttpStatusCode.NotFound +"'");
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.ListStorageObjects(containerName);
Assert.AreEqual(0, resp.Count());
@@ -137,7 +139,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task ListingStorageObjectsWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.ListStorageObjects(null);
}
@@ -161,7 +163,7 @@ namespace OpenStack.Test.Storage
this.ServicePocoClient.GetStorageAccountDelegate = () => Task.Factory.StartNew(() => account);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.ListStorageContainers();
var containers = resp.ToList();
@@ -180,7 +182,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => account);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageAccount();
Assert.AreEqual(account, resp);
@@ -202,7 +204,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageObject(containerName, objectName);
Assert.AreEqual(obj, resp);
@@ -214,7 +216,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageObject(null, objectName);
}
@@ -224,7 +226,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageObject(string.Empty, objectName);
}
@@ -234,7 +236,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageObject(containerName, null);
}
@@ -244,7 +246,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageObject(containerName, string.Empty);
}
@@ -264,7 +266,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => (StorageManifest)obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageManifest(containerName, manifestName);
Assert.AreEqual(obj, resp);
@@ -276,7 +278,7 @@ namespace OpenStack.Test.Storage
{
var manifestName = "TestManifest";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageManifest(null, manifestName);
}
@@ -286,7 +288,7 @@ namespace OpenStack.Test.Storage
{
var manifestName = "TestManifest";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageObject(string.Empty, manifestName);
}
@@ -296,7 +298,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageManifest(containerName, null);
}
@@ -306,7 +308,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageManifest(containerName, string.Empty);
}
@@ -325,7 +327,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageFolder(containerName, folderName);
Assert.AreEqual(obj, resp);
@@ -346,7 +348,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageFolder(containerName, folderName);
Assert.AreEqual(obj, resp);
@@ -358,7 +360,7 @@ namespace OpenStack.Test.Storage
{
var folderName = "TestFolder";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageFolder(null, folderName);
}
@@ -368,7 +370,7 @@ namespace OpenStack.Test.Storage
{
var folderName = "TestFolder";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageFolder(string.Empty, folderName);
}
@@ -378,7 +380,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageFolder(containerName, null);
}
@@ -388,7 +390,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageFolder(containerName, string.Empty);
}
@@ -410,7 +412,7 @@ namespace OpenStack.Test.Storage
return await Task.Run(()=>obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.CreateStorageObject(containerName, objectName, new Dictionary<string,string>(), content);
Assert.AreEqual(obj, resp);
@@ -419,7 +421,7 @@ namespace OpenStack.Test.Storage
[TestMethod]
public async Task CreatingAnObjectLargerThanTheThresholdCreatesObjectWithSegments()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var containerName = "TestContainer";
var objectName = "TestObject";
@@ -470,7 +472,7 @@ namespace OpenStack.Test.Storage
return await Task.Run(() => new StorageObject(o,c));
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, 3);
Assert.AreEqual(containerName, res.ContainerName);
@@ -486,7 +488,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(null, objectName, metadata, contentStream, 3);
}
@@ -499,7 +501,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(string.Empty, objectName, metadata, contentStream, 3);
}
@@ -512,7 +514,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, null, metadata, contentStream, 3);
}
@@ -525,7 +527,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, string.Empty, metadata, contentStream, 3);
}
@@ -538,7 +540,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, objectName, null, contentStream, 3);
}
@@ -550,7 +552,7 @@ namespace OpenStack.Test.Storage
var objectName = "TestObject";
var metadata = new Dictionary<string, string>();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, null, 3);
}
@@ -564,7 +566,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, -3);
}
@@ -578,7 +580,7 @@ namespace OpenStack.Test.Storage
var content = "THIS IS A LOT OF CONTENT THAT WILL AND CAN BE CHOPPED UP";
var contentStream = content.ConvertToStream();
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var res = await client.CreateLargeStorageObject(containerName, objectName, metadata, contentStream, 0);
}
@@ -588,7 +590,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(null, objectName, new Dictionary<string, string>(), new MemoryStream());
}
@@ -598,7 +600,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(string.Empty, objectName, new Dictionary<string, string>(), new MemoryStream());
}
@@ -608,7 +610,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(containerName, null, new Dictionary<string, string>(), new MemoryStream());
}
@@ -618,7 +620,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(containerName, string.Empty, new Dictionary<string, string>(), new MemoryStream());
}
@@ -629,7 +631,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(containerName, objectName, new Dictionary<string, string>(), null);
}
@@ -640,7 +642,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageObject(containerName, objectName, null, new MemoryStream());
}
@@ -659,7 +661,7 @@ namespace OpenStack.Test.Storage
return await Task.Run(() => m);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, objectName, new Dictionary<string, string>(), new List<StorageObject>() { obj });
}
@@ -675,7 +677,7 @@ namespace OpenStack.Test.Storage
return await Task.Run(() => m);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, objectName, new Dictionary<string, string>(), "segments");
}
@@ -686,7 +688,7 @@ namespace OpenStack.Test.Storage
var manifestName = "TestManifest";
var segmentPath = "segments";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(null, manifestName, new Dictionary<string, string>(), segmentPath);
}
@@ -697,7 +699,7 @@ namespace OpenStack.Test.Storage
var manifestName = "TestManifest";
var segmentPath = "segments";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(string.Empty, manifestName, new Dictionary<string, string>(), segmentPath);
}
@@ -708,7 +710,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var segmentPath = "segments";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, null, new Dictionary<string, string>(), segmentPath);
}
@@ -719,7 +721,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var segmentPath = "segments";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, string.Empty, new Dictionary<string, string>(), segmentPath);
}
@@ -730,7 +732,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var manifestName = "TestManifest";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, manifestName, new Dictionary<string, string>(), (string)null);
}
@@ -741,7 +743,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var manifestName = "TestManifest";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, manifestName, new Dictionary<string, string>(), string.Empty);
}
@@ -753,7 +755,7 @@ namespace OpenStack.Test.Storage
var manifestName = "TestManifest";
var segmentPath = "segments";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, manifestName, null, segmentPath);
}
@@ -767,7 +769,7 @@ namespace OpenStack.Test.Storage
var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345,
"application/octet-stream", new Dictionary<string, string>());
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(null, objectName, new Dictionary<string, string>(), new List<StorageObject>() { obj });
}
@@ -781,7 +783,7 @@ namespace OpenStack.Test.Storage
var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345,
"application/octet-stream", new Dictionary<string, string>());
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(string.Empty, objectName, new Dictionary<string, string>(), new List<StorageObject>() { obj });
}
@@ -795,7 +797,7 @@ namespace OpenStack.Test.Storage
var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345,
"application/octet-stream", new Dictionary<string, string>());
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, null, new Dictionary<string, string>(), new List<StorageObject>() { obj });
}
@@ -809,7 +811,7 @@ namespace OpenStack.Test.Storage
var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345,
"application/octet-stream", new Dictionary<string, string>());
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, string.Empty, new Dictionary<string, string>(), new List<StorageObject>() { obj });
}
@@ -820,7 +822,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, objectName, new Dictionary<string, string>(), (List<StorageObject>)null);
}
@@ -834,7 +836,7 @@ namespace OpenStack.Test.Storage
var obj = new StorageObject(objectName, containerName, DateTime.UtcNow, "12345", 12345,
"application/octet-stream", new Dictionary<string, string>());
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageManifest(containerName, objectName, null, new List<StorageObject>() { obj });
}
@@ -855,7 +857,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -876,7 +878,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -887,7 +889,7 @@ namespace OpenStack.Test.Storage
var containerName = "someContainer";
var folderName = "Test//Folder";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -897,7 +899,7 @@ namespace OpenStack.Test.Storage
{
var folderName = "TestFolder";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(null, folderName);
}
@@ -907,7 +909,7 @@ namespace OpenStack.Test.Storage
{
var folderName = "TestFolder";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(string.Empty, folderName);
}
@@ -917,7 +919,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(containerName, null);
}
@@ -927,7 +929,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageFolder(containerName, string.Empty);
}
@@ -944,7 +946,7 @@ namespace OpenStack.Test.Storage
return await Task.Run(()=>obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageContainer(containerName, new Dictionary<string, string>());
}
@@ -952,7 +954,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CreatingStorageContainersWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageContainer(null, new Dictionary<string, string>());
}
@@ -960,7 +962,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CreatingStorageContainersWithEmptyContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageContainer(string.Empty, new Dictionary<string, string>());
}
@@ -968,7 +970,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CreatingStorageContainersWithNullMetadataThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.CreateStorageContainer("TestContainer", null);
}
@@ -985,7 +987,7 @@ namespace OpenStack.Test.Storage
return Task.Factory.StartNew(() => obj);
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.GetStorageContainer(containerName);
Assert.AreEqual(obj, resp);
@@ -995,7 +997,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task GettingStorageContainersWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageContainer(null);
}
@@ -1003,7 +1005,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof (ArgumentException))]
public async Task GettingStorageContainersWithEmptyContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.GetStorageContainer(string.Empty);
}
@@ -1019,7 +1021,7 @@ namespace OpenStack.Test.Storage
await Task.Run(() => Assert.AreEqual(s.Name, obj.Name));
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.UpdateStorageContainer(obj);
}
@@ -1027,7 +1029,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task UpdatingStorageContainersWithNullContainerThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.UpdateStorageContainer(null);
}
@@ -1043,7 +1045,7 @@ namespace OpenStack.Test.Storage
await Task.Run(()=>Assert.AreEqual(s, obj.Name));
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageContainer(obj.Name);
}
@@ -1051,7 +1053,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task DeletingStorageContainersWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageContainer(null);
}
@@ -1059,7 +1061,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task DeletingStorageContainersWithEmptyContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageContainer(string.Empty);
}
@@ -1081,7 +1083,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageObject(obj.ContainerName,obj.Name);
}
@@ -1089,7 +1091,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task DeletingStorageObjectWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageObject(null,"TestObject");
}
@@ -1097,7 +1099,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task DeletingStorageObjectsWithEmptyContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageObject(string.Empty, "TestObject");
}
@@ -1105,7 +1107,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task DeletingStorageObjectWithNullObjectNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageObject("TestContainer", null);
}
@@ -1113,7 +1115,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task DeletingStorageObjectsWithEmptyObjectNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageObject("TestContainer", string.Empty);
}
@@ -1132,7 +1134,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1151,7 +1153,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1159,7 +1161,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task DeletingStorageFolderWithNullContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder(null, "TestFolder");
}
@@ -1167,7 +1169,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task DeletingStorageFolderWithEmptyContainerNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder(string.Empty, "TestFolder");
}
@@ -1175,7 +1177,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task DeletingStorageFolderWithNullObjectNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder("TestContainer", null);
}
@@ -1183,7 +1185,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task DeletingStorageFolderWithEmptyObjectNameThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DeleteStorageFolder("TestContainer", string.Empty);
}
@@ -1205,7 +1207,7 @@ namespace OpenStack.Test.Storage
});
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.UpdateStorageObject(obj);
}
@@ -1213,7 +1215,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task UpdatingStorageObjectWithNullContainerThrows()
{
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.UpdateStorageObject(null);
}
@@ -1239,7 +1241,7 @@ namespace OpenStack.Test.Storage
return obj;
};
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
var resp = await client.DownloadStorageObject(containerName, objectName, respStream);
respStream.Position = 0;
@@ -1253,7 +1255,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DownloadStorageObject(null, objectName, new MemoryStream());
}
@@ -1263,7 +1265,7 @@ namespace OpenStack.Test.Storage
{
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DownloadStorageObject(string.Empty, objectName, new MemoryStream());
}
@@ -1273,7 +1275,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DownloadStorageObject(containerName, null, new MemoryStream() );
}
@@ -1283,7 +1285,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DownloadStorageObject(containerName, string.Empty, new MemoryStream());
}
@@ -1294,7 +1296,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var objectName = "TestObject";
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None);
var client = new StorageServiceClient(GetValidCreds(), CancellationToken.None, this.ServiceLocator);
await client.DownloadStorageObject(containerName, objectName, null);
}
}

View File

@@ -22,7 +22,6 @@ using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
@@ -33,29 +32,26 @@ namespace OpenStack.Test.Storage
[TestClass]
public class StorageServicePocoClientTests
{
internal TestOpenStackServiceEndpointResolver resolver;
internal TestStorageServiceRestClient StorageServiceRestClient;
internal string authId = "12345";
internal Uri endpoint = new Uri("http://teststorageendpoint.com/v1/1234567890");
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.StorageServiceRestClient = new TestStorageServiceRestClient();
this.resolver = new TestOpenStackServiceEndpointResolver() { Endpoint = endpoint };
this.ServiceLocator = new ServiceLocator();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IStorageServiceRestClientFactory), new TestStorageServiceRestClientFactory(StorageServiceRestClient));
manager.RegisterServiceInstance(typeof(IOpenStackServiceEndpointResolver), this.resolver);
}
[TestCleanup]
public void TestCleanup()
{
this.resolver = new TestOpenStackServiceEndpointResolver() { Endpoint = endpoint };
this.StorageServiceRestClient = new TestStorageServiceRestClient();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
StorageServiceClientContext GetValidContext()
@@ -63,7 +59,7 @@ namespace OpenStack.Test.Storage
var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
creds.SetAccessTokenId(this.authId);
return new StorageServiceClientContext(creds, CancellationToken.None, "Object Storage");
return new StorageServiceClientContext(creds, CancellationToken.None, "Object Storage", endpoint);
}
#region Get Storage Container Tests
@@ -92,7 +88,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var result = await client.GetStorageContainer(containerName);
Assert.IsNotNull(result);
@@ -116,7 +112,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageContainer(containerName);
Assert.IsNotNull(result);
@@ -136,7 +132,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageContainer(containerName);
}
@@ -149,7 +145,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageContainer(containerName);
}
@@ -162,7 +158,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageContainer(containerName);
}
@@ -170,7 +166,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageContainerWithNullName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageContainer(null);
}
@@ -201,7 +197,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageAccount();
Assert.IsNotNull(result);
@@ -227,7 +223,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageAccount();
Assert.IsNotNull(result);
@@ -246,7 +242,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageAccount();
}
@@ -257,7 +253,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageAccount();
}
@@ -285,7 +281,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var respContent = new MemoryStream();
var result = await client.DownloadStorageObject(containerName, objectName, respContent);
@@ -310,7 +306,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject(containerName, objectName, new MemoryStream());
}
@@ -324,7 +320,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject(containerName, objectName, new MemoryStream());
}
@@ -338,7 +334,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject(containerName, objectName, new MemoryStream());
}
@@ -346,7 +342,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotDownloadStorageObjectWithNullContainerName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject(null, "object", new MemoryStream());
}
@@ -354,7 +350,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotDownloadStorageObjectWithNullObjectName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject("container", null, new MemoryStream());
}
@@ -362,7 +358,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotDownloadStorageObjectWithEmptyContainerName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject(string.Empty, "object", new MemoryStream());
}
@@ -370,7 +366,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotDownloadStorageObjectWithEmptyObjectName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject("container", string.Empty, new MemoryStream());
}
@@ -378,7 +374,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotDownloadStorageObjectWithnullOutputStream()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DownloadStorageObject("container", "object", null);
}
@@ -403,7 +399,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageObject(containerName, objectName);
Assert.IsNotNull(result);
@@ -448,7 +444,7 @@ namespace OpenStack.Test.Storage
this.StorageServiceRestClient.Responses.Enqueue(restResp);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageObject(containerName, objectName);
Assert.IsNotNull(result);
@@ -478,7 +474,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageObject(containerName, objectName);
Assert.IsNotNull(result);
@@ -508,7 +504,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetStorageObject(containerName, objectName);
Assert.IsNotNull(result);
@@ -533,7 +529,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject(containerName, objectName);
}
@@ -547,7 +543,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject(containerName, objectName);
}
@@ -561,7 +557,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject(containerName, objectName);
}
@@ -569,7 +565,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageObjectWithNullContainerName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject(null,"object");
}
@@ -577,7 +573,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageObjectWithNullObjectName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject("container", null);
}
@@ -585,7 +581,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageObjectWithEmptyContainerName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject(string.Empty, "object");
}
@@ -593,7 +589,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageObjectWithEmptyObjectName()
{
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageObject("container", string.Empty);
}
@@ -631,7 +627,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var result = await client.GetStorageManifest(containerName, manifestName);
Assert.IsNotNull(result);
@@ -664,7 +660,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var result = await client.GetStorageManifest(containerName, manifestName);
Assert.IsNotNull(result);
@@ -706,7 +702,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageManifest(containerName, manifestName);
}
@@ -720,7 +716,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageManifest(containerName, manifestName);
}
@@ -734,7 +730,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageManifest(containerName, manifestName);
}
@@ -748,7 +744,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageManifest(containerName, manifestName);
}
@@ -756,7 +752,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageManifestWithNullContainerName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageManifest(null, "a/b/c/manifest");
}
@@ -764,7 +760,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageManifestWithNullFolderName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageManifest("container", null);
}
@@ -772,7 +768,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageManifestWithEmptyContainerName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageManifest(string.Empty, "a/b/c/manifest");
}
@@ -780,7 +776,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageManifestWithEmptyFolderName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageManifest("container", string.Empty);
}
@@ -813,7 +809,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var result = await client.GetStorageFolder(containerName, folderName);
Assert.IsNotNull(result);
@@ -839,7 +835,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var result = await client.GetStorageFolder(containerName, folderName);
Assert.IsNotNull(result);
@@ -890,7 +886,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var resp = await client.GetStorageFolder(containerName, folderName);
Assert.AreEqual("c", resp.Name);
@@ -932,7 +928,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var resp = await client.GetStorageFolder(containerName, folderName);
}
@@ -946,7 +942,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageFolder(containerName, fodlerName);
}
@@ -960,7 +956,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageFolder(containerName, fodlerName);
}
@@ -974,7 +970,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetStorageFolder(containerName, fodlerName);
}
@@ -982,7 +978,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageFolderWithNullContainerName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageFolder(null, "a/b/c/");
}
@@ -990,7 +986,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotGetStorageFolderWithNullFolderName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageFolder("container", null);
}
@@ -998,7 +994,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageFolderWithEmptyContainerName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageFolder(string.Empty, "a/b/c/");
}
@@ -1006,7 +1002,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentException))]
public async Task CannotGetStorageFolderWithEmptyFolderName()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.GetStorageFolder("container", string.Empty);
}
@@ -1053,7 +1049,7 @@ namespace OpenStack.Test.Storage
this.StorageServiceRestClient.Responses.Enqueue(restResp1);
this.StorageServiceRestClient.Responses.Enqueue(restResp2);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new StaticLargeObjectManifest(containerName, manifestName,
new List<StorageObject>()
@@ -1100,7 +1096,7 @@ namespace OpenStack.Test.Storage
this.StorageServiceRestClient.Responses.Enqueue(restResp1);
this.StorageServiceRestClient.Responses.Enqueue(restResp2);
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new DynamicLargeObjectManifest(containerName, manifestName, segPath);
@@ -1122,7 +1118,7 @@ namespace OpenStack.Test.Storage
var containerName = "TestContainer";
var manifestName = "a/b/c/manifest";
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new TestStorageManifest(containerName, manifestName);
@@ -1135,7 +1131,7 @@ namespace OpenStack.Test.Storage
{
var manifestName = "a/b/c/manifest";
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new TestStorageManifest(null, manifestName);
@@ -1148,7 +1144,7 @@ namespace OpenStack.Test.Storage
{
var manifestName = "a/b/c/manifest";
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new TestStorageManifest(string.Empty, manifestName);
@@ -1161,7 +1157,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new TestStorageManifest(containerName, null);
@@ -1174,7 +1170,7 @@ namespace OpenStack.Test.Storage
{
var containerName = "TestContainer";
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
var manifest = new TestStorageManifest(containerName, string.Empty);
@@ -1185,7 +1181,7 @@ namespace OpenStack.Test.Storage
[ExpectedException(typeof(ArgumentNullException))]
public async Task CannotCreateManifestWithNullManifest()
{
var client = new StorageServicePocoClientFactory().Create(GetValidContext()) as StorageServicePocoClient;
var client = new StorageServicePocoClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServicePocoClient;
await client.CreateStorageManifest(null);
}
@@ -1203,7 +1199,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageManifest(manifest);
}
@@ -1220,7 +1216,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageManifest(manifest);
}
@@ -1248,7 +1244,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.Created);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.CreateStorageObject(objRequest, content);
Assert.IsNotNull(result);
@@ -1280,7 +1276,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.Created);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.CreateStorageObject(objRequest, content);
Assert.IsNotNull(result);
@@ -1305,7 +1301,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.LengthRequired);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageObject(objRequest, content);
}
@@ -1322,7 +1318,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), (HttpStatusCode)422);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageObject(objRequest, content);
}
@@ -1339,7 +1335,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageObject(objRequest, content);
}
@@ -1356,7 +1352,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageObject(objRequest, content);
}
@@ -1373,7 +1369,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.RequestTimeout);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageObject(objRequest, content);
}
@@ -1398,7 +1394,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.Created);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1420,7 +1416,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), headers, HttpStatusCode.LengthRequired);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1434,7 +1430,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), (HttpStatusCode)422);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1448,7 +1444,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1462,7 +1458,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1476,7 +1472,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.RequestTimeout);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageFolder(containerName, folderName);
}
@@ -1500,7 +1496,7 @@ namespace OpenStack.Test.Storage
var containerReq = new StorageContainer(containerName, new Dictionary<string, string>());
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageContainer(containerReq);
//Assert.IsNotNull(container);
@@ -1524,7 +1520,7 @@ namespace OpenStack.Test.Storage
var containerReq = new StorageContainer(containerName, new Dictionary<string, string>());
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageContainer(containerReq);
//Assert.IsNotNull(container);
@@ -1543,7 +1539,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageContainer(containerReq);
}
@@ -1558,7 +1554,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.CreateStorageContainer(containerReq);
}
@@ -1574,7 +1570,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageContainer(containerName);
}
@@ -1586,7 +1582,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageContainer(containerName);
}
@@ -1599,7 +1595,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Conflict);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageContainer(containerName);
}
@@ -1612,7 +1608,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageContainer(containerName);
}
@@ -1625,7 +1621,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageContainer(containerName);
}
@@ -1642,7 +1638,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageObject(containerName, objectName);
}
@@ -1655,7 +1651,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageObject(containerName, objectName);
}
@@ -1669,7 +1665,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageObject(containerName, objectName);
}
@@ -1683,7 +1679,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageObject(containerName, objectName);
}
@@ -1701,7 +1697,7 @@ namespace OpenStack.Test.Storage
this.StorageServiceRestClient.Responses.Enqueue(restResp);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1715,7 +1711,7 @@ namespace OpenStack.Test.Storage
this.StorageServiceRestClient.Responses.Enqueue(restResp);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1745,7 +1741,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(content, headers, HttpStatusCode.OK);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1759,7 +1755,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1773,7 +1769,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.DeleteStorageFolder(containerName, folderName);
}
@@ -1790,7 +1786,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageContainer(containerReq);
}
@@ -1804,7 +1800,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageContainer(containerReq);
}
@@ -1818,7 +1814,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageContainer(containerReq);
}
@@ -1837,7 +1833,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Accepted);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageObject(objectReq);
}
@@ -1853,7 +1849,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageObject(objectReq);
}
@@ -1869,7 +1865,7 @@ namespace OpenStack.Test.Storage
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.StorageServiceRestClient.Responses.Enqueue(restResp);
var client = new StorageServicePocoClient(GetValidContext());
var client = new StorageServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.UpdateStorageObject(objectReq);
}

View File

@@ -23,7 +23,6 @@ using System.Security.Cryptography;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
@@ -34,29 +33,26 @@ namespace OpenStack.Test.Storage
[TestClass]
public class StorageServiceRestClientTests
{
internal TestOpenStackServiceEndpointResolver resolver;
internal StorageRestSimulator simulator;
internal string authId = "12345";
internal Uri endpoint = new Uri("http://teststorageendpoint.com/v1/1234567890");
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.resolver = new TestOpenStackServiceEndpointResolver() { Endpoint = endpoint };
this.simulator = new StorageRestSimulator();
this.ServiceLocator = new ServiceLocator();
ServiceLocator.Reset();
var manager = ServiceLocator.Instance.Locate<IServiceLocationOverrideManager>();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IHttpAbstractionClientFactory), new StorageRestSimulatorFactory(simulator));
manager.RegisterServiceInstance(typeof(IOpenStackServiceEndpointResolver), this.resolver);
}
[TestCleanup]
public void TestCleanup()
{
this.resolver = new TestOpenStackServiceEndpointResolver() { Endpoint = endpoint };
this.simulator = new StorageRestSimulator();
ServiceLocator.Reset();
this.ServiceLocator = new ServiceLocator();
}
StorageServiceClientContext GetValidContext()
@@ -69,7 +65,7 @@ namespace OpenStack.Test.Storage
var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
creds.SetAccessTokenId(this.authId);
return new StorageServiceClientContext(creds, token, "Object Storage");
return new StorageServiceClientContext(creds, token, "Object Storage", endpoint);
}
#region CreateManifest Tests
@@ -81,7 +77,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -98,7 +94,7 @@ namespace OpenStack.Test.Storage
var segPath = "blah/blah";
var containerName = "newContainer";
var client = new StorageServiceRestClient(GetValidContext());
var client = new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateDynamicManifest(containerName, manifestName, new Dictionary<string, string>(), segPath);
@@ -113,7 +109,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -130,7 +126,7 @@ namespace OpenStack.Test.Storage
var segPath = "blah/blah";
var containerName = "newContainer";
var client = new StorageServiceRestClient(GetValidContext());
var client = new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateDynamicManifest(containerName, manifestName, new Dictionary<string, string>(), segPath);
@@ -152,7 +148,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client = new StorageServiceRestClientFactory().Create(GetValidContext()) as StorageServiceRestClient;
var client = new StorageServiceRestClientFactory().Create(GetValidContext(), this.ServiceLocator) as StorageServiceRestClient;
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -170,7 +166,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -187,7 +183,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -207,7 +203,7 @@ namespace OpenStack.Test.Storage
var objectName = "NewObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -236,7 +232,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
var hash = Convert.ToBase64String(MD5.Create().ComputeHash(content));
@@ -262,7 +258,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -289,7 +285,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -311,7 +307,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -333,7 +329,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -355,7 +351,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CreateObject(containerName, objectName, new Dictionary<string, string>(), null);
@@ -371,7 +367,7 @@ namespace OpenStack.Test.Storage
var containerName = "new/Container";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateObject(containerName, objectName, new Dictionary<string, string>(), null);
}
@@ -386,7 +382,7 @@ namespace OpenStack.Test.Storage
var context = GetValidContext();
context.Credential.SetAccessTokenId(authId);
var client =
new StorageServiceRestClient(context);
new StorageServiceRestClient(context, this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -406,7 +402,7 @@ namespace OpenStack.Test.Storage
this.simulator.Delay = TimeSpan.FromMilliseconds(500);
var client =
new StorageServiceRestClient(GetValidContext(token));
new StorageServiceRestClient(GetValidContext(token), this.ServiceLocator);
var data = "Some random data";
var content = TestHelper.CreateStream(data);
@@ -431,7 +427,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateContainer(containerName, new Dictionary<string, string>());
@@ -445,7 +441,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateContainer(containerName, new Dictionary<string, string>());
@@ -459,7 +455,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CreateContainer(containerName, new Dictionary<string, string>());
@@ -474,7 +470,7 @@ namespace OpenStack.Test.Storage
var containerName = "new/Container";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CreateContainer(containerName, new Dictionary<string, string>());
}
@@ -485,7 +481,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metaData = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -506,7 +502,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CreateContainer(containerName, new Dictionary<string, string>());
@@ -532,7 +528,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetContainer(containerName);
@@ -546,7 +542,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetContainer(containerName);
@@ -560,7 +556,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetContainer(containerName);
@@ -577,7 +573,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(containerName, new StorageRestSimulator.StorageItem(containerName));
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetContainer(containerName);
@@ -596,7 +592,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(containerName, new StorageRestSimulator.StorageItem(containerName) { MetaData = metaData});
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetContainer(containerName);
@@ -618,7 +614,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetObject(containerName, objectName);
@@ -633,7 +629,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetObject(containerName, objectName);
@@ -648,7 +644,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetObject(containerName, objectName);
@@ -669,7 +665,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(objectName, new StorageRestSimulator.StorageItem(objectName) { Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetObject(containerName, objectName);
@@ -696,7 +692,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(objectName, new StorageRestSimulator.StorageItem(objectName) { MetaData = metaData, Content = content});
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetObject(containerName, objectName);
@@ -720,7 +716,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.DeleteObject(containerName, objectName);
@@ -735,7 +731,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.DeleteObject(containerName, objectName);
@@ -750,7 +746,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.DeleteObject(containerName, objectName);
@@ -769,7 +765,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(objectName, new StorageRestSimulator.StorageItem(objectName) {Content = content});
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.DeleteObject(containerName, objectName);
@@ -787,7 +783,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.DeleteContainer(containerName);
@@ -801,7 +797,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.DeleteContainer(containerName);
@@ -815,7 +811,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.DeleteContainer(containerName);
@@ -831,7 +827,7 @@ namespace OpenStack.Test.Storage
this.simulator.IsContainerEmpty = false;
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.DeleteContainer(containerName);
@@ -847,7 +843,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(containerName, new StorageRestSimulator.StorageItem(containerName));
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.DeleteContainer(containerName);
@@ -866,7 +862,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -883,7 +879,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -900,7 +896,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -919,7 +915,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(objectName, new StorageRestSimulator.StorageItem(objectName) { MetaData = origMetaData });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test2", "Test2" } };
@@ -942,7 +938,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -958,7 +954,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -974,7 +970,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test1", "Test1" }, { "Test2", "Test2" } };
@@ -992,7 +988,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(containerName, new StorageRestSimulator.StorageItem(containerName) { MetaData = origMetaData });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var metadata = new Dictionary<string, string> { { "Test2", "Test2" } };
@@ -1015,7 +1011,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetContainerMetadata(containerName);
@@ -1029,7 +1025,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetContainerMetadata(containerName);
@@ -1043,7 +1039,7 @@ namespace OpenStack.Test.Storage
var containerName = "newContainer";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetContainerMetadata(containerName);
@@ -1060,7 +1056,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(containerName, new StorageRestSimulator.StorageItem(containerName) { MetaData = origMetaData });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetContainerMetadata(containerName);
@@ -1081,7 +1077,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetObjectMetadata(containerName, objectName);
@@ -1096,7 +1092,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetObjectMetadata(containerName, objectName);
@@ -1111,7 +1107,7 @@ namespace OpenStack.Test.Storage
var objectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetObjectMetadata(containerName, objectName);
@@ -1130,7 +1126,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(objectName, new StorageRestSimulator.StorageItem(objectName) { MetaData = origMetaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetObjectMetadata(containerName, objectName);
@@ -1153,7 +1149,7 @@ namespace OpenStack.Test.Storage
var targetObjectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1170,7 +1166,7 @@ namespace OpenStack.Test.Storage
var targetObjectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1187,7 +1183,7 @@ namespace OpenStack.Test.Storage
var targetObjectName = "newObject";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1207,7 +1203,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(targetContainerName, new StorageRestSimulator.StorageItem(targetContainerName));
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1229,7 +1225,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(sourceObjectName, new StorageRestSimulator.StorageItem(sourceObjectName) { MetaData = origMetaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1251,7 +1247,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(sourceObjectName, new StorageRestSimulator.StorageItem(sourceObjectName) { MetaData = origMetaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1272,7 +1268,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add(sourceContainerName, new StorageRestSimulator.StorageItem(sourceContainerName));
this.simulator.Objects.Add(sourceObjectName, new StorageRestSimulator.StorageItem(sourceObjectName) { MetaData = origMetaData, Content = content });
var client = new StorageServiceRestClient(GetValidContext());
var client = new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1296,7 +1292,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(sourceObjectName, new StorageRestSimulator.StorageItem(sourceObjectName) { MetaData = origMetaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.CopyObject(sourceContainerName, sourceObjectName, targetContainerName, targetObjectName);
@@ -1317,7 +1313,7 @@ namespace OpenStack.Test.Storage
public async Task GetStorageAccountIncludesAuthHeader()
{
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetAccount();
@@ -1329,7 +1325,7 @@ namespace OpenStack.Test.Storage
public async Task GetStorageAccountFormsCorrectUrlAndMethod()
{
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetAccount();
@@ -1343,7 +1339,7 @@ namespace OpenStack.Test.Storage
this.simulator.Containers.Add("TestContainer", new StorageRestSimulator.StorageItem("TestContainer"));
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetAccount();
@@ -1368,7 +1364,7 @@ namespace OpenStack.Test.Storage
var folderName = "newFolder";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetFolder(containerName, folderName);
@@ -1383,7 +1379,7 @@ namespace OpenStack.Test.Storage
var folderName = "a/b/b/";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetFolder(containerName, folderName);
@@ -1398,7 +1394,7 @@ namespace OpenStack.Test.Storage
var folderName = "/";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetFolder(containerName, folderName);
@@ -1413,7 +1409,7 @@ namespace OpenStack.Test.Storage
var folderName = "a/b/b/";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetFolder(containerName, folderName);
@@ -1432,7 +1428,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(folderName, new StorageRestSimulator.StorageItem(folderName) { Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetFolder(containerName, folderName);
@@ -1453,7 +1449,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(folderName, new StorageRestSimulator.StorageItem(folderName) { MetaData = metaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetFolder(containerName, folderName);
@@ -1474,7 +1470,7 @@ namespace OpenStack.Test.Storage
var manifestName = "newManifest";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetManifestMetadata(containerName, manifestName);
@@ -1489,7 +1485,7 @@ namespace OpenStack.Test.Storage
var manifestName = "a/b/b/manifest";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetManifestMetadata(containerName, manifestName);
@@ -1504,7 +1500,7 @@ namespace OpenStack.Test.Storage
var manifestName = "a/b/b/manifest";
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetManifestMetadata(containerName, manifestName);
@@ -1523,7 +1519,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(manifestName, new StorageRestSimulator.StorageItem(manifestName) { Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetManifestMetadata(containerName, manifestName);
@@ -1544,7 +1540,7 @@ namespace OpenStack.Test.Storage
this.simulator.Objects.Add(manifestName, new StorageRestSimulator.StorageItem(manifestName) { MetaData = metaData, Content = content });
var client =
new StorageServiceRestClient(GetValidContext());
new StorageServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetManifestMetadata(containerName, manifestName);

View File

@@ -17,6 +17,7 @@
using System;
using System.IO;
using System.Threading.Tasks;
using OpenStack.Common.ServiceLocation;
using OpenStack.Storage;
namespace OpenStack.Test.Storage
@@ -138,7 +139,7 @@ namespace OpenStack.Test.Storage
this.client = client;
}
public IStorageServicePocoClient Create(StorageServiceClientContext context)
public IStorageServicePocoClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
return client;
}

View File

@@ -18,6 +18,7 @@ using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Storage;
namespace OpenStack.Test.Storage
@@ -126,7 +127,7 @@ namespace OpenStack.Test.Storage
this.Client = client;
}
public IStorageServiceRestClient Create(StorageServiceClientContext context)
public IStorageServiceRestClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
return Client;
}

View File

@@ -25,24 +25,12 @@ namespace OpenStack.Common.ServiceLocation
/// <inheritdoc/>
public class ServiceLocator : IServiceLocator
{
private static IServiceLocator _instance = new ServiceLocator();
private readonly ServiceLocationManager _runtimeManager;
private readonly Dictionary<Type, object> _services = new Dictionary<Type, object>();
private readonly Dictionary<Type, object> _overrideServices = new Dictionary<Type, object>();
private readonly IServiceLocationAssemblyScanner _scanner = new ServiceLocationAssemblyScanner();
public static IServiceLocator Instance
{
get { return _instance; }
}
internal static void Reset()
{
_instance = new ServiceLocator();
}
private ServiceLocator()
internal ServiceLocator()
{
this._runtimeManager = new ServiceLocationRuntimeManager(this);
this._services.Add(typeof(IServiceLocationRuntimeManager), this._runtimeManager);

View File

@@ -16,6 +16,7 @@
using System;
using System.Collections.Generic;
using System.Threading;
using OpenStack.Identity;
namespace OpenStack
@@ -40,6 +41,39 @@ namespace OpenStack
/// <returns>An instance of an OpenStack client.</returns>
IOpenStackClient CreateClient(ICredential credential, string version);
/// <summary>
/// Creates an instance of a client that can support the given credential and version.
/// </summary>
/// <param name="credential">The credential that must be supported.</param>
/// <param name="token">A cancellation token that can be used to cancel operations.</param>
/// <param name="version">The version that must be supported.</param>
/// <returns>An instance of an OpenStack client.</returns>
IOpenStackClient CreateClient(ICredential credential, CancellationToken token, string version);
/// <summary>
/// Creates an instance of a client that can support the given credential and version.
/// </summary>
/// <param name="credential">The credential that must be supported.</param>
/// <returns>An instance of an OpenStack client.</returns>
IOpenStackClient CreateClient<T>(ICredential credential) where T : IOpenStackClient;
/// <summary>
/// Creates an instance of a client that can support the given credential and version.
/// </summary>
/// <param name="credential">The credential that must be supported.</param>
/// <param name="version">The version that must be supported.</param>
/// <returns>An instance of an OpenStack client.</returns>
IOpenStackClient CreateClient<T>(ICredential credential, string version) where T : IOpenStackClient;
/// <summary>
/// Creates an instance of a client that can support the given credential and version.
/// </summary>
/// <param name="credential">The credential that must be supported.</param>
/// <param name="token">A cancellation token that can be used to cancel operations.</param>
/// <param name="version">The version that must be supported.</param>
/// <returns>An instance of an OpenStack client.</returns>
IOpenStackClient CreateClient<T>(ICredential credential, CancellationToken token, string version) where T : IOpenStackClient;
/// <summary>
/// Registers a client for use.
/// </summary>

View File

@@ -16,6 +16,7 @@
using System.Collections.Generic;
using System.Threading;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack
@@ -32,8 +33,9 @@ namespace OpenStack
/// </summary>
/// <param name="credential">The credential that the client will use.</param>
/// <param name="cancellationToken">The cancellation token that the client will use.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns></returns>
IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken);
IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator);
/// <summary>
/// Gets a list of supported versions.

View File

@@ -15,6 +15,7 @@
// ============================================================================ */
using System.Threading;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
{
@@ -28,7 +29,8 @@ namespace OpenStack.Identity
/// </summary>
/// <param name="credentials">The credential to be used when interacting with OpenStack.</param>
/// <param name="token">The cancellation token to be used when interacting with OpenStack.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>An instance of the client.</returns>
IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token);
IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator);
}
}

View File

@@ -15,6 +15,7 @@
// ============================================================================ */
using System.Threading;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
{
@@ -28,7 +29,8 @@ namespace OpenStack.Identity
/// </summary>
/// <param name="credential">The credential to be used when interacting with OpenStack.</param>
/// <param name="cancellationToken">The cancellation token to be used when interacting with OpenStack.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>An instance of the client.</returns>
IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken);
IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator);
}
}

View File

@@ -24,14 +24,6 @@ namespace OpenStack.Identity
/// </summary>
internal interface IOpenStackServiceCatalog : IEnumerable<OpenStackServiceDefinition>
{
/// <summary>
/// Gets the public endpoint for the given service and region.
/// </summary>
/// <param name="serviceName">The name of the service.</param>
/// <param name="region">The region of the endpoint.</param>
/// <returns>A Uri that represents the public endpoint for the given service in the given region.</returns>
Uri GetPublicEndpoint(string serviceName, string region);
/// <summary>
/// Determines if the given service exists in the catalog.
/// </summary>

View File

@@ -16,6 +16,7 @@
using System.Threading;
using System.Threading.Tasks;
using OpenStack.Common;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
@@ -25,14 +26,18 @@ namespace OpenStack.Identity
{
internal IOpenStackCredential Credential;
internal CancellationToken CancellationToken;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the IdentityServiceClient class.
/// </summary>
/// <param name="credential"></param>
/// <param name="cancellationToken"></param>
internal IdentityServiceClient(IOpenStackCredential credential, CancellationToken cancellationToken)
/// <param name="credential">The credential to be used by the client.</param>
/// <param name="cancellationToken">A cancellation token to be used when completing requests.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
internal IdentityServiceClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service client with a null service locator.");
this.ServiceLocator = serviceLocator;
this.Credential = credential;
this.CancellationToken = cancellationToken;
}
@@ -40,7 +45,7 @@ namespace OpenStack.Identity
/// <inheritdoc/>
public async Task<IOpenStackCredential> Authenticate()
{
var client = ServiceLocator.Instance.Locate<IIdentityServicePocoClientFactory>().Create(this.Credential, this.CancellationToken);
var client = this.ServiceLocator.Locate<IIdentityServicePocoClientFactory>().Create(this.Credential, this.CancellationToken, this.ServiceLocator);
this.Credential = await client.Authenticate();
return this.Credential;
}

View File

@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
{
@@ -36,9 +37,9 @@ namespace OpenStack.Identity
}
/// <inheritdoc/>
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken)
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
return new IdentityServiceClient((IOpenStackCredential)credential, cancellationToken);
return new IdentityServiceClient((IOpenStackCredential)credential, cancellationToken, serviceLocator);
}
/// <inheritdoc/>

View File

@@ -29,25 +29,29 @@ namespace OpenStack.Identity
internal IOpenStackCredential credential;
internal CancellationToken cancellationToken;
internal const string IdentityServiceName = "Identity";
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the IdentityServicePocoClient class.
/// </summary>
/// <param name="credential">The credential to be used when interacting with OpenStack.</param>
/// <param name="cancellationToken">The cancellation token to be used when interacting with OpenStack.</param>
public IdentityServicePocoClient(IOpenStackCredential credential, CancellationToken cancellationToken)
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public IdentityServicePocoClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
credential.AssertIsNotNull("credential");
cancellationToken.AssertIsNotNull("cancellationToken");
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service poco client with a null service locator.");
this.credential = credential;
this.cancellationToken = cancellationToken;
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public async Task<IOpenStackCredential> Authenticate()
{
var client = ServiceLocator.Instance.Locate<IIdentityServiceRestClientFactory>().Create(this.credential, this.cancellationToken);
var client = this.ServiceLocator.Locate<IIdentityServiceRestClientFactory>().Create(this.credential, this.cancellationToken, this.ServiceLocator);
var resp = await client.Authenticate();
@@ -58,10 +62,10 @@ namespace OpenStack.Identity
var payload = await resp.ReadContentAsStringAsync();
var tokenConverter = ServiceLocator.Instance.Locate<IAccessTokenPayloadConverter>();
var tokenConverter = this.ServiceLocator.Locate<IAccessTokenPayloadConverter>();
var accessToken = tokenConverter.Convert(payload);
var scConverter = ServiceLocator.Instance.Locate<IOpenStackServiceCatalogPayloadConverter>();
var scConverter = this.ServiceLocator.Locate<IOpenStackServiceCatalogPayloadConverter>();
var serviceCatalog = scConverter.Convert(payload);
this.credential.SetAccessTokenId(accessToken);
@@ -69,11 +73,10 @@ namespace OpenStack.Identity
if (string.IsNullOrEmpty(this.credential.Region))
{
var resolver = ServiceLocator.Instance.Locate<IOpenStackRegionResolver>();
var resolver = this.ServiceLocator.Locate<IOpenStackRegionResolver>();
var region = resolver.Resolve(this.credential.AuthenticationEndpoint, this.credential.ServiceCatalog, IdentityServiceName);
//TODO: figure out if we want to throw in the case where the region cannot be resolved...
this.credential.SetRegion(region);
}

View File

@@ -15,6 +15,7 @@
// ============================================================================ */
using System.Threading;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
{
@@ -22,9 +23,9 @@ namespace OpenStack.Identity
internal class IdentityServicePocoClientFactory :IIdentityServicePocoClientFactory
{
/// <inheritdoc/>
public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token)
public IIdentityServicePocoClient Create(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator)
{
return new IdentityServicePocoClient(credentials, token);
return new IdentityServicePocoClient(credentials, token, serviceLocator);
}
}
}

View File

@@ -27,33 +27,37 @@ namespace OpenStack.Identity
/// <inheritdoc/>
internal class IdentityServiceRestClient : IIdentityServiceRestClient
{
internal IOpenStackCredential credential;
internal CancellationToken cancellationToken;
internal IOpenStackCredential Credential;
internal CancellationToken CancellationToken;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the IdentityServiceRestClient class.
/// </summary>
/// <param name="credential">The credential to be used by this client.</param>
/// <param name="cancellationToken">The cancellation token to be used by this client.</param>
public IdentityServiceRestClient(IOpenStackCredential credential, CancellationToken cancellationToken)
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public IdentityServiceRestClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
credential.AssertIsNotNull("credential");
cancellationToken.AssertIsNotNull("cancellationToken");
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an identity service rest client with a null service locator.");
this.credential = credential;
this.cancellationToken = cancellationToken;
this.Credential = credential;
this.CancellationToken = cancellationToken;
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public async Task<IHttpResponseAbstraction> Authenticate()
{
var client = ServiceLocator.Instance.Locate<IHttpAbstractionClientFactory>().Create(this.cancellationToken);
var client = this.ServiceLocator.Locate<IHttpAbstractionClientFactory>().Create(this.CancellationToken);
client.Headers.Add("Accept", "application/json");
client.ContentType = "application/json";
client.Uri = this.credential.AuthenticationEndpoint;
client.Uri = this.Credential.AuthenticationEndpoint;
client.Method = HttpMethod.Post;
client.Content = CreateAuthenticationJsonPayload(this.credential).ConvertToStream();
client.Content = CreateAuthenticationJsonPayload(this.Credential).ConvertToStream();
return await client.SendAsync();
}

View File

@@ -15,6 +15,7 @@
// ============================================================================ */
using System.Threading;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Identity
{
@@ -22,9 +23,9 @@ namespace OpenStack.Identity
internal class IdentityServiceRestClientFactory : IIdentityServiceRestClientFactory
{
/// <inheritdoc/>
public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken)
public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
return new IdentityServiceRestClient(credential, cancellationToken);
return new IdentityServiceRestClient(credential, cancellationToken, serviceLocator);
}
}
}

View File

@@ -24,13 +24,6 @@ namespace OpenStack.Identity
/// <inheritdoc/>
public class OpenStackServiceCatalog : List<OpenStackServiceDefinition>, IOpenStackServiceCatalog
{
/// <inheritdoc/>
public Uri GetPublicEndpoint(string serviceName, string region)
{
var resolver = ServiceLocator.Instance.Locate<IOpenStackServiceEndpointResolver>();
return new Uri(resolver.ResolveEndpoint(this, serviceName, region));
}
/// <inheritdoc/>
public bool Exists(string serviceName)
{

View File

@@ -25,6 +25,18 @@ namespace OpenStack.Identity
/// <inheritdoc/>
internal class OpenStackServiceCatalogPayloadConverter : IOpenStackServiceCatalogPayloadConverter
{
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the OpenStackServiceCatalogPayloadConverter class.
/// </summary>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public OpenStackServiceCatalogPayloadConverter(IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a service catalog payload converter with a null service locator.");
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public OpenStackServiceCatalog Convert(string payload)
{
@@ -62,7 +74,7 @@ namespace OpenStack.Identity
/// <returns>The service definition.</returns>
internal OpenStackServiceDefinition ConvertServiceDefinition(JToken serviceDef)
{
var converter = ServiceLocator.Instance.Locate<IOpenStackServiceDefinitionPayloadConverter>();
var converter = this.ServiceLocator.Locate<IOpenStackServiceDefinitionPayloadConverter>();
return converter.Convert(serviceDef.ToString());
}
}

View File

@@ -26,6 +26,18 @@ namespace OpenStack.Identity
/// <inheritdoc/>
internal class OpenStackServiceDefinitionPayloadConverter : IOpenStackServiceDefinitionPayloadConverter
{
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the OpenStackServiceDefinitionPayloadConverter class.
/// </summary>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public OpenStackServiceDefinitionPayloadConverter(IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a service definition payload converter with a null service locator.");
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public OpenStackServiceDefinition Convert(string payload)
{
@@ -55,7 +67,7 @@ namespace OpenStack.Identity
/// <returns>A service endpoint.</returns>
internal OpenStackServiceEndpoint ConvertEndpoint(JToken endpoint)
{
var converter = ServiceLocator.Instance.Locate<IOpenStackServiceEndpointPayloadConverter>();
var converter = this.ServiceLocator.Locate<IOpenStackServiceEndpointPayloadConverter>();
return converter.Convert(endpoint.ToString());
}
}

View File

@@ -95,9 +95,13 @@
<Compile Include="IOpenStackServiceClientDefinition.cs" />
<Compile Include="IOpenStackServiceClientManager.cs" />
<Compile Include="OpenStackClient.cs" />
<Compile Include="OpenStackClientFactory.cs" />
<Compile Include="OpenStackClientManager.cs" />
<Compile Include="OpenStackServiceClientManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\AssemblyVersionInfo.cs">
<Link>Properties\AssemblyVersionInfo.cs</Link>
</Compile>
<Compile Include="ServiceRegistrar.cs" />
<Compile Include="Storage\ContainerNameValidator.cs" />
<Compile Include="Storage\DynamicLargeObjectManifest.cs" />
@@ -123,7 +127,6 @@
<Compile Include="Storage\StorageFolder.cs" />
<Compile Include="Storage\StorageFolderPayloadConverter.cs" />
<Compile Include="Storage\StorageItem.cs" />
<Compile Include="Storage\StorageItemNameExtractor.cs" />
<Compile Include="Storage\StorageManifest.cs" />
<Compile Include="Storage\StorageObject.cs" />
<Compile Include="Storage\StorageObjectPayloadConverter.cs" />

View File

@@ -26,17 +26,15 @@ namespace OpenStack
/// <inheritdoc/>
public class OpenStackClient : IOpenStackClient
{
internal CancellationToken cancellationToken;
internal CancellationToken CancellationToken;
internal IServiceLocator ServiceLocator;
/// <inheritdoc/>
public IOpenStackCredential Credential { get; private set; }
/// <summary>
/// Creates a new instance of the OpenStackClient class.
/// </summary>
public OpenStackClient()
internal OpenStackClient()
{
//TODO: remove the need for a default constructor, as state becomes an issue. This will need to be done in conjunction with changes in the ClientManager
}
/// <summary>
@@ -44,10 +42,14 @@ namespace OpenStack
/// </summary>
/// <param name="credential">The credential to be used by this client.</param>
/// <param name="cancellationToken">The cancellation token to be used by this client.</param>
public OpenStackClient(IOpenStackCredential credential, CancellationToken cancellationToken)
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public OpenStackClient(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create an OpenStack client with a null service locator.");
this.Credential = credential;
this.cancellationToken = cancellationToken;
this.CancellationToken = cancellationToken;
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
@@ -73,8 +75,8 @@ namespace OpenStack
/// <inheritdoc/>
public T CreateServiceClient<T>(string version) where T : IOpenStackServiceClient
{
var manager = ServiceLocator.Instance.Locate<IOpenStackServiceClientManager>();
return manager.CreateServiceClient<T>(this.Credential, this.cancellationToken);
var manager = this.ServiceLocator.Locate<IOpenStackServiceClientManager>();
return manager.CreateServiceClient<T>(this.Credential, this.CancellationToken);
}
/// <inheritdoc/>

View File

@@ -0,0 +1,106 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Threading;
using OpenStack.Common;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack
{
/// <summary>
/// Factory class for creating OpenStack clients.
/// </summary>
public static class OpenStackClientFactory
{
/// <summary>
/// Creates an OpenStack client that supports the given credential.
/// </summary>
/// <param name="credential">A credential to be used by the client.</param>
/// <returns>A OpenStack client.</returns>
public static IOpenStackClient CreateClient(IOpenStackCredential credential)
{
return CreateClient(credential, CancellationToken.None, string.Empty);
}
/// <summary>
/// Creates an OpenStack client that supports the given credential.
/// </summary>
/// <param name="credential">A credential to be used by the client.</param>
/// <param name="version">A version that the client must support.</param>
/// <returns>A OpenStack client.</returns>
public static IOpenStackClient CreateClient(IOpenStackCredential credential, string version)
{
return CreateClient(credential, CancellationToken.None, version);
}
/// <summary>
/// Creates an OpenStack client that supports the given credential and version.
/// </summary>
/// <param name="credential">A credential to be used by the client.</param>
/// <param name="version">A version that the client must support.</param>
/// <param name="token">A cancellation token to be used to cancel operations.</param>
/// <returns>An OpenStack client.</returns>
public static IOpenStackClient CreateClient(IOpenStackCredential credential, CancellationToken token, string version)
{
credential.AssertIsNotNull("credential", "Cannot create a client with a null credential.");
var locator = new ServiceLocator();
var clientManager = locator.Locate<IOpenStackClientManager>();
return clientManager.CreateClient(credential, token, version);
}
/// <summary>
/// Creates a client of the requested type that supports the given credential.
/// </summary>
/// <typeparam name="T">The type of client to create.</typeparam>
/// <param name="credential">A credential to be used by the client.</param>
/// <returns>An OpenStack client.</returns>
public static IOpenStackClient CreateClient<T>(IOpenStackCredential credential) where T : IOpenStackClient
{
return CreateClient<T>(credential, CancellationToken.None, string.Empty);
}
/// <summary>
/// Creates a client of the requested type that supports the given credential.
/// </summary>
/// <typeparam name="T">The type of client to create.</typeparam>
/// <param name="credential">A credential to be used by the client.</param>
/// <param name="version">A version that the client must support.</param>
/// <returns>An OpenStack client.</returns>
public static IOpenStackClient CreateClient<T>(IOpenStackCredential credential, string version) where T : IOpenStackClient
{
return CreateClient<T>(credential, CancellationToken.None, version);
}
/// <summary>
/// Creates a client of the requested type that supports the given credential and version.
/// </summary>
/// <typeparam name="T">The type of client to create.</typeparam>
/// <param name="credential">A credential to be used by the client.</param>
/// <param name="version">A version that the client must support.</param>
/// <param name="token">A cancellation token to be used to cancel operations.</param>
/// <returns>An OpenStack client.</returns>
public static IOpenStackClient CreateClient<T>(IOpenStackCredential credential, CancellationToken token, string version) where T : IOpenStackClient
{
credential.AssertIsNotNull("credential", "Cannot create a client with a null credential.");
var locator = new ServiceLocator();
var clientManager = locator.Locate<IOpenStackClientManager>();
return clientManager.CreateClient<T>(credential, token, version);
}
}
}

View File

@@ -17,7 +17,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Reflection;
using System.Threading;
using OpenStack.Common;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack
@@ -25,13 +29,15 @@ namespace OpenStack
/// <inheritdoc/>
internal class OpenStackClientManager : IOpenStackClientManager
{
internal IServiceLocator ServiceLocator;
internal ICollection<Type> clients;
/// <summary>
/// Creates a new instance of the OpenStackClientManager class.
/// </summary>
internal OpenStackClientManager()
internal OpenStackClientManager(IServiceLocator serviceLocator)
{
this.ServiceLocator = serviceLocator;
this.clients = new Collection<Type>();
}
@@ -44,12 +50,59 @@ namespace OpenStack
/// <inheritdoc/>
public IOpenStackClient CreateClient(ICredential credential, string version)
{
credential.AssertIsNotNull("credential","Cannot create an OpenStack client with a null credential.");
return this.CreateClient(credential, CancellationToken.None, version);
}
/// <inheritdoc/>
public IOpenStackClient CreateClient(ICredential credential, CancellationToken token, string version)
{
credential.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null credential.");
version.AssertIsNotNull("version", "Cannot create an OpenStack client with a null version.");
foreach (var clientType in this.clients)
//Ensure that the assembly that contains the credential has a chance to register itself.
this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetTypeInfo().Assembly);
return this.GetSupportedClient(this.clients, credential, token, version);
}
/// <inheritdoc/>
public IOpenStackClient CreateClient<T>(ICredential credential) where T : IOpenStackClient
{
return this.CreateClient<T>(credential, CancellationToken.None, string.Empty);
}
/// <inheritdoc/>
public IOpenStackClient CreateClient<T>(ICredential credential, string version) where T : IOpenStackClient
{
return this.CreateClient<T>(credential, CancellationToken.None, version);
}
/// <inheritdoc/>
public IOpenStackClient CreateClient<T>(ICredential credential, CancellationToken token, string version) where T: IOpenStackClient
{
credential.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null credential.");
version.AssertIsNotNull("version", "Cannot create an OpenStack client with a null version.");
//Ensure that the assemblies that contain the credential and client type has had a chance to register itself.
this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetTypeInfo().Assembly);
this.ServiceLocator.EnsureAssemblyRegistration(typeof(T).GetTypeInfo().Assembly);
return this.GetSupportedClient(this.clients.Where(c => c == typeof(T)), credential, token, version);
}
/// <summary>
/// Gets a client for the given collection that supports the credential and version.
/// </summary>
/// <param name="clientTypes">A list client types.</param>
/// <param name="credential">A credential that needs to be supported.</param>
/// <param name="version">A version that needs to be supported.</param>
/// <param name="token">A cancellation token that can be used to cancel operations.</param>
/// <returns>A client that supports the given credential and version.</returns>
internal IOpenStackClient GetSupportedClient(IEnumerable<Type> clientTypes, ICredential credential, CancellationToken token, string version)
{
foreach (var clientType in clientTypes)
{
var client = this.CreateClient(clientType);
var client = this.CreateClientInstance(clientType, credential, token);
if (client.IsSupported(credential, version))
{
return client;
@@ -63,19 +116,23 @@ namespace OpenStack
/// Creates a new instance of the requested client type
/// </summary>
/// <param name="clientType">The type of the client to create.</param>
/// <param name="credential">A credential that needs to be supported.</param>
/// <param name="token">A cancellation token that can be used to cancel operations.</param>
/// <returns>An instance of the requested client.</returns>
internal IOpenStackClient CreateClient(Type clientType)
internal IOpenStackClient CreateClientInstance(Type clientType, ICredential credential, CancellationToken token)
{
clientType.AssertIsNotNull("clientType", "Cannot create an OpenStack client with a null type.");
credential.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null credential.");
token.AssertIsNotNull("credential", "Cannot create an OpenStack client with a null cancellation token. Use CancellationToken.None.");
IOpenStackClient instance;
IOpenStackClient instance;
try
{
instance = Activator.CreateInstance(clientType) as IOpenStackClient;
instance = Activator.CreateInstance(clientType, credential, token, this.ServiceLocator) as IOpenStackClient;
}
catch (Exception ex)
{
throw new InvalidOperationException(string.Format("Could not create a client of type '{0}'. See inner exception for details.", clientType.Name),ex);
throw new InvalidOperationException(string.Format("Could not create a client of type '{0}'. See inner exception for details.", clientType.Name), ex);
}
if (instance != null)

View File

@@ -28,13 +28,15 @@ namespace OpenStack
/// <inheritdoc/>
internal class OpenStackServiceClientManager : IOpenStackServiceClientManager
{
internal IServiceLocator ServiceLocator;
internal IDictionary<Type, IOpenStackServiceClientDefinition> serviceClientDefinitions;
/// <summary>
/// Creates a new instance of the OpenStackServiceClientManager class.
/// </summary>
internal OpenStackServiceClientManager()
internal OpenStackServiceClientManager(IServiceLocator serviceLocator)
{
this.ServiceLocator = serviceLocator;
this.serviceClientDefinitions = new Dictionary<Type, IOpenStackServiceClientDefinition>();
}
@@ -47,7 +49,7 @@ namespace OpenStack
//Ensure that the assembly that contains this credential has had a chance to be service located.
//This is, at least for now, the entry point for third-parties can extend the API/SDK.
ServiceLocator.Instance.EnsureAssemblyRegistration(credential.GetType().GetTypeInfo().Assembly);
this.ServiceLocator.EnsureAssemblyRegistration(credential.GetType().GetTypeInfo().Assembly);
foreach (var serviceClientDef in this.serviceClientDefinitions.Where(s =>typeof(T).GetTypeInfo().IsAssignableFrom(s.Key.GetTypeInfo())))
{
@@ -75,7 +77,7 @@ namespace OpenStack
IOpenStackServiceClient instance;
try
{
instance = clientDefinition.Create(credential, cancellationToken) as IOpenStackServiceClient;
instance = clientDefinition.Create(credential, cancellationToken, this.ServiceLocator) as IOpenStackServiceClient;
}
catch (Exception ex)
{

View File

@@ -35,7 +35,6 @@ namespace OpenStack
manager.RegisterServiceInstance(typeof(IStorageServiceRestClientFactory), new StorageServiceRestClientFactory());
manager.RegisterServiceInstance(typeof(IStorageContainerNameValidator), new StorageContainerNameValidator());
manager.RegisterServiceInstance(typeof(IStorageFolderNameValidator), new StorageFolderNameValidator());
manager.RegisterServiceInstance(typeof(IStorageItemNameExtractor), new StorageItemNameExtractor());
manager.RegisterServiceInstance(typeof(ILargeStorageObjectCreatorFactory), new LargeStorageObjectCreatorFactory());
//Identity related clients/services
@@ -45,23 +44,23 @@ namespace OpenStack
manager.RegisterServiceInstance(typeof(IOpenStackRegionResolver), new OpenStackRegionResolver());
//Converters
manager.RegisterServiceInstance(typeof(IStorageContainerPayloadConverter), new StorageContainerPayloadConverter());
manager.RegisterServiceInstance(typeof(IStorageContainerPayloadConverter), new StorageContainerPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IStorageObjectPayloadConverter), new StorageObjectPayloadConverter());
manager.RegisterServiceInstance(typeof(IStorageFolderPayloadConverter), new StorageFolderPayloadConverter());
manager.RegisterServiceInstance(typeof(IStorageAccountPayloadConverter), new StorageAccountPayloadConverter());
manager.RegisterServiceInstance(typeof(IStorageFolderPayloadConverter), new StorageFolderPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IStorageAccountPayloadConverter), new StorageAccountPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IAccessTokenPayloadConverter), new AccessTokenPayloadConverter());
manager.RegisterServiceInstance(typeof(IOpenStackServiceCatalogPayloadConverter), new OpenStackServiceCatalogPayloadConverter());
manager.RegisterServiceInstance(typeof(IOpenStackServiceDefinitionPayloadConverter), new OpenStackServiceDefinitionPayloadConverter());
manager.RegisterServiceInstance(typeof(IOpenStackServiceCatalogPayloadConverter), new OpenStackServiceCatalogPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IOpenStackServiceDefinitionPayloadConverter), new OpenStackServiceDefinitionPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IOpenStackServiceEndpointPayloadConverter), new OpenStackServiceEndpointPayloadConverter());
//Client Management
var clientManager = new OpenStackClientManager();
var clientManager = new OpenStackClientManager(locator);
clientManager.RegisterClient<OpenStackClient>();
manager.RegisterServiceInstance(typeof(IOpenStackClientManager), clientManager);
//Service Management
var serviceManager = new OpenStackServiceClientManager();
var serviceManager = new OpenStackServiceClientManager(locator);
serviceManager.RegisterServiceClient<StorageServiceClient>(new StorageServiceClientDefinition());
serviceManager.RegisterServiceClient<IdentityServiceClient>(new IdentityServiceClientDefinition());
manager.RegisterServiceInstance(typeof(IOpenStackServiceClientManager), serviceManager);

View File

@@ -13,6 +13,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Storage
{
/// <summary>
@@ -24,7 +27,8 @@ namespace OpenStack.Storage
/// Creates a client that can be used to interact with the OpenStack storage service.
/// </summary>
/// <param name="context">A storage service context to be used by the client.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>The client.</returns>
IStorageServicePocoClient Create(StorageServiceClientContext context);
IStorageServicePocoClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator);
}
}

View File

@@ -14,6 +14,8 @@
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Storage
{
/// <summary>
@@ -25,7 +27,8 @@ namespace OpenStack.Storage
/// Creates a client that can be used to connect to an OpenStack storage service.
/// </summary>
/// <param name="context">The storage service context that the client will use.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>The client.</returns>
IStorageServiceRestClient Create(StorageServiceClientContext context);
IStorageServiceRestClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator);
}
}

View File

@@ -25,6 +25,18 @@ namespace OpenStack.Storage
/// <inheritdoc/>
internal class StorageAccountPayloadConverter : IStorageAccountPayloadConverter
{
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageAccountPayloadConverter class.
/// </summary>
/// <param name="serviceLocator">A service locator that will be used to locate dependent services.</param>
public StorageAccountPayloadConverter(IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage account payload converter with a null service locator.");
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public StorageAccount Convert(string name, IHttpHeadersAbstraction headers, string payload)
{
@@ -32,7 +44,7 @@ namespace OpenStack.Storage
headers.AssertIsNotNull("headers");
payload.AssertIsNotNull("payload");
var containerConverter = ServiceLocator.Instance.Locate<IStorageContainerPayloadConverter>();
var containerConverter = this.ServiceLocator.Locate<IStorageContainerPayloadConverter>();
try
{

View File

@@ -27,6 +27,18 @@ namespace OpenStack.Storage
/// <inheritdoc/>
internal class StorageContainerPayloadConverter : IStorageContainerPayloadConverter
{
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageContainerPayloadConverter class.
/// </summary>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public StorageContainerPayloadConverter(IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage container payload converter with a null service locator.");
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public IEnumerable<StorageContainer> Convert(string payload)
{
@@ -95,8 +107,8 @@ namespace OpenStack.Storage
headers.AssertIsNotNull("headers");
payload.AssertIsNotNull("payload");
var objectConverter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var folderConverter = ServiceLocator.Instance.Locate<IStorageFolderPayloadConverter>();
var objectConverter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var folderConverter = this.ServiceLocator.Locate<IStorageFolderPayloadConverter>();
try
{

View File

@@ -29,6 +29,17 @@ namespace OpenStack.Storage
internal class StorageFolderPayloadConverter : IStorageFolderPayloadConverter
{
internal const string consecutiveSlashRegex = @"/{2,}";
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageFolderPayloadConverter class.
/// </summary>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public StorageFolderPayloadConverter(IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage folder payload converter with a null service locator.");
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public IEnumerable<StorageFolder> Convert(IEnumerable<StorageObject> objects)
@@ -108,7 +119,7 @@ namespace OpenStack.Storage
var subFolders = array.Where(t => t["subdir"] != null);
var rawObjects = array.Where(t => t["subdir"] == null);
var objectConverter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var objectConverter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var objects = rawObjects.Select(t => objectConverter.ConvertSingle(t,containerName)).ToList();
objects.RemoveAll(o => string.Equals(o.FullName, folderName, StringComparison.Ordinal));

View File

@@ -58,8 +58,10 @@ namespace OpenStack.Storage
/// <returns>The "friendly" name of the item. (e.g. "b" if the items full name is "a/b")</returns>
internal static string ExtractName(string fullItemName)
{
var extractor = ServiceLocator.Instance.Locate<IStorageItemNameExtractor>();
return extractor.ExtractName(fullItemName);
var fullName = fullItemName.Trim('/');
var lastIndex = fullName.LastIndexOf('/');
lastIndex++;
return fullName.Substring(lastIndex, fullName.Length - lastIndex);
}
}
}

View File

@@ -32,6 +32,7 @@ namespace OpenStack.Storage
{
internal StorageServiceClientContext Context;
internal const string StorageServiceName = "Object Storage";
internal IServiceLocator ServiceLocator;
/// <inheritdoc/>
public long LargeObjectThreshold { get; set; }
@@ -48,7 +49,21 @@ namespace OpenStack.Storage
// The reason is that this breaks encapsulation. The rest layer/client is responsible for resolving it's own endpoint,
// This object should not also try and resolve the uri. In general we abstracted the consumer away from the URI, we should not break that
// abstraction.
return this.Context.Credential.ServiceCatalog.GetPublicEndpoint(StorageServiceName, this.Context.Credential.Region);
return this.Context.PublicEndpoint;
}
/// <summary>
/// Gets the public endpoint for a service in the given service catalog for the given region.
/// </summary>
/// <param name="serviceCatalog">The service catalog to search.</param>
/// <param name="serviceName">The name of the service to look for.</param>
/// <param name="region">The region to look for.</param>
/// <returns>A Uri for the public endpoint.</returns>
internal Uri GetPublicEndpoint(OpenStackServiceCatalog serviceCatalog, string serviceName, string region)
{
var resolver = this.ServiceLocator.Locate<IOpenStackServiceEndpointResolver>();
var endpoint = resolver.ResolveEndpoint(serviceCatalog, StorageServiceName, region);
return new Uri(endpoint);
}
/// <summary>
@@ -56,13 +71,18 @@ namespace OpenStack.Storage
/// </summary>
/// <param name="credentials">The credential to be used by this client.</param>
/// <param name="token">The cancellation token to be used by this client.</param>
public StorageServiceClient(IOpenStackCredential credentials, CancellationToken token)
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public StorageServiceClient(IOpenStackCredential credentials, CancellationToken token, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service client with a null service locator.");
this.LargeObjectThreshold = 524288000; //Set the default large file threshold to 500MB.
this.LargeObjectSegments = 10; //set the default number of segments for large objects to 10.
this.LargeObjectSegmentContainer = "LargeObjectSegments"; //set the default name of the container that will hold segments to 'LargeObjectSegments';
this.Context = new StorageServiceClientContext(credentials, token, StorageServiceName);
this.ServiceLocator = serviceLocator;
var endpoint = this.GetPublicEndpoint(credentials.ServiceCatalog, StorageServiceName, credentials.Region);
this.Context = new StorageServiceClientContext(credentials, token, StorageServiceName, endpoint);
}
/// <inheritdoc/>
@@ -198,7 +218,7 @@ namespace OpenStack.Storage
folderName.AssertIsNotNullOrEmpty("folderName", "Cannot create a storage folder with a name that is null or empty.");
folderName = EnsureTrailingSlashOnFolderName(folderName);
var validator = ServiceLocator.Instance.Locate<IStorageFolderNameValidator>();
var validator = this.ServiceLocator.Locate<IStorageFolderNameValidator>();
if (!validator.Validate(folderName))
{
throw new ArgumentException(string.Format("Folder name '{0}' is invalid. Folder names cannot includes consecutive slashes.", folderName), "folderName");
@@ -305,7 +325,7 @@ namespace OpenStack.Storage
throw new ArgumentException("Cannot create a large object with zero or less segments.", "numberOfSegments");
}
var factory = ServiceLocator.Instance.Locate<ILargeStorageObjectCreatorFactory>();
var factory = this.ServiceLocator.Locate<ILargeStorageObjectCreatorFactory>();
var creator = factory.Create(this);
return await creator.Create(containerName, objectName, metadata, content, numberOfSegments, this.LargeObjectSegmentContainer);
}
@@ -316,7 +336,7 @@ namespace OpenStack.Storage
/// <returns>A POCO client.</returns>
internal IStorageServicePocoClient GetPocoClient()
{
return ServiceLocator.Instance.Locate<IStorageServicePocoClientFactory>().Create(this.Context);
return this.ServiceLocator.Locate<IStorageServicePocoClientFactory>().Create(this.Context, this.ServiceLocator);
}
/// <summary>

View File

@@ -14,6 +14,7 @@
// limitations under the License.
// ============================================================================ */
using System;
using System.Threading;
using OpenStack.Identity;
@@ -39,18 +40,24 @@ namespace OpenStack.Storage
/// </summary>
public string StorageServiceName { get; set; }
/// <summary>
/// Gets or sets the public endpoint.
/// </summary>
public Uri PublicEndpoint { get; set; }
/// <summary>
/// Creates a new instance of the StorageServiceClientContext class.
/// </summary>
/// <param name="credential">The credential for this context.</param>
/// <param name="cancellationToken">The cancellation token for this context.</param>
/// <param name="serviceName">The name of the storage service.</param>
/// <param name="region">The region of the storage service.</param>
internal StorageServiceClientContext(IOpenStackCredential credential, CancellationToken cancellationToken, string serviceName)
/// <param name="publicEndpoint">The Uri for the public endpoint of the storage service.</param>
internal StorageServiceClientContext(IOpenStackCredential credential, CancellationToken cancellationToken, string serviceName, Uri publicEndpoint)
{
this.Credential = credential;
this.CancellationToken = cancellationToken;
this.StorageServiceName = serviceName;
this.PublicEndpoint = publicEndpoint;
}
}
}

View File

@@ -18,6 +18,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Storage
@@ -37,9 +38,9 @@ namespace OpenStack.Storage
}
/// <inheritdoc/>
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken)
public IOpenStackServiceClient Create(ICredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
{
return new StorageServiceClient((IOpenStackCredential)credential, cancellationToken);
return new StorageServiceClient((IOpenStackCredential)credential, cancellationToken, serviceLocator);
}
/// <inheritdoc/>

View File

@@ -30,14 +30,19 @@ namespace OpenStack.Storage
internal class StorageServicePocoClient : IStorageServicePocoClient
{
internal StorageServiceClientContext _context;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageServicePocoClient class.
/// </summary>
/// <param name="context">The storage service to use for this client.</param>
internal StorageServicePocoClient(StorageServiceClientContext context)
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
internal StorageServicePocoClient(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service poco client with a null service locator.");
this._context = context;
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
@@ -55,7 +60,7 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to create storage object '{0}'. The remote server returned the following status code: '{1}'.", obj.Name, resp.StatusCode));
}
var converter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var respObj = converter.Convert(obj.ContainerName, obj.FullName, resp.Headers);
return respObj;
@@ -84,7 +89,7 @@ namespace OpenStack.Storage
}
else //static large object manifest
{
var converter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var manifestPayload = converter.Convert(staticManifest.Objects).ConvertToStream();
resp = await client.CreateStaticManifest(staticManifest.ContainerName, staticManifest.FullName, staticManifest.Metadata, manifestPayload);
@@ -124,10 +129,9 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to get storage account. The remote server returned the following status code: '{0}'.", resp.StatusCode));
}
var endpoint = this._context.Credential.ServiceCatalog.GetPublicEndpoint(this._context.StorageServiceName, this._context.Credential.Region);
var accountName = endpoint.Segments.Last().TrimEnd('/');
var accountName = _context.PublicEndpoint.Segments.Last().TrimEnd('/');
var converter = ServiceLocator.Instance.Locate<IStorageAccountPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageAccountPayloadConverter>();
var account = converter.Convert(accountName, resp.Headers, await resp.ReadContentAsStringAsync());
return account;
@@ -146,7 +150,7 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to get storage container '{0}'. The remote server returned the following status code: '{1}'.", containerName, resp.StatusCode));
}
var converter = ServiceLocator.Instance.Locate<IStorageContainerPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageContainerPayloadConverter>();
var container = converter.Convert(containerName, resp.Headers, await resp.ReadContentAsStringAsync());
return container;
@@ -166,7 +170,7 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to get storage object '{0}'. The remote server returned the following status code: '{1}'.", objectName, resp.StatusCode));
}
var converter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var obj = converter.Convert(containerName, objectName, resp.Headers);
return obj;
@@ -185,7 +189,7 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to get storage manifest '{0}'. The remote server returned the following status code: '{1}'.", manifestName, resp.StatusCode));
}
var objectConverter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var objectConverter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var obj = objectConverter.Convert(containerName, manifestName, resp.Headers);
if (!(obj is StorageManifest))
@@ -217,7 +221,7 @@ namespace OpenStack.Storage
throw new InvalidOperationException(string.Format("Failed to download storage object '{0}'. The remote server returned the following status code: '{1}'.", objectName, resp.StatusCode));
}
var converter = ServiceLocator.Instance.Locate<IStorageObjectPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var obj = converter.Convert(containerName, objectName, resp.Headers);
await resp.Content.CopyToAsync(outputStream);
@@ -300,7 +304,7 @@ namespace OpenStack.Storage
try
{
var converter = ServiceLocator.Instance.Locate<IStorageFolderPayloadConverter>();
var converter = this.ServiceLocator.Locate<IStorageFolderPayloadConverter>();
var folder = converter.Convert(containerName, folderName, await resp.ReadContentAsStringAsync());
return folder;
}
@@ -352,7 +356,7 @@ namespace OpenStack.Storage
/// <returns>The client.</returns>
internal IStorageServiceRestClient GetRestClient()
{
return ServiceLocator.Instance.Locate<IStorageServiceRestClientFactory>().Create(this._context);
return this.ServiceLocator.Locate<IStorageServiceRestClientFactory>().Create(this._context, this.ServiceLocator);
}
}
}

View File

@@ -14,15 +14,17 @@
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Storage
{
/// <inheritdoc/>
internal class StorageServicePocoClientFactory : IStorageServicePocoClientFactory
{
/// <inheritdoc/>
public IStorageServicePocoClient Create(StorageServiceClientContext context)
public IStorageServicePocoClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
return new StorageServicePocoClient(context);
return new StorageServicePocoClient(context, serviceLocator);
}
}
}

View File

@@ -17,7 +17,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using OpenStack.Common;
@@ -29,17 +28,21 @@ namespace OpenStack.Storage
/// <inheritdoc/>
internal class StorageServiceRestClient : IStorageServiceRestClient
{
internal StorageServiceClientContext context;
internal StorageServiceClientContext Context;
internal IStorageContainerNameValidator StorageContainerNameValidator;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageServiceRestClient class.
/// </summary>
/// <param name="context"></param>
internal StorageServiceRestClient(StorageServiceClientContext context)
/// <param name="context">The current storage service context to use.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
internal StorageServiceRestClient(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
this.StorageContainerNameValidator = ServiceLocator.Instance.Locate<IStorageContainerNameValidator>();
this.context = context;
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a storage service rest client with a null service locator.");
this.ServiceLocator = serviceLocator;
this.StorageContainerNameValidator = this.ServiceLocator.Locate<IStorageContainerNameValidator>();
this.Context = context;
}
/// <inheritdoc/>
@@ -47,9 +50,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, objectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, objectName);
client.Method = HttpMethod.Put;
this.AddItemMetadata(metadata, client);
@@ -67,9 +70,9 @@ namespace OpenStack.Storage
segmentsPath.AssertIsNotNullOrEmpty("segmentsPath","Cannot create a dynamic large object manifest with a null or empty segments path.");
metadata.AssertIsNotNull("metadata","Cannot create a storage manifest with null metadata.");
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, manifestName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, manifestName);
client.Method = HttpMethod.Put;
client.Content = new MemoryStream();
@@ -87,9 +90,9 @@ namespace OpenStack.Storage
metadata.AssertIsNotNull("metadata", "Cannot create a storage manifest with null metadata.");
content.AssertIsNotNull("content","Cannot create a static large object manifest with null content.");
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
var baseUri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
var baseUri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Uri = new Uri(string.Format("{0}/{1}?multipart-manifest=put", baseUri, manifestName));
client.Method = HttpMethod.Put;
client.Content = content;
@@ -104,9 +107,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Method = HttpMethod.Put;
client.Content = new MemoryStream();
@@ -120,9 +123,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, objectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, objectName);
client.Method = HttpMethod.Get;
return await client.SendAsync();
@@ -134,9 +137,9 @@ namespace OpenStack.Storage
AssertContainerNameIsValid(containerName);
folderName.AssertIsNotNullOrEmpty("folderName","Cannot get a folder with a null or empty folder name.");
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
var baseUri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
var baseUri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
var prefix = string.Equals("/", folderName, StringComparison.Ordinal)
? string.Empty
: string.Format("&prefix={0}", folderName);
@@ -152,9 +155,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Method = HttpMethod.Get;
return await client.SendAsync();
@@ -165,9 +168,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, objectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, objectName);
client.Method = HttpMethod.Delete;
return await client.SendAsync();
@@ -178,9 +181,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Method = HttpMethod.Delete;
return await client.SendAsync();
@@ -191,9 +194,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, objectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, objectName);
client.Method = HttpMethod.Post;
AddItemMetadata(metadata,client);
@@ -205,9 +208,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Method = HttpMethod.Post;
AddItemMetadata(metadata, client);
@@ -219,9 +222,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Method = HttpMethod.Head;
return await client.SendAsync();
@@ -232,9 +235,9 @@ namespace OpenStack.Storage
{
AssertContainerNameIsValid(containerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), containerName, objectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, containerName, objectName);
client.Method = HttpMethod.Head;
return await client.SendAsync();
@@ -246,9 +249,9 @@ namespace OpenStack.Storage
AssertContainerNameIsValid(containerName);
manifestName.AssertIsNotNullOrEmpty("manifestName", "Cannot get a manifest with a null or empty folder name.");
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
var baseUri = CreateRequestUri(GetServiceEndpoint(this.context), containerName);
var baseUri = CreateRequestUri(this.Context.PublicEndpoint, containerName);
client.Uri = new Uri(string.Format("{0}/{1}?multipart-manifest=get", baseUri, manifestName));
client.Method = HttpMethod.Get;
@@ -261,9 +264,9 @@ namespace OpenStack.Storage
AssertContainerNameIsValid(sourceContainerName);
AssertContainerNameIsValid(targetContainerName);
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context), sourceContainerName, sourceObjectName);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, sourceContainerName, sourceObjectName);
client.Headers.Add("Destination",string.Join("/", targetContainerName, targetObjectName));
client.Method = new HttpMethod("COPY");
@@ -274,9 +277,9 @@ namespace OpenStack.Storage
/// <inheritdoc/>
public async Task<IHttpResponseAbstraction> GetAccount()
{
var client = this.GetHttpClient(this.context);
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(GetServiceEndpoint(this.context));
client.Uri = CreateRequestUri(this.Context.PublicEndpoint);
client.Method = HttpMethod.Get;
return await client.SendAsync();
@@ -289,7 +292,7 @@ namespace OpenStack.Storage
/// <returns>The Http client.</returns>
internal IHttpAbstractionClient GetHttpClient(StorageServiceClientContext context)
{
var client = ServiceLocator.Instance.Locate<IHttpAbstractionClientFactory>().Create(context.CancellationToken);
var client = this.ServiceLocator.Locate<IHttpAbstractionClientFactory>().Create(context.CancellationToken);
AddAuthenticationHeader(context.Credential.AccessTokenId, client);
client.Headers.Add("Accept","application/json");
return client;
@@ -342,15 +345,5 @@ namespace OpenStack.Storage
{
client.Headers.Add("X-Auth-Token", authenticationId);
}
/// <summary>
/// Gets the public endpoint for the remote service.
/// </summary>
/// <param name="context">The storage service context to use.</param>
/// <returns>The public endpoint for the remote storage service.</returns>
internal static Uri GetServiceEndpoint(StorageServiceClientContext context)
{
return context.Credential.ServiceCatalog.GetPublicEndpoint(context.StorageServiceName, context.Credential.Region);
}
}
}

View File

@@ -14,15 +14,17 @@
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Storage
{
/// <inheritdoc/>
internal class StorageServiceRestClientFactory : IStorageServiceRestClientFactory
{
/// <inheritdoc/>
public IStorageServiceRestClient Create(StorageServiceClientContext context)
public IStorageServiceRestClient Create(StorageServiceClientContext context, IServiceLocator serviceLocator)
{
return new StorageServiceRestClient(context);
return new StorageServiceRestClient(context, serviceLocator);
}
}
}

View File

@@ -8,8 +8,6 @@ Quick Start Example
The following code will connect to Openstack, and print out all of the containers in the default storage account::
using System;
using System.Linq;
using System.Security;
using System.Threading;
using Openstack;
using Openstack.Identity;
@@ -21,7 +19,7 @@ The following code will connect to Openstack, and print out all of the container
var tenantId = "XXXXXXXXXXXXXX-Project";
var credential = new OpenstackCredential(authUri, userName, password, tenantId);
var client = new OpenstackClient(credential, CancellationToken.None);
var client = OpenStackClientFactory.CreateClient(credential);
await client.Connect();