diff --git a/.gitattributes b/.gitattributes
deleted file mode 100644
index 1ff0c42..0000000
--- a/.gitattributes
+++ /dev/null
@@ -1,63 +0,0 @@
-###############################################################################
-# Set default behavior to automatically normalize line endings.
-###############################################################################
-* text=auto
-
-###############################################################################
-# Set default behavior for command prompt diff.
-#
-# This is need for earlier builds of msysgit that does not have it on by
-# default for csharp files.
-# Note: This is only used by command line
-###############################################################################
-#*.cs diff=csharp
-
-###############################################################################
-# Set the merge driver for project and solution files
-#
-# Merging from the command prompt will add diff markers to the files if there
-# are conflicts (Merging from VS is not affected by the settings below, in VS
-# the diff markers are never inserted). Diff markers may cause the following
-# file extensions to fail to load in VS. An alternative would be to treat
-# these files as binary and thus will always conflict and require user
-# intervention with every merge. To do so, just uncomment the entries below
-###############################################################################
-#*.sln merge=binary
-#*.csproj merge=binary
-#*.vbproj merge=binary
-#*.vcxproj merge=binary
-#*.vcproj merge=binary
-#*.dbproj merge=binary
-#*.fsproj merge=binary
-#*.lsproj merge=binary
-#*.wixproj merge=binary
-#*.modelproj merge=binary
-#*.sqlproj merge=binary
-#*.wwaproj merge=binary
-
-###############################################################################
-# behavior for image files
-#
-# image files are treated as binary by default.
-###############################################################################
-#*.jpg binary
-#*.png binary
-#*.gif binary
-
-###############################################################################
-# diff behavior for common document formats
-#
-# Convert binary document formats to text before diffing them. This feature
-# is only available from the command line. Turn it on by uncommenting the
-# entries below.
-###############################################################################
-#*.doc diff=astextplain
-#*.DOC diff=astextplain
-#*.docx diff=astextplain
-#*.DOCX diff=astextplain
-#*.dot diff=astextplain
-#*.DOT diff=astextplain
-#*.pdf diff=astextplain
-#*.PDF diff=astextplain
-#*.rtf diff=astextplain
-#*.RTF diff=astextplain
diff --git a/.gitignore b/.gitignore
deleted file mode 100644
index d22210f..0000000
--- a/.gitignore
+++ /dev/null
@@ -1,9 +0,0 @@
-################################################################################
-# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
-################################################################################
-
-*.user
-*.suo
-packages/
-obj/
-bin/
\ No newline at end of file
diff --git a/.gitreview b/.gitreview
deleted file mode 100644
index c7779a4..0000000
--- a/.gitreview
+++ /dev/null
@@ -1,4 +0,0 @@
-[gerrit]
-host=review.openstack.org
-port=29418
-project=stackforge/openstack-sdk-dotnet.git
diff --git a/CHANGELOG.md b/CHANGELOG.md
deleted file mode 100644
index 39990e0..0000000
--- a/CHANGELOG.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Release Notes
-
-This changelog contains the relevant feature additions and bug fixes. To obtain a complete diff between versions you can got to https://github.com/stackforge/openstack-sdk-dotnet/compare/XXX...XXX where the XXX values are two different tagged versions of the library. For example, https://github.com/stackforge/openstack-sdk-dotnet/compare/v0.9.0...v0.9.1
-
-* v0.9.1 (2014-05-30)
-
- * Includes bug fixes for DevStack compatibility.
-
-* v0.9.0 (2014-05-12)
-
- * Initial release of the SDK.
- * Includes basic support for authentication.
- * Includes basic support for working with storage containers, objects and folders.
\ No newline at end of file
diff --git a/OpenStack/AssemblyVersionInfo.cs b/OpenStack/AssemblyVersionInfo.cs
deleted file mode 100644
index 0661bcd..0000000
--- a/OpenStack/AssemblyVersionInfo.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// /* ============================================================================
-// 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.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("0.9.1.0")]
-[assembly: AssemblyFileVersion("0.9.1.0")]
diff --git a/OpenStack/Build/readme.txt b/OpenStack/Build/readme.txt
deleted file mode 100644
index 0c6af64..0000000
--- a/OpenStack/Build/readme.txt
+++ /dev/null
@@ -1 +0,0 @@
-This is where we would put things like fixcop and stylcop related stuff or any custom build targets that we would want to bring in... basically anything that is related to building the solution.
diff --git a/OpenStack/Examples/CustomServiceClientExample/App.config b/OpenStack/Examples/CustomServiceClientExample/App.config
deleted file mode 100644
index 8e15646..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/CustomServiceClientExample.csproj b/OpenStack/Examples/CustomServiceClientExample/CustomServiceClientExample.csproj
deleted file mode 100644
index 8141156..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/CustomServiceClientExample.csproj
+++ /dev/null
@@ -1,79 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {83B16A76-A3DF-42E5-95A6-5BBE41FC7854}
- Exe
- Properties
- CustomServiceClientExample
- CustomServiceClientExample
- v4.5
- 512
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\..\Bin\Debug\Newtonsoft.Json.dll
-
-
- False
- ..\..\Bin\net45\Debug\OpenStack.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoPocoClient.cs b/OpenStack/Examples/CustomServiceClientExample/EchoPocoClient.cs
deleted file mode 100644
index a37cc62..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoPocoClient.cs
+++ /dev/null
@@ -1,41 +0,0 @@
-// /* ============================================================================
-// 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.Tasks;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- internal class EchoPocoClient : IEchoPocoClient
- {
- internal IServiceLocator ServiceLocator;
-
- public EchoPocoClient(IServiceLocator serviceLocator)
- {
- this.ServiceLocator = serviceLocator;
- }
-
- public async Task Echo(string message)
- {
- var restClient = this.ServiceLocator.Locate().Create(this.ServiceLocator);
- var resp = await restClient.Echo(message);
- var payload = await resp.ReadContentAsStringAsync();
- var obj = JObject.Parse(payload);
- return new EchoResponse((string)obj["args"]["m"], (string)obj["url"]);
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoPocoClientFactory.cs b/OpenStack/Examples/CustomServiceClientExample/EchoPocoClientFactory.cs
deleted file mode 100644
index ff4de25..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoPocoClientFactory.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// /* ============================================================================
-// 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 OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- internal class EchoPocoClientFactory : IEchoPocoClientFactory
- {
- public IEchoPocoClient Create(IServiceLocator serviceLocator)
- {
- return new EchoPocoClient(serviceLocator);
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoResponse.cs b/OpenStack/Examples/CustomServiceClientExample/EchoResponse.cs
deleted file mode 100644
index abcf48a..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoResponse.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-// /* ============================================================================
-// 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.
-// ============================================================================ */
-
-namespace CustomServiceClientExample
-{
- public class EchoResponse
- {
- public string Message { get; private set; }
-
- public string Url { get; private set; }
-
- public EchoResponse(string message, string url)
- {
- this.Message = message;
- this.Url = url;
- }
- }
-}
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoRestClient.cs b/OpenStack/Examples/CustomServiceClientExample/EchoRestClient.cs
deleted file mode 100644
index d6ec888..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoRestClient.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-// /* ============================================================================
-// 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 System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- internal class EchoRestClient : IEchoRestClient
- {
- internal const string serviceEndpoint = "http://httpbin.org/get";
-
- internal IServiceLocator ServiceLocator;
-
- public EchoRestClient(IServiceLocator serviceLocator)
- {
- this.ServiceLocator = serviceLocator;
- }
-
- public async Task Echo(string message)
- {
- var client = this.ServiceLocator.Locate().Create(CancellationToken.None);
- client.Method = HttpMethod.Get;
- client.Uri = new Uri(serviceEndpoint + "?m=" + message);
- return await client.SendAsync();
- }
- }
-}
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoRestClientFactory.cs b/OpenStack/Examples/CustomServiceClientExample/EchoRestClientFactory.cs
deleted file mode 100644
index a57cfa2..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoRestClientFactory.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// /* ============================================================================
-// 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 OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- internal class EchoRestClientFactory : IEchoRestClientFactory
- {
- public IEchoRestClient Create(IServiceLocator serviceLocator)
- {
- return new EchoRestClient(serviceLocator);
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClient.cs b/OpenStack/Examples/CustomServiceClientExample/EchoServiceClient.cs
deleted file mode 100644
index 3b23c23..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClient.cs
+++ /dev/null
@@ -1,39 +0,0 @@
-// /* ============================================================================
-// 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 System.Threading.Tasks;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace CustomServiceClientExample
-{
- internal class EchoServiceClient : IEchoServiceClient
- {
- internal IServiceLocator ServiceLocator;
-
- public EchoServiceClient(ICredential credential, CancellationToken token, IServiceLocator serviceLocator)
- {
- this.ServiceLocator = serviceLocator;
- }
-
- public async Task Echo(string message)
- {
- var pocoClient = this.ServiceLocator.Locate().Create(this.ServiceLocator);
- return await pocoClient.Echo(message);
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs b/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs
deleted file mode 100644
index c3a31ac..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoServiceClientDefinition.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// /* ============================================================================
-// 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.Collections.Generic;
-using System.Threading;
-using OpenStack;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace CustomServiceClientExample
-{
- internal class EchoServiceClientDefinition : IOpenStackServiceClientDefinition
- {
- public string Name { get; private set; }
-
- public EchoServiceClientDefinition()
- {
- this.Name = typeof(EchoServiceClient).Name;
- }
-
- public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken, IServiceLocator serviceLocator)
- {
- return new EchoServiceClient(credential, cancellationToken, serviceLocator);
- }
-
- public IEnumerable ListSupportedVersions()
- {
- return new List();
- }
-
- public bool IsSupported(ICredential credential, string serviceName)
- {
- return true;
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/EchoServiceRegistrar.cs b/OpenStack/Examples/CustomServiceClientExample/EchoServiceRegistrar.cs
deleted file mode 100644
index ac7a01c..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/EchoServiceRegistrar.cs
+++ /dev/null
@@ -1,32 +0,0 @@
-// /* ============================================================================
-// 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 OpenStack;
-using OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- public class EchoServiceRegistrar : IServiceLocationRegistrar
- {
- public void Register(IServiceLocationManager manager, IServiceLocator locator)
- {
- manager.RegisterServiceInstance(typeof(IEchoPocoClientFactory), new EchoPocoClientFactory());
- manager.RegisterServiceInstance(typeof(IEchoRestClientFactory), new EchoRestClientFactory());
- var serviceManager = locator.Locate();
- serviceManager.RegisterServiceClient(new EchoServiceClientDefinition());
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClient.cs b/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClient.cs
deleted file mode 100644
index a6da5eb..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClient.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// /* ============================================================================
-// 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.Tasks;
-
-namespace CustomServiceClientExample
-{
- public interface IEchoPocoClient
- {
- Task Echo(string message);
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClientFactory.cs b/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClientFactory.cs
deleted file mode 100644
index 136f1af..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/IEchoPocoClientFactory.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// /* ============================================================================
-// 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 OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- public interface IEchoPocoClientFactory
- {
- IEchoPocoClient Create(IServiceLocator serviceLocator);
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/IEchoRestClient.cs b/OpenStack/Examples/CustomServiceClientExample/IEchoRestClient.cs
deleted file mode 100644
index ebe69c1..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/IEchoRestClient.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// /* ============================================================================
-// 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.Tasks;
-using OpenStack.Common.Http;
-
-namespace CustomServiceClientExample
-{
- public interface IEchoRestClient
- {
- Task Echo(string message);
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/IEchoRestClientFactory.cs b/OpenStack/Examples/CustomServiceClientExample/IEchoRestClientFactory.cs
deleted file mode 100644
index 1d83b22..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/IEchoRestClientFactory.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// /* ============================================================================
-// 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 OpenStack.Common.ServiceLocation;
-
-namespace CustomServiceClientExample
-{
- public interface IEchoRestClientFactory
- {
- IEchoRestClient Create(IServiceLocator serviceLocator);
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/IEchoServiceClient.cs b/OpenStack/Examples/CustomServiceClientExample/IEchoServiceClient.cs
deleted file mode 100644
index 2c9f003..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/IEchoServiceClient.cs
+++ /dev/null
@@ -1,26 +0,0 @@
-// /* ============================================================================
-// 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.Tasks;
-using OpenStack;
-
-namespace CustomServiceClientExample
-{
- public interface IEchoServiceClient : IOpenStackServiceClient
- {
- Task Echo(string message);
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/Program.cs b/OpenStack/Examples/CustomServiceClientExample/Program.cs
deleted file mode 100644
index 7a3a0e2..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/Program.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-// /* ============================================================================
-// 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 System.Threading.Tasks;
-using OpenStack;
-using OpenStack.Identity;
-
-namespace CustomServiceClientExample
-{
- class Program
- {
- static void Main(string[] args)
- {
- var authUri = new Uri("https://region.identity.host.com:12345/v2.0/tokens");
- var userName = "user name";
- var password = "password";
- var tenantId = "XXXXXXXXXXXXXX-Project";
- var echoMessage = "Hello world!";
-
- Console.WriteLine("Calling remote service to echo the following message: '{0}'", echoMessage);
-
- var echoMessageTask = EchoMessage(echoMessage, authUri, userName, password, tenantId);
- echoMessageTask.Wait();
-
- Console.WriteLine("Response from remote service: '{0}'", echoMessageTask.Result);
- Console.ReadLine();
- }
-
- public static async Task EchoMessage(string message, Uri authUri, string userName, string password, string tenantId)
- {
- var credential = new OpenStackCredential(authUri, userName, password, tenantId);
- var client = OpenStackClientFactory.CreateClient(credential);
-
- await client.Connect();
-
- var echoServiceClient = client.CreateServiceClient();
- var resp = await echoServiceClient.Echo(message);
- return resp.Message;
- }
- }
-}
\ No newline at end of file
diff --git a/OpenStack/Examples/CustomServiceClientExample/Properties/AssemblyInfo.cs b/OpenStack/Examples/CustomServiceClientExample/Properties/AssemblyInfo.cs
deleted file mode 100644
index cba98de..0000000
--- a/OpenStack/Examples/CustomServiceClientExample/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("CustomServiceClientExample")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
-[assembly: AssemblyProduct("CustomServiceClientExample")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("4cc5544b-fdb5-43ef-8108-9ed8e995d114")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenStack/Examples/Examples.sln b/OpenStack/Examples/Examples.sln
deleted file mode 100644
index 0f4cf55..0000000
--- a/OpenStack/Examples/Examples.sln
+++ /dev/null
@@ -1,28 +0,0 @@
-
-Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2013
-VisualStudioVersion = 12.0.30110.0
-MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleStorageExample", "SimpleStorageExample\SimpleStorageExample.csproj", "{A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}"
-EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomServiceClientExample", "CustomServiceClientExample\CustomServiceClientExample.csproj", "{83B16A76-A3DF-42E5-95A6-5BBE41FC7854}"
-EndProject
-Global
- GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
- Release|Any CPU = Release|Any CPU
- EndGlobalSection
- GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}.Release|Any CPU.Build.0 = Release|Any CPU
- {83B16A76-A3DF-42E5-95A6-5BBE41FC7854}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {83B16A76-A3DF-42E5-95A6-5BBE41FC7854}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {83B16A76-A3DF-42E5-95A6-5BBE41FC7854}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {83B16A76-A3DF-42E5-95A6-5BBE41FC7854}.Release|Any CPU.Build.0 = Release|Any CPU
- EndGlobalSection
- GlobalSection(SolutionProperties) = preSolution
- HideSolutionNode = FALSE
- EndGlobalSection
-EndGlobal
diff --git a/OpenStack/Examples/SimpleStorageExample/App.config b/OpenStack/Examples/SimpleStorageExample/App.config
deleted file mode 100644
index 8e15646..0000000
--- a/OpenStack/Examples/SimpleStorageExample/App.config
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/OpenStack/Examples/SimpleStorageExample/Program.cs b/OpenStack/Examples/SimpleStorageExample/Program.cs
deleted file mode 100644
index 8e2e7cf..0000000
--- a/OpenStack/Examples/SimpleStorageExample/Program.cs
+++ /dev/null
@@ -1,71 +0,0 @@
-// /* ============================================================================
-// 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;
-
-namespace SimpleStorageExample
-{
- class Program
- {
- static void Main(string[] args)
- {
- //enter your user name, password, tenant Id, and the authorization endpoint
- //for the instance of OpenStack that you want to connect to.
- var authUri = new Uri("https://region.identity.host.com:12345/v2.0/tokens");
- var userName = "user name";
- var password = "password";
- var tenantId = "tenant Id"; // e.g. XXXXXXXXXXXXX-Project
-
- //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, password, tenantId);
-
- //Create a new OpenStackClient object using the credentials you just created.
- 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.
- var connectTask = client.Connect();
-
- //Console applications can't do async, so we need to wait on the task,
- //in other contexts you can use the wait keyword.
- connectTask.Wait();
-
- //Once the OpenStackClient has been connected, you can request a service client from it.
- //The service client will be created with the credentials that you have already specified,
- //and do not need any additional information for you to interact with them.
- var storageClient = client.CreateServiceClient();
-
- //Once we have the storage service client, we can ask it for the details of the current storage account.
- var getAccountTask = storageClient.GetStorageAccount();
- getAccountTask.Wait();
- var account = getAccountTask.Result;
-
- //Here we will write out the name of the account, and print out the names of each storage container in the account.
- Console.WriteLine("Connected to storage account '{0}'", account.Name);
- Console.WriteLine("Storage account '{0}' has the following containers:", account.Name);
- foreach (var container in account.Containers)
- {
- Console.WriteLine("\t{0}",container.Name);
- }
- Console.WriteLine(string.Empty);
- Console.ReadLine();
- }
- }
-}
diff --git a/OpenStack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs b/OpenStack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs
deleted file mode 100644
index 6f198e8..0000000
--- a/OpenStack/Examples/SimpleStorageExample/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,36 +0,0 @@
-using System.Reflection;
-using System.Runtime.CompilerServices;
-using System.Runtime.InteropServices;
-
-// General Information about an assembly is controlled through the following
-// set of attributes. Change these attribute values to modify the information
-// associated with an assembly.
-[assembly: AssemblyTitle("SimpleStorageExample")]
-[assembly: AssemblyDescription("")]
-[assembly: AssemblyConfiguration("")]
-[assembly: AssemblyCompany("Microsoft")]
-[assembly: AssemblyProduct("SimpleStorageExample")]
-[assembly: AssemblyCopyright("Copyright © Microsoft 2014")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// Setting ComVisible to false makes the types in this assembly not visible
-// to COM components. If you need to access a type in this assembly from
-// COM, set the ComVisible attribute to true on that type.
-[assembly: ComVisible(false)]
-
-// The following GUID is for the ID of the typelib if this project is exposed to COM
-[assembly: Guid("095db9ea-9103-4a27-b7ec-e91bd1e0817c")]
-
-// Version information for an assembly consists of the following four values:
-//
-// Major Version
-// Minor Version
-// Build Number
-// Revision
-//
-// You can specify all the values or you can default the Build and Revision Numbers
-// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj b/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj
deleted file mode 100644
index eeca3fa..0000000
--- a/OpenStack/Examples/SimpleStorageExample/SimpleStorageExample.csproj
+++ /dev/null
@@ -1,65 +0,0 @@
-
-
-
-
- Debug
- AnyCPU
- {A8BB096A-9E6F-4D84-B091-F1FCF4DDCBDC}
- Exe
- Properties
- SimpleStorageExample
- SimpleStorageExample
- v4.5
- 512
-
-
- AnyCPU
- true
- full
- false
- bin\Debug\
- DEBUG;TRACE
- prompt
- 4
-
-
- AnyCPU
- pdbonly
- true
- bin\Release\
- TRACE
- prompt
- 4
-
-
-
- ..\..\Bin\net45\Debug\Newtonsoft.Json.dll
-
-
- False
- ..\..\Bin\net45\Debug\OpenStack.dll
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/OpenStack/Externals/readme.txt b/OpenStack/Externals/readme.txt
deleted file mode 100644
index 42d9446..0000000
--- a/OpenStack/Externals/readme.txt
+++ /dev/null
@@ -1 +0,0 @@
-This is a folder to bring in any non-NuGet external dependencies...
\ No newline at end of file
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeFlavorPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeFlavorPayloadConverterTests.cs
deleted file mode 100644
index 5b74cfd..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeFlavorPayloadConverterTests.cs
+++ /dev/null
@@ -1,383 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeFlavorPayloadConverterTests
- {
- internal string CreateFlavorJsonFixtrue(string name, string id, string ram, string disk, string vcpus,
- string permaUri, string publicUri)
- {
- var ComputeFlavorJsonResponseFixture = @"{{
- ""flavor"" : {{
- ""name"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""ram"": {3},
- ""vcpus"": {4},
- ""disk"": {5},
- ""id"": ""{6}""
- }}
- }}";
-
- return string.Format(ComputeFlavorJsonResponseFixture, name, publicUri, permaUri, ram, vcpus, disk, id);
- }
-
- internal string CreateFlavorSummaryJsonFixtrue(string name, string id, string permaUri, string publicUri)
- {
- var computeFlavorSummaryJsonResponseFixture = @"{{
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""name"": ""{3}""
- }}";
-
- return string.Format(computeFlavorSummaryJsonResponseFixture, id, publicUri, permaUri, name);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadToFlavor()
- {
- var flavorName = "m1.tiny";
- var flavorId = "1";
- var flavorPublicUri = "http://www.server.com/v2/flavors/1";
- var flavorPermUri = "http://www.server.com/flavors/1";
- var flavorRam = "512";
- var flavorDisk = "10";
- var flavorVcpus = "2";
-
- var computeFlavorJsonResponseFixture = CreateFlavorJsonFixtrue(flavorName, flavorId, flavorRam, flavorDisk,
- flavorVcpus, flavorPermUri, flavorPublicUri);
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavor = converter.ConvertFlavor(computeFlavorJsonResponseFixture);
- Assert.IsNotNull(flavor);
- Assert.AreEqual(flavorName, flavor.Name);
- Assert.AreEqual(flavorId, flavor.Id);
- Assert.AreEqual(flavorRam, flavor.Ram);
- Assert.AreEqual(flavorVcpus, flavor.Vcpus);
- Assert.AreEqual(flavorDisk, flavor.Disk);
- Assert.AreEqual(new Uri(flavorPermUri), flavor.PermanentUri);
- Assert.AreEqual(new Uri(flavorPublicUri), flavor.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingRamToFlavor()
- {
- var missingFixture = @"{
- ""flavor"": {
- ""name"": ""m1.tiny"",
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""vcpus"": 2,
- ""disk"": 10
- }
- }";
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavor = converter.ConvertFlavor(missingFixture);
- Assert.IsNotNull(flavor);
- Assert.AreEqual("m1.tiny", flavor.Name);
- Assert.AreEqual("1", flavor.Id);
- Assert.AreEqual("2", flavor.Vcpus);
- Assert.AreEqual("10", flavor.Disk);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingVcpusToFlavor()
- {
- var missingFixture = @"{
- ""flavor"": {
- ""name"": ""m1.tiny"",
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"": 512,
- ""disk"": 10
- }
- }";
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavor = converter.ConvertFlavor(missingFixture);
- Assert.IsNotNull(flavor);
- Assert.AreEqual("m1.tiny", flavor.Name);
- Assert.AreEqual("1", flavor.Id);
- Assert.AreEqual("512", flavor.Ram);
- Assert.AreEqual("10", flavor.Disk);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingDiskToFlavor()
- {
- var missingFixture = @"{
- ""flavor"": {
- ""name"": ""m1.tiny"",
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"": 512,
- ""vcpus"": 2
- }
- }";
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavor = converter.ConvertFlavor(missingFixture);
- Assert.IsNotNull(flavor);
- Assert.AreEqual("m1.tiny", flavor.Name);
- Assert.AreEqual("1", flavor.Id);
- Assert.AreEqual("512", flavor.Ram);
- Assert.AreEqual("2", flavor.Vcpus);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingIdToFlavor()
- {
- var missingIdFixture = @"{
- ""flavor"" : {
- ""name"": ""m1.tiny"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"": 512,
- ""vcpus"": 2,
- ""disk"": 10
- }
- }";
-
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavor(missingIdFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingNameToFlavor()
- {
- var missingTokenFixture = @"{
- ""flavor"": {
- ""name"" : ""m1.tiny"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"": 512,
- ""vcpus"": 2,
- ""disk"": 10
- }
- }";
-
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavor(missingTokenFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObjectToFlavor()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavor(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonToFlavor()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavor(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonToFlavor()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavor(nonObjectJson);
- }
-
- [TestMethod]
- public void CanParseValidFlavorsJsonPayloadWithMultipleFlavors()
- {
- var validMultipleFlavorsJsonFixture = @"{{ ""flavors"": [ {0} ] }}";
- var firstFlavor = CreateFlavorSummaryJsonFixtrue("m1.tiny", "1", "http://server.com/flavors/1",
- "http://server.com/v2/flavors/1");
- var secondFlavor = CreateFlavorSummaryJsonFixtrue("m1.small", "2", "http://server.com/flavors/2",
- "http://server.com/v2/flavors/2");
-
- var validMultipleFlavorsJson = string.Format(validMultipleFlavorsJsonFixture,
- string.Join(",", new List() {firstFlavor, secondFlavor}));
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavors = converter.ConvertFlavors(validMultipleFlavorsJson).ToList();
-
- Assert.AreEqual(2, flavors.Count());
- var flv1 =
- flavors.First(o => string.Equals(o.Name, "m1.tiny", StringComparison.InvariantCultureIgnoreCase));
- var flv2 =
- flavors.First(o => string.Equals(o.Name, "m1.small", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(flv1);
- Assert.IsNotNull(flv2);
-
- Assert.AreEqual("1", flv1.Id);
- Assert.AreEqual(new Uri("http://server.com/flavors/1"), flv1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/flavors/1"), flv1.PublicUri);
-
- Assert.AreEqual("2", flv2.Id);
- Assert.AreEqual(new Uri("http://server.com/flavors/2"), flv2.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/flavors/2"), flv2.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertValidFlavorsJsonPayloadWithSingleFlavor()
- {
- var validFlavorsJsonFixture = @"{{ ""flavors"": [ {0} ] }}";
- var firstFlavor = CreateFlavorSummaryJsonFixtrue("m1.tiny", "1", "http://server.com/flavors/1",
- "http://server.com/v2/flavors/1");
- var validMultipleFlavorsJson = string.Format(validFlavorsJsonFixture, firstFlavor);
-
- var converter = new ComputeFlavorPayloadConverter();
- var flavors = converter.ConvertFlavors(validMultipleFlavorsJson).ToList();
-
- Assert.AreEqual(1, flavors.Count());
- var flv1 =
- flavors.First(o => string.Equals(o.Name, "m1.tiny", StringComparison.InvariantCultureIgnoreCase));
-
- Assert.IsNotNull(flv1);
-
- Assert.AreEqual("1", flv1.Id);
- Assert.AreEqual(new Uri("http://server.com/flavors/1"), flv1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/flavors/1"), flv1.PublicUri);
- }
-
- [TestMethod]
- public void CanParseValidFlavorsPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""flavors"": [ ] }";
-
- var converter = new ComputeFlavorPayloadConverter();
- var containers = converter.ConvertFlavors(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyFlavorsPayload()
- {
- var payload = string.Empty;
-
- var converter = new ComputeFlavorPayloadConverter();
- var containers = converter.ConvertFlavors(payload).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullFlavorsPayload()
- {
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavors(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFlavorsJsonPayload()
- {
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavors("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFlavorsPayload()
- {
- var converter = new ComputeFlavorPayloadConverter();
- converter.ConvertFlavors("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeImagePayloadConverterTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeImagePayloadConverterTests.cs
deleted file mode 100644
index 73c781c..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeImagePayloadConverterTests.cs
+++ /dev/null
@@ -1,640 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeImagePayloadConverterTests
- {
- internal string CreateImageJsonFixtrue(string name, string id, string permaUri, string publicUri, string status, string minDisk, string minRam, string progress, string created, string updated)
- {
- var ComputeFlavorJsonResponseFixture = @"{{
- ""image"" : {{
- ""name"": ""{0}"",
- ""status"": ""{1}"",
- ""updated"": ""{2}"",
- ""created"": ""{3}"",
- ""minDisk"": {4},
- ""progress"": {5},
- ""minRam"": {6},
- ""links"": [
- {{
- ""href"": ""{7}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{8}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""metadata"": {{
- ""kernel_id"": ""nokernel"",
- ""ramdisk_id"": ""98765""
- }},
- ""id"": ""{9}""
- }}
- }}";
-
- return string.Format(ComputeFlavorJsonResponseFixture, name, status, updated, created, minDisk, progress, minRam, publicUri, permaUri, id);
- }
-
- internal string CreateImageSummaryJsonFixtrue(string name, string id, string permaUri, string publicUri)
- {
- var computeImageSummaryJsonResponseFixture = @"{{
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""name"": ""{3}""
- }}";
-
- return string.Format(computeImageSummaryJsonResponseFixture, id, publicUri, permaUri, name);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadToImage()
- {
- var imageName = "myimage";
- var imageId = "12345";
- var imagePublicUri = "http://www.server.com/v2/images/12345";
- var imagePermUri = "http://www.server.com/images/12345";
- var minRam = 512;
- var minDisk = 10;
- var progress = 100;
- var status = "ACTIVE";
-
- var lastUpdate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var createdDate = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(100));
- var created = createdDate.ToLongTimeString();
- var updated = lastUpdate.ToLongTimeString();
-
- var computeFlavorJsonResponseFixture = CreateImageJsonFixtrue(imageName, imageId, imagePermUri, imagePublicUri,
- status, minDisk.ToString(), minRam.ToString(), progress.ToString(), created,updated);
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(computeFlavorJsonResponseFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual(imageName, image.Name);
- Assert.AreEqual(imageId, image.Id);
- Assert.AreEqual(minRam, image.MinimumRamSize);
- Assert.AreEqual(progress, image.UploadProgress);
- Assert.AreEqual(minDisk, image.MinimumDiskSize);
- Assert.AreEqual(status, image.Status);
- Assert.AreEqual(lastUpdate.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(createdDate.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(new Uri(imagePermUri), image.PermanentUri);
- Assert.AreEqual(new Uri(imagePublicUri), image.PublicUri);
- Assert.AreEqual(2, image.Metadata.Count);
- Assert.AreEqual("nokernel",image.Metadata["kernel_id"]);
- Assert.AreEqual("98765",image.Metadata["ramdisk_id"]);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingMinRamToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(0, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- public void CanConvertJsonPayloadMissingMetadataToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""minRam"": 512,
- ""progress"": 100,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- Assert.AreEqual(0, image.Metadata.Count);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithBadMetadataToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""minRam"": 512,
- ""progress"": 100,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""metadata"": {
- ""kernel_id"": { ""NotExpectyed"" : ""SomeBadValue"" },
- ""ramdisk_id"": ""98765""
- },
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(missingFixture);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingMinDiskToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(0, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingStatusToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual(string.Empty, image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingUpdateDateToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.MinValue;
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissinCreatedDateToImage()
- {
- var created = DateTime.MinValue;
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(100, image.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), image.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), image.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingProgressToImage()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- var image = converter.ConvertImage(missingFixture);
- Assert.IsNotNull(image);
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("ACTIVE", image.Status);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(512, image.MinimumRamSize);
- Assert.AreEqual(10, image.MinimumDiskSize);
- Assert.AreEqual(0, image.UploadProgress);
- Assert.AreEqual(created, image.CreateDate);
- Assert.AreEqual(updated, image.LastUpdated);
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingIdToImage()
- {
- var missingFixture = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ]
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingNameToImage()
- {
- var missingFixture = @"{
- ""image"" : {
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minDisk"": 10,
- ""progress"": 100,
- ""minRam"": 512,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObjectToImage()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonToImage()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonToImage()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImage(nonObjectJson);
- }
-
- [TestMethod]
- public void CanParseValidFlavorsJsonPayloadWithMultipleFlavors()
- {
- var validMultipleImagesJsonFixture = @"{{ ""images"": [ {0} ] }}";
- var firstImage = CreateImageSummaryJsonFixtrue("image1", "12345", "http://server.com/images/12345",
- "http://server.com/v2/images/12345");
- var secondImage = CreateImageSummaryJsonFixtrue("image2", "23456", "http://server.com/images/23456",
- "http://server.com/v2/images/23456");
-
- var validMultipleImagesJson = string.Format(validMultipleImagesJsonFixture,
- string.Join(",", new List() { firstImage, secondImage }));
-
- var converter = new ComputeImagePayloadConverter();
- var images = converter.ConvertImages(validMultipleImagesJson).ToList();
-
- Assert.AreEqual(2, images.Count());
- var img1 =
- images.First(o => string.Equals(o.Name, "image1", StringComparison.InvariantCultureIgnoreCase));
- var img2 =
- images.First(o => string.Equals(o.Name, "image2", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(img1);
- Assert.IsNotNull(img2);
-
- Assert.AreEqual("12345", img1.Id);
- Assert.AreEqual(new Uri("http://server.com/images/12345"), img1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/images/12345"), img1.PublicUri);
-
- Assert.AreEqual("23456", img2.Id);
- Assert.AreEqual(new Uri("http://server.com/images/23456"), img2.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/images/23456"), img2.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertValidFlavorsJsonPayloadWithSingleFlavor()
- {
- var validImagesJsonFixture = @"{{ ""images"": [ {0} ] }}";
- var firstImage = CreateImageSummaryJsonFixtrue("image1", "12345", "http://server.com/images/12345",
- "http://server.com/v2/images/12345");
- var validImagesJson = string.Format(validImagesJsonFixture, firstImage);
-
- var converter = new ComputeImagePayloadConverter();
- var images = converter.ConvertImages(validImagesJson).ToList();
-
- Assert.AreEqual(1, images.Count());
- var img1 =
- images.First(o => string.Equals(o.Name, "image1", StringComparison.InvariantCultureIgnoreCase));
-
- Assert.IsNotNull(img1);
-
- Assert.AreEqual("12345", img1.Id);
- Assert.AreEqual(new Uri("http://server.com/images/12345"), img1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/images/12345"), img1.PublicUri);
- }
-
- [TestMethod]
- public void CanParseValidImagesPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""images"": [ ] }";
-
- var converter = new ComputeImagePayloadConverter();
- var containers = converter.ConvertImages(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyImagesPayload()
- {
- var payload = string.Empty;
-
- var converter = new ComputeImagePayloadConverter();
- var containers = converter.ConvertImages(payload).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullImagesPayload()
- {
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImages(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidImagesJsonPayload()
- {
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImages("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidImagesPayload()
- {
- var converter = new ComputeImagePayloadConverter();
- converter.ConvertImages("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeItemMetadataPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeItemMetadataPayloadConverterTests.cs
deleted file mode 100644
index 0de42f1..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeItemMetadataPayloadConverterTests.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json.Linq;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeItemMetadataPayloadConverterTests
- {
- [TestMethod]
- public void CanConvertJsonPayloadToMetadata()
- {
- var metadataPayload = @"{
- ""metadata"": {
- ""item1"": ""value1"",
- ""item2"": ""value2""
- }
- }";
-
- var converter = new ComputeItemMetadataPayloadConverter();
- var metadata = converter.Convert(metadataPayload);
-
- Assert.AreEqual(2, metadata.Count);
- Assert.IsTrue(metadata.ContainsKey("item1"));
- Assert.AreEqual("value1",metadata["item1"]);
- Assert.IsTrue(metadata.ContainsKey("item2"));
- Assert.AreEqual("value2", metadata["item2"]);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObjectToMetadata()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeItemMetadataPayloadConverter();
- converter.Convert(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonToMetadata()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeItemMetadataPayloadConverter();
- converter.Convert(nonObjectJson);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonToMetadata()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeItemMetadataPayloadConverter();
- converter.Convert(badJsonFixture);
- }
-
- [TestMethod]
- public void CanConvertEmptyMetadataToJson()
- {
- var metadata = new Dictionary();
-
- var converter = new ComputeItemMetadataPayloadConverter();
- var payload = converter.Convert(metadata);
-
- var jsonObj = JObject.Parse(payload);
- var metadataToken = jsonObj["metadata"];
- Assert.IsNotNull(metadataToken);
- Assert.AreEqual(0, metadataToken.Children().Count());
- }
-
- [TestMethod]
- public void CanConvertSingleMetadataToJson()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
-
- var converter = new ComputeItemMetadataPayloadConverter();
- var payload = converter.Convert(metadata);
-
- var jsonObj = JObject.Parse(payload);
- var metadataToken = jsonObj["metadata"];
- Assert.IsNotNull(metadataToken);
- Assert.AreEqual("value1", metadataToken["item1"]);
- }
-
- [TestMethod]
- public void CanConvertMultipleMetadataToJson()
- {
- var metadata = new Dictionary() {{"item1", "value1"}, {"item2", "value2"}};
-
- var converter = new ComputeItemMetadataPayloadConverter();
- var payload = converter.Convert(metadata);
-
- var jsonObj = JObject.Parse(payload);
- var metadataToken = jsonObj["metadata"];
- Assert.IsNotNull(metadataToken);
- Assert.AreEqual("value1", metadataToken["item1"]);
- Assert.AreEqual("value2", metadataToken["item2"]);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotConvertNullMetadataToJson()
- {
- IDictionary metadata = null;
- var converter = new ComputeItemMetadataPayloadConverter();
- converter.Convert(metadata);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeKeyPairPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeKeyPairPayloadConverterTests.cs
deleted file mode 100644
index ca02c1c..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeKeyPairPayloadConverterTests.cs
+++ /dev/null
@@ -1,232 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeKeyPairPayloadConverterTests
- {
- internal string CreateKeyPairJsonFixtrue(string name, string publickKey, string fingerprint)
- {
- var ComputeKeyPairJsonResponseFixture = @"{{
- ""keypair"": {{
- ""public_key"": ""{1}"",
- ""name"": ""{0}"",
- ""fingerprint"": ""{2}""
- }}
- }}";
-
- return string.Format(ComputeKeyPairJsonResponseFixture, name, publickKey, fingerprint);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadToKeyPair()
- {
- var keyName = "Key1";
- var publicKey = "12345";
- var fingerprint = "abcdef";
-
- var computeFlavorJsonResponseFixture = CreateKeyPairJsonFixtrue(keyName, publicKey, fingerprint);
-
- var converter = new ComputeKeyPairPayloadConverter();
- var keyPair = converter.Convert(computeFlavorJsonResponseFixture);
- Assert.IsNotNull(keyPair);
- Assert.AreEqual(keyName, keyPair.Name);
- Assert.AreEqual(publicKey, keyPair.PublicKey);
- Assert.AreEqual(fingerprint, keyPair.Fingerprint);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingPublicKey()
- {
- var missingFixture = @"{
- ""keypair"": {
- ""name"": ""Key1"",
- ""fingerprint"": ""ABCDEF""
- }
- }";
-
- var converter = new ComputeKeyPairPayloadConverter();
- var keyPair = converter.Convert(missingFixture);
- Assert.IsNotNull(keyPair);
- Assert.AreEqual("Key1", keyPair.Name);
- Assert.AreEqual(string.Empty, keyPair.PublicKey);
- Assert.AreEqual("ABCDEF", keyPair.Fingerprint);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingFingerprint()
- {
- var missingFixture = @"{
- ""keypair"": {
- ""public_key"": ""12345"",
- ""name"": ""Key1""
- }
- }";
-
- var converter = new ComputeKeyPairPayloadConverter();
- var keyPair = converter.Convert(missingFixture);
- Assert.IsNotNull(keyPair);
- Assert.AreEqual("Key1", keyPair.Name);
- Assert.AreEqual("12345", keyPair.PublicKey);
- Assert.AreEqual(string.Empty, keyPair.Fingerprint);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingName()
- {
- var missingFixture = @"{
- ""keypair"": {
- ""public_key"": ""12345"",
- ""fingerprint"": ""ABCDEF""
- }
- }";
-
- var converter = new ComputeKeyPairPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObjectToKeyPair()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonToKeyPair()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonToKeyPair()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs(nonObjectJson);
- }
-
- [TestMethod]
- public void CanParseValidJsonPayloadWithMultipleKeyPairs()
- {
- var validMultipleKeyPairsJsonFixture = @"{{ ""keypairs"": [ {0} ] }}";
- var firstKey = CreateKeyPairJsonFixtrue("Key1", "12345", "abcdef");
- var secondKey = CreateKeyPairJsonFixtrue("Key2", "54321", "fedcba");
-
- var validMultipleKeyPairsJson = string.Format(validMultipleKeyPairsJsonFixture,
- string.Join(",", new List() {firstKey, secondKey}));
-
- var converter = new ComputeKeyPairPayloadConverter();
- var pairs = converter.ConvertKeyPairs(validMultipleKeyPairsJson).ToList();
-
- Assert.AreEqual(2, pairs.Count());
- var key1 =
- pairs.First(o => string.Equals(o.Name, "Key1", StringComparison.InvariantCultureIgnoreCase));
- var key2 =
- pairs.First(o => string.Equals(o.Name, "Key2", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(key1);
- Assert.IsNotNull(key2);
-
- Assert.AreEqual("12345", key1.PublicKey);
- Assert.AreEqual("abcdef", key1.Fingerprint);
-
- Assert.AreEqual("54321", key2.PublicKey);
- Assert.AreEqual("fedcba", key2.Fingerprint);
- }
-
- [TestMethod]
- public void CanConvertValidJsonPayloadWithSingleKeyPair()
- {
- var validKeyPairsJsonFixture = @"{{ ""keypairs"": [ {0} ] }}";
- var firstKey = CreateKeyPairJsonFixtrue("Key1", "12345", "abcdef");
-
- var validKeyPairsJson = string.Format(validKeyPairsJsonFixture, firstKey);
-
- var converter = new ComputeKeyPairPayloadConverter();
- var pairs = converter.ConvertKeyPairs(validKeyPairsJson).ToList();
-
- Assert.AreEqual(1, pairs.Count());
- var key1 = pairs.First(o => string.Equals(o.Name, "Key1", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(key1);
-
- Assert.AreEqual("12345", key1.PublicKey);
- Assert.AreEqual("abcdef", key1.Fingerprint);
- }
-
- [TestMethod]
- public void CanParseValidKeyPairsPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""keypairs"": [ ] }";
-
- var converter = new ComputeKeyPairPayloadConverter();
- var containers = converter.ConvertKeyPairs(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyKeyPairsPayload()
- {
- var payload = string.Empty;
-
- var converter = new ComputeKeyPairPayloadConverter();
- var containers = converter.ConvertKeyPairs(payload).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullKeyPairsPayload()
- {
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidKeyPairsJsonPayload()
- {
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidKeyPairsPayload()
- {
- var converter = new ComputeKeyPairPayloadConverter();
- converter.ConvertKeyPairs("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeRestSimulator.cs b/OpenStack/OpenStack.Test/Compute/ComputeRestSimulator.cs
deleted file mode 100644
index ce1c907..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeRestSimulator.cs
+++ /dev/null
@@ -1,733 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Mime;
-using System.Text;
-using System.Threading;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common;
-using OpenStack.Common.Http;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- public class ComputeRestSimulator : RestSimulator
- {
- internal ICollection Flavors { get; private set; }
-
- internal ICollection Images { get; private set; }
-
- internal ICollection Servers { get; private set; }
-
- internal ICollection KeyPairs { get; private set; }
-
- public ComputeRestSimulator() : base()
- {
- this.Flavors = new List();
- this.Images = new List();
- this.Servers = new List();
- this.KeyPairs = new List();
- }
-
- public ComputeRestSimulator(CancellationToken token) : this()
- {
- }
-
- protected override IHttpResponseAbstraction HandleGet()
- {
- if (this.Uri.Segments.Count() >= 4)
- {
- switch (this.Uri.Segments[3].TrimEnd('/').ToLower())
- {
- case "flavors":
- return HandleGetFlavor();
- case "images":
- return HandleGetImage();
- case "servers":
- return HandleGetServer();
- case "os-keypairs":
- return HandleGetKeyPairs();
- }
- }
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandleGetFlavor()
- {
- Stream flavorContent;
- switch (this.Uri.Segments.Count())
- {
- case 5:
- //flavor id given, list single flavor
- var flavorId = this.Uri.Segments[4].TrimEnd('/');
- var flavor =
- this.Flavors.FirstOrDefault(
- f => string.Equals(f.Id, flavorId, StringComparison.OrdinalIgnoreCase));
- if (flavor == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- flavorContent = TestHelper.CreateStream(GenerateFlavorPayload(flavor));
- break;
- case 4:
- //no flavor id given, list all flavors
- flavorContent = TestHelper.CreateStream(GenerateItemsPayload(this.Flavors, "flavors"));
- break;
- default:
- //Unknown Uri format
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), flavorContent);
- }
-
- internal IHttpResponseAbstraction HandleGetKeyPairs()
- {
- Stream keyPairContent;
- switch (this.Uri.Segments.Count())
- {
- case 5:
- var keyPairName = this.Uri.Segments[4].TrimEnd('/');
- var pair =
- this.KeyPairs.FirstOrDefault(
- kp => string.Equals(kp.Name, keyPairName, StringComparison.OrdinalIgnoreCase));
- if (pair == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- keyPairContent = TestHelper.CreateStream(GenerateKeyPairPayload(pair));
- break;
- case 4:
- keyPairContent = TestHelper.CreateStream(GenerateKeyPairsPayload(this.KeyPairs));
- break;
- default:
- //Unknown Uri format
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), keyPairContent);
- }
-
- internal IHttpResponseAbstraction HandleGetImage()
- {
- Stream imageContent;
- switch (this.Uri.Segments.Count())
- {
- case 5:
- //image id given, list single image
- var imageId = this.Uri.Segments[4].TrimEnd('/');
- if (imageId.ToLower() == "detail")
- {
- imageContent = TestHelper.CreateStream(GenerateItemsPayload(this.Images, "images"));
- }
- else
- {
- var image =
- this.Images.FirstOrDefault(
- f => string.Equals(f.Id, imageId, StringComparison.OrdinalIgnoreCase));
- if (image == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- imageContent = TestHelper.CreateStream(GenerateImagePayload(image));
- }
- break;
- case 6:
- if (this.Uri.Segments[5].TrimEnd('/').ToLower() != "metadata")
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
- var imgId = this.Uri.Segments[4].TrimEnd('/');
- var img =
- this.Images.FirstOrDefault(
- i => string.Equals(i.Id, imgId, StringComparison.OrdinalIgnoreCase));
- if (img == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
- imageContent = TestHelper.CreateStream(GenerateMetadataPayload(img.Metadata));
- break;
- default:
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), imageContent);
- }
-
- internal IHttpResponseAbstraction HandleGetServer()
- {
- Stream serverContent;
-
- if (this.Uri.Segments.Count() < 5)
- {
- if (this.Uri.Segments.Count() == 4)
- {
- serverContent = TestHelper.CreateStream(GenerateItemsPayload(this.Flavors, "servers"));
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), serverContent);
- }
- throw new NotImplementedException();
- }
-
- var srvId = this.Uri.Segments[4].TrimEnd('/');
- var srv =
- this.Servers.FirstOrDefault(
- s => string.Equals(s.Id, srvId, StringComparison.OrdinalIgnoreCase));
- if (srv == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
-
- switch (this.Uri.Segments.Count())
- {
- case 6:
- if (this.Uri.Segments[5].TrimEnd('/').ToLower() != "metadata")
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- serverContent = TestHelper.CreateStream(GenerateMetadataPayload(srv.Metadata));
- break;
- case 5:
- //server id given, list single server
- serverContent = TestHelper.CreateStream(GenerateServerPayload(srv));
- break;
- default:
- //Unknown Uri format
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), serverContent);
- }
-
- protected override IHttpResponseAbstraction HandlePost()
- {
- if (this.Uri.Segments.Count() >= 4)
- {
- switch (this.Uri.Segments[3].TrimEnd('/').ToLower())
- {
- case "servers":
- return HandlePostServer();
- case "images":
- return HandlePostImage();
- }
- }
- throw new NotImplementedException();
- }
-
- protected override IHttpResponseAbstraction HandlePut()
- {
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandlePostImage()
- {
- switch (this.Uri.Segments.Count())
- {
- case 6:
- if (this.Uri.Segments[5].TrimEnd('/').ToLower() != "metadata")
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
- var imgId = this.Uri.Segments[4].TrimEnd('/');
- var img =
- this.Images.FirstOrDefault(
- i => string.Equals(i.Id, imgId, StringComparison.OrdinalIgnoreCase));
- if (img == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- ParseAndStoreMetadata(img, GetPayload(this.Content));
- break;
- default:
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary());
- }
-
- internal IHttpResponseAbstraction HandlePostServer()
- {
- switch (this.Uri.Segments.Count())
- {
- case 4:
- return HandlePostNewServer();
- case 6:
- var srvId = this.Uri.Segments[4].TrimEnd('/');
- var action = this.Uri.Segments[5].TrimEnd('/').ToLower();
- switch (action)
- {
- case "metadata":
- return HandlePostServerMetadata(srvId);
- case "action":
- return HandlePostServerAction(srvId);
- default:
- throw new NotImplementedException();
- }
- default:
- throw new NotImplementedException();
- }
- }
-
- internal IHttpResponseAbstraction HandlePostServerAction(string serverId)
- {
- this.Content.Position = 0;
- var reqBody = TestHelper.GetStringFromStream(this.Content);
- var body = JObject.Parse(reqBody);
- if (body["addFloatingIp"] != null && body["addFloatingIp"]["address"] != null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.Accepted, new Dictionary());
- }
-
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandlePostServerMetadata(string serverId)
- {
- var srv =
- this.Servers.FirstOrDefault(
- s => string.Equals(s.Id, serverId, StringComparison.OrdinalIgnoreCase));
- if (srv == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- ParseAndStoreMetadata(srv, GetPayload(this.Content));
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary());
- }
-
- internal IHttpResponseAbstraction HandlePostNewServer()
- {
- var payload = TestHelper.GetStringFromStream(this.Content);
- var obj = JObject.Parse(payload);
- var name = (string)obj["server"]["name"];
- var srv = new ComputeServer(Guid.NewGuid().ToString(), name, "12345", new Uri("http://test.com"), new Uri("http://test.com"), new Dictionary());
- this.Servers.Add(srv);
- var responsePayload = GenerateCreateServeResponse(srv);
-
- return TestHelper.CreateResponse(HttpStatusCode.Accepted, new Dictionary(), responsePayload.ConvertToStream());
- }
-
- protected override IHttpResponseAbstraction HandleDelete()
- {
- if (this.Uri.Segments.Count() >= 4)
- {
- switch (this.Uri.Segments[3].TrimEnd('/').ToLower())
- {
- case "images":
- return HandleDeleteImages();
- case "flavors":
- return HandleDeleteFlavors();
- case "servers":
- return HandleDeleteServers();
- }
- }
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- private IHttpResponseAbstraction HandleDeleteImages()
- {
- if (this.Uri.Segments.Count() < 5)
- {
- throw new NotImplementedException();
- }
-
- var imageId = this.Uri.Segments[4].TrimEnd('/');
- var image = this.Images.FirstOrDefault(i => i.Id == imageId);
- if (image == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- switch (this.Uri.Segments.Count())
- {
- case 5:
- this.Images.Remove(image);
- return TestHelper.CreateResponse(HttpStatusCode.OK);
- case 7:
- var key = this.Uri.Segments[6].TrimEnd('/');
- if (!image.Metadata.ContainsKey(key))
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
- image.Metadata.Remove(key);
- return TestHelper.CreateResponse(HttpStatusCode.OK);
- default:
- throw new NotImplementedException();
- }
- }
-
- private IHttpResponseAbstraction HandleDeleteFlavors()
- {
- throw new NotImplementedException();
- }
-
- private IHttpResponseAbstraction HandleDeleteServers()
- {
- if (this.Uri.Segments.Count() < 5)
- {
- throw new NotImplementedException();
- }
-
- var srvId = this.Uri.Segments[4].TrimEnd('/');
- var srv = this.Servers.FirstOrDefault(s => s.Id == srvId);
- if (srv == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- switch (this.Uri.Segments.Count())
- {
- case 5:
- this.Servers.Remove(srv);
- return TestHelper.CreateResponse(HttpStatusCode.OK);
- case 7:
- var key = this.Uri.Segments[6].TrimEnd('/');
- if (!srv.Metadata.ContainsKey(key))
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
- srv.Metadata.Remove(key);
- return TestHelper.CreateResponse(HttpStatusCode.OK);
- default:
- throw new NotImplementedException();
- }
- }
-
- protected override IHttpResponseAbstraction HandleHead()
- {
- throw new NotImplementedException();
- }
-
- protected override IHttpResponseAbstraction HandleCopy()
- {
- throw new NotImplementedException();
- }
-
- private string GetPayload(Stream input)
- {
- using (var sr = new StreamReader(input))
- {
- return sr.ReadToEnd();
- }
- }
-
- private string GenerateItemsPayload(IEnumerable items, string collectionName )
- {
- var payload = new StringBuilder();
- payload.Append(string.Format("{{ \"{0}\": [",collectionName));
- var first = true;
- foreach (var item in items)
- {
- if (!first)
- {
- payload.Append(",");
- }
-
- payload.Append("{");
- payload.Append(string.Format("\"id\": \"{0}\",", item.Id));
- payload.Append("\"links\": [");
- payload.Append("{");
- payload.Append(string.Format("\"href\": \"{0}\",", item.PublicUri.AbsoluteUri));
- payload.Append("\"rel\": \"self\"");
- payload.Append("},{");
- payload.Append(string.Format("\"href\": \"{0}\",", item.PermanentUri.AbsoluteUri));
- payload.Append("\"rel\": \"bookmark\"");
- payload.Append("}");
- payload.Append("],");
- payload.Append(string.Format("\"name\": \"{0}\"", item.Name));
- payload.Append("}");
- first = false;
- }
- payload.Append("] }");
- return payload.ToString();
- }
-
- private string GenerateKeyPairPayload(ComputeKeyPair keyPair)
- {
- var payloadFixture = @"{{
- ""keypair"": {{
- ""public_key"": ""{1}"",
- ""name"": ""{0}"",
- ""fingerprint"": ""{2}""
- }}
- }}";
- return string.Format(payloadFixture, keyPair.Name, keyPair.PublicKey, keyPair.Fingerprint);
- }
-
- private string GenerateKeyPairsPayload(IEnumerable keyPairs)
- {
- var payload = new StringBuilder();
- payload.Append("{ \"keypairs\": [");
- var first = true;
- foreach (var keyPair in keyPairs)
- {
- if (!first)
- {
- payload.Append(",");
- }
- payload.Append(GenerateKeyPairPayload(keyPair));
- first = false;
- }
-
- payload.Append("] }");
- return payload.ToString();
- }
-
- private string GenerateFlavorPayload(ComputeFlavor flavor)
- {
- var payloadFixture = @"{{
- ""flavor"" : {{
- ""name"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""ram"": {3},
- ""vcpus"": {4},
- ""disk"": {5},
- ""id"": ""{6}""
- }}
- }}";
- return string.Format(payloadFixture, flavor.Name, flavor.PublicUri.AbsoluteUri,
- flavor.PermanentUri.AbsoluteUri, flavor.Ram, flavor.Vcpus, flavor.Disk, flavor.Id);
- }
-
- private string GenerateImagePayload(ComputeImage image)
- {
- var payloadFixture = @"{{
- ""image"" : {{
- ""name"": ""{0}"",
- ""status"": ""{1}"",
- ""updated"": ""{2}"",
- ""created"": ""{3}"",
- ""minDisk"": {4},
- ""progress"": {5},
- ""minRam"": {6},
- ""links"": [
- {{
- ""href"": ""{7}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{8}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{9}""
- }}
- }}";
-
- return string.Format(payloadFixture, image.Name, image.Status, image.CreateDate, image.LastUpdated,
- image.MinimumDiskSize, image.UploadProgress, image.MinimumRamSize, image.PublicUri.AbsoluteUri,
- image.PermanentUri.AbsoluteUri, image.Id);
- }
-
- internal string GenerateCreateServeResponse(ComputeServer server)
- {
- var payloadFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{2}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{3}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{1}""
- }}
- }}";
-
- return string.Format(payloadFixture, server.Id, server.AdminPassword,
- server.PublicUri.AbsoluteUri, server.PermanentUri.AbsoluteUri);
- }
-
- private string GenerateServerPayload(ComputeServer server)
- {
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{2}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""hostId"": ""bd5417ccb076908f6e0d639c37c053b0b6b9681db3464d19908dd4d9"",
- ""addresses"": {{
- ""private"": [
- {{
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""10.0.0.2"",
- ""OS-EXT-IPS:type"": ""fixed""
- }},
- {{
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""172.24.4.3"",
- ""OS-EXT-IPS:type"": ""floating""
- }}
- ]
- }},
- ""links"": [
- {{
- ""href"": ""{4}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{5}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""key_name"": null,
- ""image"": {{
- ""id"": ""c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""links"": [
- {{
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/images/c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""rel"": ""bookmark""
- }}
- ]
- }},
- ""OS-EXT-STS:task_state"": null,
- ""OS-EXT-STS:vm_state"": ""active"",
- ""OS-SRV-USG:launched_at"": ""2014-06-11T18:04:45.000000"",
- ""flavor"": {{
- ""id"": ""1"",
- ""links"": [
- {{
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/flavors/1"",
- ""rel"": ""bookmark""
- }}
- ]
- }},
- ""id"": ""{0}"",
- ""security_groups"": [
- {{
- ""name"": ""MyGroup""
- }},
- {{
- ""name"": ""default""
- }}
- ],
- ""OS-SRV-USG:terminated_at"": null,
- ""OS-EXT-AZ:availability_zone"": ""nova"",
- ""user_id"": ""70d48d344b494a1cbe8adbf7c02be7b5"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""OS-DCF:diskConfig"": ""AUTO"",
- ""os-extended-volumes:volumes_attached"": [],
- ""accessIPv4"": """",
- ""accessIPv6"": """",
- ""progress"": {3},
- ""OS-EXT-STS:power_state"": 1,
- ""config_drive"": """",
- ""metadata"": {{}}
- }}
- }}";
- return string.Format(payloadFixture, server.Id, server.Name, server.Status, server.Progress, server.PublicUri.AbsoluteUri, server.PermanentUri.AbsoluteUri);
- }
-
- private string GenerateMetadataPayload(IDictionary metadata)
- {
- var payload = new StringBuilder();
- payload.Append("{ \"metadata\" : {");
- var isFirst = true;
-
- foreach (var item in metadata)
- {
- if (!isFirst)
- {
- payload.Append(",");
- }
-
- payload.AppendFormat("\"{0}\":\"{1}\"", item.Key, item.Value);
- isFirst = false;
- }
-
- payload.Append("}}");
- return payload.ToString();
- }
-
- private void ParseAndStoreMetadata(MetadataComputeItem item, string payload)
- {
- var jObj = JObject.Parse(payload);
- var metaToken = jObj["metadata"];
- var metdata = JsonConvert.DeserializeObject>(metaToken.ToString());
- item.Metadata = metdata;
- }
- }
-
- public class ComputeRestSimulatorFactory : IHttpAbstractionClientFactory
- {
- internal ComputeRestSimulator Simulator = null;
-
- public ComputeRestSimulatorFactory(ComputeRestSimulator simulator)
- {
- this.Simulator = simulator;
- }
-
- public IHttpAbstractionClient Create()
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(CancellationToken token)
- {
- if (this.Simulator != null)
- {
- this.Simulator.Headers.Clear();
- }
- return this.Simulator ?? new ComputeRestSimulator(token);
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout)
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout, CancellationToken token)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeServerPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeServerPayloadConverterTests.cs
deleted file mode 100644
index a9bb00a..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeServerPayloadConverterTests.cs
+++ /dev/null
@@ -1,756 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeServerPayloadConverterTests
- {
- internal string CreateServerJsonFixtrue(string name, string id, string status, int progress, string publicUri, string permUri)
- {
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{2}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""hostId"": ""bd5417ccb076908f6e0d639c37c053b0b6b9681db3464d19908dd4d9"",
- ""addresses"": {{
- ""private"": [
- {{
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""10.0.0.2"",
- ""OS-EXT-IPS:type"": ""fixed""
- }},
- {{
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""172.24.4.3"",
- ""OS-EXT-IPS:type"": ""floating""
- }}
- ]
- }},
- ""links"": [
- {{
- ""href"": ""{4}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{5}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""key_name"": null,
- ""image"": {{
- ""id"": ""c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""links"": [
- {{
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/images/c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""rel"": ""bookmark""
- }}
- ]
- }},
- ""OS-EXT-STS:task_state"": null,
- ""OS-EXT-STS:vm_state"": ""active"",
- ""OS-SRV-USG:launched_at"": ""2014-06-11T18:04:45.000000"",
- ""flavor"": {{
- ""id"": ""1"",
- ""links"": [
- {{
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/flavors/1"",
- ""rel"": ""bookmark""
- }}
- ]
- }},
- ""id"": ""{0}"",
- ""security_groups"": [
- {{
- ""name"": ""MyGroup""
- }},
- {{
- ""name"": ""default""
- }}
- ],
- ""OS-SRV-USG:terminated_at"": null,
- ""OS-EXT-AZ:availability_zone"": ""nova"",
- ""user_id"": ""70d48d344b494a1cbe8adbf7c02be7b5"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""OS-DCF:diskConfig"": ""AUTO"",
- ""os-extended-volumes:volumes_attached"": [],
- ""accessIPv4"": """",
- ""accessIPv6"": """",
- ""progress"": {3},
- ""OS-EXT-STS:power_state"": 1,
- ""config_drive"": """",
- ""metadata"": {{}}
- }}
- }}";
- return string.Format(payloadFixture, id, name, status, progress, publicUri, permUri);
- }
-
- internal string CreateServerRequstSummaryJsonFixtrue(string id, string permaUri, string publicUri, string adminPass)
- {
- var computeServerSummaryJsonResponseFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{3}""
- }}
- }}";
-
- return string.Format(computeServerSummaryJsonResponseFixture, id, publicUri, permaUri, adminPass);
- }
-
- internal string CreateServersSummaryJsonFixtrue(string name, string id, string permaUri, string publicUri)
- {
- var computeServerSummaryJsonResponseFixture = @"{{
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""name"": ""{3}""
- }}";
-
- return string.Format(computeServerSummaryJsonResponseFixture, id, publicUri, permaUri, name);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverId = "12345";
- var serverName = "testServer";
- var serverProgress = 0;
- var serverState = "ACTIVE";
-
- var computeServerFixture = CreateServerJsonFixtrue(serverName, serverId, serverState, serverProgress, serverPublicUri, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- var server = converter.Convert(computeServerFixture);
-
- Assert.IsNotNull(server);
- Assert.AreEqual(serverId, server.Id);
- Assert.AreEqual(serverName, server.Name);
- Assert.AreEqual(serverState.ToLower(), server.Status.ToString().ToLower());
- Assert.AreEqual(serverProgress, server.Progress);
- Assert.AreEqual(new Uri(serverPermUri), server.PermanentUri);
- Assert.AreEqual(new Uri(serverPublicUri), server.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingIdToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverName = "testServer";
- var serverProgress = 0;
- var serverState = "ACTIVE";
-
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{1}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""href"": ""{3}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{4}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""name"": ""{0}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""progress"": {2}
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverName, serverState, serverProgress, serverPublicUri, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingpublicUriToServer()
- {
- var serverPermUri = "http://www.server.com/servers/1";
- var serverId = "12345";
- var serverName = "testServer";
- var serverProgress = 0;
- var serverState = "ACTIVE";
-
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{2}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{4}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{0}"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""progress"": {3}
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverId, serverName, serverState, serverProgress, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingPermUriToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverId = "12345";
- var serverName = "testServer";
- var serverProgress = 0;
- var serverState = "ACTIVE";
-
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{2}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""href"": ""{4}"",
- ""rel"": ""self""
- }},
- {{
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{0}"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""progress"": {3}
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverId, serverName, serverState, serverProgress, serverPublicUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingStatusToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverId = "12345";
- var serverName = "testServer";
- var serverProgress = 0;
-
- var payloadFixture = @"{{
- ""server"": {{
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""href"": ""{3}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{4}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{0}"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""progress"": {2}
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverId, serverName, serverProgress, serverPublicUri, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingNameToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverId = "12345";
- var serverProgress = 0;
- var serverState = "ACTIVE";
-
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{1}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""href"": ""{3}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{4}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{0}"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""progress"": {2}
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverId, serverState, serverProgress, serverPublicUri, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(missingFixture);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadMissingProgressToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverId = "12345";
- var serverName = "testServer";
- var serverState = "ACTIVE";
-
- var payloadFixture = @"{{
- ""server"": {{
- ""status"": ""{2}"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""links"": [
- {{
- ""href"": ""{3}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{4}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""id"": ""{0}"",
- ""name"": ""{1}"",
- ""created"": ""2014-06-11T18:04:25Z""
- }}
- }}";
-
- var missingFixture = string.Format(payloadFixture, serverId, serverName, serverState, serverPublicUri, serverPermUri);
-
- var converter = new ComputeServerPayloadConverter();
- var server = converter.Convert(missingFixture);
-
- Assert.IsNotNull(server);
- Assert.AreEqual(serverId, server.Id);
- Assert.AreEqual(serverName, server.Name);
- Assert.AreEqual(serverState.ToLower(), server.Status.ToString().ToLower());
- Assert.AreEqual(0, server.Progress);
- Assert.AreEqual(new Uri(serverPermUri), server.PermanentUri);
- Assert.AreEqual(new Uri(serverPublicUri), server.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertServerJsonPayloadEmptyObjectToServer()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidServerJsonToServer()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectServerJsonToServer()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(nonObjectJson);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotConvertNullJsonToServer()
- {
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotConvertEmptyStringJsonToServer()
- {
- var converter = new ComputeServerPayloadConverter();
- converter.Convert(string.Empty);
- }
-
- [TestMethod]
- public void CanConvertSummaryJsonPayloadToServer()
- {
-
- var serverId = "1";
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverAdminPass = "ABCDE";
-
- var computeServerFixture = CreateServerRequstSummaryJsonFixtrue(serverId, serverPermUri, serverPublicUri, serverAdminPass);
-
- var converter = new ComputeServerPayloadConverter();
- var server = converter.ConvertSummary(computeServerFixture);
-
- Assert.IsNotNull(server);
- Assert.AreEqual(serverId, server.Id);
- Assert.AreEqual(serverAdminPass, server.AdminPassword);
- Assert.AreEqual(new Uri(serverPermUri), server.PermanentUri);
- Assert.AreEqual(new Uri(serverPublicUri), server.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertSummaryJsonPayloadMissingIdToServer()
- {
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverAdminPass = "ABCDE";
-
- var computeServerSummaryJsonResponseFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{0}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{2}""
- }}
- }}";
-
- var missingFixture = string.Format(computeServerSummaryJsonResponseFixture, serverPermUri, serverPublicUri, serverAdminPass);
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertSummaryJsonPayloadMissingpublicUriToServer()
- {
- var serverId = "1";
- var serverPermUri = "http://www.server.com/servers/1";
- var serverAdminPass = "ABCDE";
-
- var computeServerSummaryJsonResponseFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{2}""
- }}
- }}";
-
- var missingFixture = string.Format(computeServerSummaryJsonResponseFixture, serverId, serverPermUri, serverAdminPass);
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertSummaryJsonPayloadMissingPermUriToServer()
- {
- var serverId = "1";
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverAdminPass = "ABCDE";
-
- var computeServerSummaryJsonResponseFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }}
- ],
- ""adminPass"": ""{2}""
- }}
- }}";
-
- var missingFixture = string.Format(computeServerSummaryJsonResponseFixture, serverId, serverPublicUri, serverAdminPass);
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertSummaryJsonPayloadMissingAdminPasswordToServer()
- {
- var serverId = "1";
- var serverPublicUri = "http://www.server.com/v2/servers/1";
- var serverPermUri = "http://www.server.com/servers/1";
-
- var computeServerSummaryJsonResponseFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ]
- }}
- }}";
-
- var missingFixture = string.Format(computeServerSummaryJsonResponseFixture, serverId, serverPermUri, serverPublicUri);
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(missingFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObjectToServer()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonToServer()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonToServer()
- {
- var nonObjectJson = @"[]";
-
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertSummary(nonObjectJson);
- }
-
- [TestMethod]
- public void CanParseValidServersJsonPayloadWithMultipleFlavors()
- {
- var validMultipleServersJsonFixture = @"{{ ""servers"": [ {0} ] }}";
- var firstServer = CreateServersSummaryJsonFixtrue("srv1", "1", "http://server.com/servers/1",
- "http://server.com/v2/servers/1");
- var secondServer = CreateServersSummaryJsonFixtrue("srv2", "2", "http://server.com/servers/2",
- "http://server.com/v2/servers/2");
-
- var validMultipleServersJson = string.Format(validMultipleServersJsonFixture,
- string.Join(",", new List() { firstServer, secondServer }));
-
- var converter = new ComputeServerPayloadConverter();
- var servers = converter.ConvertServers(validMultipleServersJson).ToList();
-
- Assert.AreEqual(2, servers.Count());
- var srv1 =
- servers.First(o => string.Equals(o.Name, "srv1", StringComparison.InvariantCultureIgnoreCase));
- var srv2 =
- servers.First(o => string.Equals(o.Name, "srv2", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(srv1);
- Assert.IsNotNull(srv2);
-
- Assert.AreEqual("1", srv1.Id);
- Assert.AreEqual(new Uri("http://server.com/servers/1"), srv1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/servers/1"), srv1.PublicUri);
-
- Assert.AreEqual("2", srv2.Id);
- Assert.AreEqual(new Uri("http://server.com/servers/2"), srv2.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/servers/2"), srv2.PublicUri);
- }
-
- [TestMethod]
- public void CanConvertValidServersJsonPayloadWithSingleFlavor()
- {
- var validFlavorsJsonFixture = @"{{ ""servers"": [ {0} ] }}";
- var firstServer = CreateServersSummaryJsonFixtrue("myserver", "1", "http://server.com/servers/1",
- "http://server.com/v2/servers/1");
- var validSingleServerPayload = string.Format(validFlavorsJsonFixture, firstServer);
-
- var converter = new ComputeServerPayloadConverter();
- var servers = converter.ConvertServers(validSingleServerPayload).ToList();
-
- Assert.AreEqual(1, servers.Count());
- var srv1 =
- servers.First(o => string.Equals(o.Name, "myserver", StringComparison.InvariantCultureIgnoreCase));
-
- Assert.IsNotNull(srv1);
-
- Assert.AreEqual("1", srv1.Id);
- Assert.AreEqual(new Uri("http://server.com/servers/1"), srv1.PermanentUri);
- Assert.AreEqual(new Uri("http://server.com/v2/servers/1"), srv1.PublicUri);
- }
-
- [TestMethod]
- public void CanParseValidServersPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""servers"": [ ] }";
-
- var converter = new ComputeServerPayloadConverter();
- var containers = converter.ConvertServers(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyServersPayload()
- {
- var payload = string.Empty;
-
- var converter = new ComputeServerPayloadConverter();
- var containers = converter.ConvertServers(payload).ToList();
-
- Assert.AreEqual(0, containers.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullServersPayload()
- {
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertServers(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidServersJsonPayload()
- {
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertServers("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidServersPayload()
- {
- var converter = new ComputeServerPayloadConverter();
- converter.ConvertServers("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeServiceClientTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeServiceClientTests.cs
deleted file mode 100644
index 9065cac..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeServiceClientTests.cs
+++ /dev/null
@@ -1,773 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Compute;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeServiceClientTests
- {
- internal TestComputeServicePocoClient ServicePocoClient;
-
- internal string authId = "12345";
- internal string endpoint = "http://testcomputeendpoint.com/v2/1234567890";
- internal ServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.ServicePocoClient = new TestComputeServicePocoClient();
- this.ServiceLocator = new ServiceLocator();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IComputeServicePocoClientFactory), new TestComputeServicePocoClientFactory(this.ServicePocoClient));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.ServicePocoClient = new TestComputeServicePocoClient();
- this.ServiceLocator = new ServiceLocator();
- }
-
- IOpenStackCredential GetValidCreds()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Nova", "Compute Service",
- new List()
- {
- new OpenStackServiceEndpoint(endpoint, string.Empty, "some version", "some version info", "1,2,3")
- }));
-
- var creds = new OpenStackCredential(new Uri(this.endpoint), "SomeUser", "Password", "SomeTenant");
- creds.SetAccessTokenId(this.authId);
- creds.SetServiceCatalog(catalog);
- return creds;
- }
-
- [TestMethod]
- public async Task CanGetFlavors()
- {
- var flv1 = new ComputeFlavor("1", "m1.tiny", "512", "2", "10", new Uri("http://someuri.com/v2/flavors/1"),
- new Uri("http://someuri.com/flavors/1"), new Dictionary());
- var flv2 = new ComputeFlavor("2", "m1.small", "1024", "4", "100", new Uri("http://someuri.com/v2/flavors/2"),
- new Uri("http://someuri.com/flavors/2"), new Dictionary());
- var flavors = new List() {flv1, flv2};
-
- this.ServicePocoClient.GetFlavorsDelegate = () => Task.Factory.StartNew(() => (IEnumerable)flavors);
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var resp = await client.GetFlavors();
- Assert.IsNotNull(resp);
-
- var respFlavors = resp.ToList();
- Assert.AreEqual(2, respFlavors.Count());
- Assert.AreEqual(flv1, respFlavors[0]);
- Assert.AreEqual(flv2, respFlavors[1]);
- }
-
- [TestMethod]
- public async Task CanGetFlavor()
- {
- var expectedFlavor = new ComputeFlavor("1", "m1.tiny", "512", "2", "10", new Uri("http://someuri.com/v2/flavors/1"),
- new Uri("http://someuri.com/flavors/1"), new Dictionary());
-
- this.ServicePocoClient.GetFlavorDelegate = (id) =>
- {
- Assert.AreEqual("1", id);
- return Task.Factory.StartNew(() => expectedFlavor);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var flavor = await client.GetFlavor("1");
-
- Assert.IsNotNull(flavor);
- Assert.AreEqual(expectedFlavor, flavor);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetFlavorWithNullFlavorIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetFlavor(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetFlavorWithEmptyFlavorIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetFlavor(string.Empty);
- }
-
- [TestMethod]
- public async Task CanCreateServer()
- {
- var serverName = "MyServer";
- var imageId = "56789";
- var keyName = "MyKey";
- var flavorId = "2";
- var networkId = "98765";
- var adminPassword = "ABCDE";
- var expServer = new ComputeServer("1235", serverName, adminPassword, new Uri("http://someuri.com/v2/servers/12345"),
- new Uri("http://someuri.com/servers/12345"), new Dictionary());
-
- this.ServicePocoClient.CreateServerDelegate = (name, imgId, flvId, ntwId, key, groups) =>
- {
- Assert.AreEqual(serverName, name);
- Assert.AreEqual(imageId, imgId);
- Assert.AreEqual(flavorId, flvId);
- Assert.AreEqual(networkId, ntwId);
- Assert.AreEqual(keyName, key);
- Assert.IsTrue(groups.Any(g => g == "default"));
- return Task.Factory.StartNew(() => expServer);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var server = await client.CreateServer(serverName, imageId, flavorId, networkId, keyName, new List() { "default" });
-
- Assert.IsNotNull(server);
- Assert.AreEqual("1235", server.Id);
- Assert.AreEqual(adminPassword, server.AdminPassword);
- }
-
- [TestMethod]
- public async Task CanCreateServerWithoutKeyName()
- {
- var serverName = "MyServer";
- var imageId = "56789";
- var flavorId = "2";
- var networkId = "98765";
- var adminPassword = "ABCDE";
- var expServer = new ComputeServer("1235", serverName, adminPassword, new Uri("http://someuri.com/v2/servers/12345"),
- new Uri("http://someuri.com/servers/12345"), new Dictionary());
-
- this.ServicePocoClient.CreateServerDelegate = (name, imgId, flvId, ntwId, key, groups) =>
- {
- Assert.AreEqual(serverName, name);
- Assert.AreEqual(imageId, imgId);
- Assert.AreEqual(flavorId, flvId);
- Assert.AreEqual(networkId, ntwId);
- Assert.AreEqual(string.Empty, key);
- Assert.IsTrue(groups.Any(g => g == "default"));
- return Task.Factory.StartNew(() => expServer);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var server = await client.CreateServer(serverName, imageId, flavorId, networkId, new List() { "default" });
-
- Assert.IsNotNull(server);
- Assert.AreEqual("1235", server.Id);
- Assert.AreEqual(adminPassword, server.AdminPassword);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task CreateServerWithNullNameThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer(null, "12345", "2", "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task CreateServerWithEmptyNameThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer(string.Empty, "12345", "2", "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task CreateServerWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", null, "2", "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task CreateServerWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", string.Empty, "2", "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task CreateServerWithNullFlavorIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", null, "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task CreateServerWithEmptyFlavorIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", string.Empty, "54321", new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task CreateServerWithNullNetworkIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", "2", null, new List() { "default" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task CreateServerWithEmptyNetworkIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", "2", string.Empty, new List() { "default" });
- }
-
- [TestMethod]
- public async Task CanGetServers()
- {
- var expServer1 = new ComputeServer("1", "srv1",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
-
- var expServer2 = new ComputeServer("2", "srv2",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- var servers = new List() { expServer1, expServer2 };
-
- this.ServicePocoClient.GetServersDelegate = () => Task.Factory.StartNew(() => (IEnumerable)servers);
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var resp = await client.GetServers();
- Assert.IsNotNull(resp);
-
- var respFlavors = resp.ToList();
- Assert.AreEqual(2, respFlavors.Count());
- Assert.AreEqual(expServer1, respFlavors[0]);
- Assert.AreEqual(expServer2, respFlavors[1]);
- }
-
- [TestMethod]
- public async Task CanGetServer()
- {
- var serverId = "12345";
- var expServer = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
-
- this.ServicePocoClient.GetServerDelegate = (id) =>
- {
- Assert.AreEqual(serverId, id);
- return Task.Factory.StartNew(() => expServer);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var server = await client.GetServer(serverId);
-
- Assert.IsNotNull(server);
- Assert.AreEqual(expServer, server);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetServerWithNullIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetServer(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetServerWithEmptyIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetServer(string.Empty);
- }
-
- [TestMethod]
- public async Task CanDeleteServer()
- {
- this.ServicePocoClient.DeleteServerDelegate = async (serverId) =>
- {
- await Task.Run(() => Assert.AreEqual(serverId, "12345"));
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServer("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteServerWithNullServerIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServer(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteServerWithEmptyServerIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServer(string.Empty);
- }
-
- [TestMethod]
- public async Task CanAssignFloatingIp()
- {
- this.ServicePocoClient.AssignFloatingIpDelegate = async (serverId, ipAddress) =>
- {
- await Task.Run(() =>
- {
- Assert.AreEqual(serverId, "12345");
- Assert.AreEqual(ipAddress, "172.0.0.1");
- });
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.AssignFloatingIp("12345", "172.0.0.1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task AssignFloatingIpWithNullServerIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.AssignFloatingIp(null, "172.0.0.1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task AssignFloatingIpWithEmptyServerIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.AssignFloatingIp(string.Empty, "172.0.0.1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task AssignFloatingIpWithNullIpAddressThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.AssignFloatingIp("12345", null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task AssignFloatingIpWithEmptyIpAddressThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.AssignFloatingIp("12345", string.Empty);
- }
-
- [TestMethod]
- public async Task CanGetServerMetadata()
- {
- var meta = new Dictionary() { { "item1", "value1" } };
-
- this.ServicePocoClient.GetServerMetadataDelegate = (id) =>
- {
- Assert.AreEqual("12345", id);
- return Task.Factory.StartNew(() => (IDictionary)meta);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var metadata = await client.GetServerMetadata("12345");
-
- Assert.IsNotNull(metadata);
- Assert.AreEqual(meta, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetServerMetadataWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetServerMetadata(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetServerMetadataWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetServerMetadata(string.Empty);
- }
-
- [TestMethod]
- public async Task CanDeleteServerMetadata()
- {
- this.ServicePocoClient.DeleteServerMetadataDelegate = async (flavorId, key) =>
- {
- await Task.Run(() =>
- {
- Assert.AreEqual(flavorId, "12345");
- Assert.AreEqual(key, "item1");
- });
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServerMetadata("12345", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteServerMetadataWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServerMetadata(null, "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteServerMetadataWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServerMetadata(string.Empty, "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteServerMetadataWithEmptyKeyThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServerMetadata("12345", string.Empty);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteServerMetadataWithNullKeyThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteServerMetadata("12345", null);
- }
-
- [TestMethod]
- public async Task CanUpdateServerMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- this.ServicePocoClient.UpdateServerMetadataDelegate = async (flavorId, meta) =>
- {
- await Task.Run(() =>
- {
- Assert.AreEqual(flavorId, "12345");
- Assert.AreEqual(metadata, meta);
- });
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateServerMetadata("12345", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task UpdateServerMetadataWithNullImageIdThrows()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateServerMetadata(null, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task UpdateServerMetadataWithEmptyImageIdThrows()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateServerMetadata(string.Empty, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task UpdateServerMetadataWithNullMetadataThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateServerMetadata("12345", null);
- }
-
- [TestMethod]
- public async Task CanGetImages()
- {
- var img1 = new ComputeImage("12345", "image1", new Uri("http://someuri.com/v2/images/12345"), new Uri("http://someuri.com/images/12345"), new Dictionary(), "active", DateTime.Now, DateTime.Now, 10, 512, 100);
- var img2 = new ComputeImage("23456", "image2", new Uri("http://someuri.com/v2/images/23456"), new Uri("http://someuri.com/images/23456"), new Dictionary(), "active", DateTime.Now, DateTime.Now, 10, 512, 100);
- var images = new List() { img1, img2 };
-
- this.ServicePocoClient.GetImagesDelegate = () => Task.Factory.StartNew(() => (IEnumerable)images);
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var resp = await client.GetImages();
- Assert.IsNotNull(resp);
-
- var respImage = resp.ToList();
- Assert.AreEqual(2, respImage.Count());
- Assert.AreEqual(img1, respImage[0]);
- Assert.AreEqual(img2, respImage[1]);
- }
-
- [TestMethod]
- public async Task CanGetImage()
- {
- var img1 = new ComputeImage("12345", "image1", new Uri("http://someuri.com/v2/images/12345"), new Uri("http://someuri.com/images/12345"), new Dictionary(), "active", DateTime.Now, DateTime.Now, 10, 512, 100);
-
- this.ServicePocoClient.GetImageDelegate = (id) =>
- {
- Assert.AreEqual("12345", id);
- return Task.Factory.StartNew(() => img1);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var image = await client.GetImage("12345");
-
- Assert.IsNotNull(image);
- Assert.AreEqual(img1, image);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetImageWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetImage(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetImageWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetImage(string.Empty);
- }
-
- [TestMethod]
- public async Task CanDeleteImage()
- {
- this.ServicePocoClient.DeleteImageDelegate = async (imageId) =>
- {
- await Task.Run(() => Assert.AreEqual(imageId, "12345"));
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImage("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteImageWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImage(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteImageWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImage(string.Empty);
- }
-
- [TestMethod]
- public async Task CanGetImageMetadata()
- {
- var meta = new Dictionary() { { "item1", "value1" } };
-
- this.ServicePocoClient.GetImageMetadataDelegate = (id) =>
- {
- Assert.AreEqual("12345", id);
- return Task.Factory.StartNew(() => (IDictionary)meta);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var metadata = await client.GetImageMetadata("12345");
-
- Assert.IsNotNull(metadata);
- Assert.AreEqual(meta, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetImageMetadataWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetImageMetadata(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetImageMetadataWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetImageMetadata(string.Empty);
- }
-
- [TestMethod]
- public async Task CanDeleteImageMetadata()
- {
- this.ServicePocoClient.DeleteImageMetadataDelegate = async (imageId, key) =>
- {
- await Task.Run(() =>
- {
- Assert.AreEqual(imageId, "12345");
- Assert.AreEqual(key, "item1");
- });
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImageMetadata("12345", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteImageMetadataWithNullImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImageMetadata(null, "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteImageMetadataWithEmptyImageIdThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImageMetadata(string.Empty, "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task DeleteImageMetadataWithEmptyKeyThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImageMetadata("12345", string.Empty);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task DeleteImageMetadataWithNullKeyThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.DeleteImageMetadata("12345", null);
- }
-
- [TestMethod]
- public async Task CanUpdateImageMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- this.ServicePocoClient.UpdateImageMetadataDelegate = async (imageId, meta) =>
- {
- await Task.Run(() =>
- {
- Assert.AreEqual(imageId, "12345");
- Assert.AreEqual(metadata, meta);
- });
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateImageMetadata("12345", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task UpdateImageMetadataWithNullImageIdThrows()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateImageMetadata(null, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task UpdateImageMetadataWithEmptyImageIdThrows()
- {
- var metadata = new Dictionary() { { "item1", "value1" } };
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateImageMetadata(string.Empty, metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task UpdateImageMetadataWithNullMetadataThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.UpdateImageMetadata("12345", null);
- }
-
- [TestMethod]
- public async Task CanGetKeyPairs()
- {
- var expKeyPair1 = new ComputeKeyPair("1", "ABCDEF","12345");
- var expKeyPair2 = new ComputeKeyPair("2", "FEDCBA", "54321");
- var pairs = new List() { expKeyPair1, expKeyPair2 };
-
- this.ServicePocoClient.GetKeyPairsDelegate = () => Task.Factory.StartNew(() => (IEnumerable)pairs);
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var resp = await client.GetKeyPairs();
- Assert.IsNotNull(resp);
-
- var respPairs = resp.ToList();
- Assert.AreEqual(2, respPairs.Count());
- Assert.AreEqual(expKeyPair1, respPairs[0]);
- Assert.AreEqual(expKeyPair2, respPairs[1]);
- }
-
- [TestMethod]
- public async Task CanGetKeyPair()
- {
- var keyName = "1";
- var expKeyPair1 = new ComputeKeyPair(keyName, "ABCDEF", "12345");
-
- this.ServicePocoClient.GetKeyPairDelegate = (name) =>
- {
- Assert.AreEqual(keyName, name);
- return Task.Factory.StartNew(() => expKeyPair1);
- };
-
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- var keyPair = await client.GetKeyPair(keyName);
-
- Assert.IsNotNull(keyPair);
- Assert.AreEqual(expKeyPair1, keyPair);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public async Task GetKeyPairWithNullNameThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetKeyPair(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public async Task GetKeyPairWithEmptyNameThrows()
- {
- var client = new ComputeServiceClient(GetValidCreds(), "Nova", CancellationToken.None, this.ServiceLocator);
- await client.GetKeyPair(string.Empty);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeServicePocoClientTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeServicePocoClientTests.cs
deleted file mode 100644
index 2578912..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeServicePocoClientTests.cs
+++ /dev/null
@@ -1,1599 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Text;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Compute;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeServicePocoClientTests
- {
- internal TestComputeServiceRestClient ComputeServiceRestClient;
- internal string authId = "12345";
- internal Uri endpoint = new Uri("http://testcomputeendpoint.com/v1/1234567890");
- internal IServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.ComputeServiceRestClient = new TestComputeServiceRestClient();
- this.ServiceLocator = new ServiceLocator();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IComputeServiceRestClientFactory), new TestComputeServiceRestClientFactory(ComputeServiceRestClient));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.ComputeServiceRestClient = new TestComputeServiceRestClient();
- this.ServiceLocator = new ServiceLocator();
- }
-
- ServiceClientContext GetValidContext()
- {
- var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
- creds.SetAccessTokenId(this.authId);
-
- return new ServiceClientContext(creds, CancellationToken.None, "Object Storage", endpoint);
- }
-
- private string GenerateMetadataPayload(IDictionary metadata)
- {
- var payload = new StringBuilder();
- payload.Append("{ \"metadata\" : {");
- var isFirst = true;
-
- foreach (var item in metadata)
- {
- if (!isFirst)
- {
- payload.Append(",");
- }
-
- payload.AppendFormat("\"{0}\":\"{1}\"", item.Key, item.Value);
- isFirst = false;
- }
-
- payload.Append("}}");
- return payload.ToString();
- }
-
- private IDictionary ParseMetadataPayload(string payload)
- {
- var jObj = JObject.Parse(payload);
- var metaToken = jObj["metadata"];
- return JsonConvert.DeserializeObject>(metaToken.ToString());
- }
-
- #region Get Compute Flavor Tests
-
- [TestMethod]
- public async Task CanGetComputeFlavorWithOkResponse()
- {
- var payload = @"{
- ""flavor"": {
- ""name"": ""m1.tiny"",
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"" : 512,
- ""vcpus"": 2,
- ""disk"": 10
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetFlavor("1");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("m1.tiny", result.Name);
- Assert.AreEqual("1", result.Id);
- Assert.AreEqual("512", result.Ram);
- Assert.AreEqual("2", result.Vcpus);
- Assert.AreEqual("10", result.Disk);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), result.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), result.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeFlavorWithNonAuthoritativeResponse()
- {
- var payload = @"{
- ""flavor"": {
- ""name"": ""m1.tiny"",
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""ram"" : 512,
- ""vcpus"": 2,
- ""disk"": 10
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetFlavor("1");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("m1.tiny", result.Name);
- Assert.AreEqual("1", result.Id);
- Assert.AreEqual("512", result.Ram);
- Assert.AreEqual("2", result.Vcpus);
- Assert.AreEqual("10", result.Disk);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), result.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), result.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeFlavorWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavor("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeFlavorAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavor("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeFlavorAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavor("1");
- }
-
- #endregion
-
- #region Get Compute Flavors Tests
-
- [TestMethod]
- public async Task CanGetComputeFlavorsWithOkResponse()
- {
- var payload = @"{
- ""flavors"": [
- {
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""name"": ""m1.tiny""
- }
- ]
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetFlavors();
-
- Assert.IsNotNull(result);
-
- var flavors = result.ToList();
- Assert.AreEqual(1, flavors.Count());
-
- var flavor = flavors.First();
- Assert.AreEqual("m1.tiny", flavor.Name);
- Assert.AreEqual("1", flavor.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeFlavorsWithNonAuthoritativeResponse()
- {
- var payload = @"{
- ""flavors"": [
- {
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/flavors/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/flavors/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""name"": ""m1.tiny""
- }
- ]
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetFlavors();
-
- Assert.IsNotNull(result);
-
- var flavors = result.ToList();
- Assert.AreEqual(1, flavors.Count());
-
- var flavor = flavors.First();
- Assert.AreEqual("m1.tiny", flavor.Name);
- Assert.AreEqual("1", flavor.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/flavors/1"), flavor.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/flavors/1"), flavor.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeFlavorsWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavors();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeFlavorsAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavors();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeFlavorsAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetFlavors();
- }
-
- #endregion
-
- #region Get Compute Server Metadata Tests
-
- [TestMethod]
- public async Task CanGetComputeServerMetadataWithNonAuthoritativeResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var content = TestHelper.CreateStream(GenerateMetadataPayload(metadata));
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var respData = await client.GetServerMetadata("1");
-
- Assert.AreEqual(2, respData.Count);
- Assert.AreEqual("value1", respData["item1"]);
- Assert.AreEqual("value2", respData["item2"]);
- }
-
- [TestMethod]
- public async Task CanGetComputeServerMetadataWithOkResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var content = TestHelper.CreateStream(GenerateMetadataPayload(metadata));
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var respData = await client.GetServerMetadata("1");
-
- Assert.AreEqual(2, respData.Count);
- Assert.AreEqual("value1", respData["item1"]);
- Assert.AreEqual("value2", respData["item2"]);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeServerMetadataAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServerMetadata("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeServerMetadataAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServerMetadata("12345");
- }
-
- #endregion
-
- #region Create Compute Server Tests
-
- [TestMethod]
- public async Task CanCreateComputeServerWithAcceptedResponse()
- {
- var serverId = "98765";
- var keyName = "MyKey";
- var publicUrl = "http://15.125.87.81:8774/v2/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
- var permUrl = "http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
- var adminPassword = "ABCDEF";
- var serverFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{3}""
- }}
- }}";
-
- var payload = string.Format(serverFixture, serverId, publicUrl, permUrl, adminPassword);
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.Accepted);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.CreateServer("MyServer", "12345", "1", "54321", keyName, new List() { "MyGroup" });
-
- Assert.IsNotNull(result);
-
- Assert.AreEqual(serverId, result.Id);
- Assert.AreEqual(adminPassword, result.AdminPassword);
- Assert.AreEqual(new Uri(publicUrl), result.PublicUri);
- Assert.AreEqual(new Uri(permUrl), result.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanCreateComputeServerWithOkResponse()
- {
- var serverId = "98765";
- var keyName = "MyKey";
- var publicUrl = "http://15.125.87.81:8774/v2/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
- var permUrl = "http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/servers/" + serverId;
- var adminPassword = "ABCDEF";
- var serverFixture = @"{{
- ""server"": {{
- ""security_groups"": [
- {{
- ""name"": ""default""
- }},
- {{
- ""name"": ""MyGroup""
- }}
- ],
- ""OS-DCF:diskConfig"": ""MANUAL"",
- ""id"": ""{0}"",
- ""links"": [
- {{
- ""href"": ""{1}"",
- ""rel"": ""self""
- }},
- {{
- ""href"": ""{2}"",
- ""rel"": ""bookmark""
- }}
- ],
- ""adminPass"": ""{3}""
- }}
- }}";
-
- var payload = string.Format(serverFixture, serverId, publicUrl, permUrl, adminPassword);
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.CreateServer("MyServer", "12345", "1", "54321", keyName, new List() { "MyGroup" });
-
- Assert.IsNotNull(result);
-
- Assert.AreEqual(serverId, result.Id);
- Assert.AreEqual(adminPassword, result.AdminPassword);
- Assert.AreEqual(new Uri(publicUrl), result.PublicUri);
- Assert.AreEqual(new Uri(permUrl), result.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenCreatingAComputeServerAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", "1", "54321", string.Empty, new List() { "MyGroup" });
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenCreatingAComputeServerAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.CreateServer("MyServer", "12345", "1", "54321", string.Empty, new List() { "MyGroup" });
- }
-
- #endregion
-
- #region Delete Compute Server Tests
-
- [TestMethod]
- public async Task CanDeleteComputeServerWithOkResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(),
- HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServer("12345");
- }
-
- [TestMethod]
- public async Task CanDeleteComputeServerWithNoContentResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(),
- HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServer("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingAComputeServerAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServer("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingAComputeServerAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServer("12345");
- }
-
- #endregion
-
- #region Get Compute Servers Tests
-
- public string ServersPayload = @"{
- ""servers"": [
- {
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/servers/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/servers/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""name"": ""server1""
- }
- ]
- }";
-
- [TestMethod]
- public async Task CanGetComputeServersWithOkResponse()
- {
- var content = TestHelper.CreateStream(ServersPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetServers();
-
- Assert.IsNotNull(result);
-
- var servers = result.ToList();
- Assert.AreEqual(1, servers.Count());
-
- var server = servers.First();
- Assert.AreEqual("server1", server.Name);
- Assert.AreEqual("1", server.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/servers/1"), server.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/servers/1"), server.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeServersWithNonAuthoritativeResponse()
- {
- var content = TestHelper.CreateStream(ServersPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetServers();
-
- Assert.IsNotNull(result);
-
- var servers = result.ToList();
- Assert.AreEqual(1, servers.Count());
-
- var server = servers.First();
- Assert.AreEqual("server1", server.Name);
- Assert.AreEqual("1", server.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/servers/1"), server.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/servers/1"), server.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeServersWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServers();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeServersAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServers();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeServersAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServers();
- }
-
- #endregion
-
- #region Get Compute Server Tests
-
- public string ServerPayload = @"{
- ""server"": {
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-11T18:04:46Z"",
- ""hostId"": ""bd5417ccb076908f6e0d639c37c053b0b6b9681db3464d19908dd4d9"",
- ""addresses"": {
- ""private"": [
- {
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""10.0.0.2"",
- ""OS-EXT-IPS:type"": ""fixed""
- },
- {
- ""OS-EXT-IPS-MAC:mac_addr"": ""fa:16:3e:34:da:44"",
- ""version"": 4,
- ""addr"": ""172.24.4.3"",
- ""OS-EXT-IPS:type"": ""floating""
- }
- ]
- },
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/servers/1"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/servers/1"",
- ""rel"": ""bookmark""
- }
- ],
- ""key_name"": null,
- ""image"": {
- ""id"": ""c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""links"": [
- {
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/images/c650e788-3c46-4efc-bfa6-1d94a14d6405"",
- ""rel"": ""bookmark""
- }
- ]
- },
- ""OS-EXT-STS:task_state"": null,
- ""OS-EXT-STS:vm_state"": ""active"",
- ""OS-SRV-USG:launched_at"": ""2014-06-11T18:04:45.000000"",
- ""flavor"": {
- ""id"": ""1"",
- ""links"": [
- {
- ""href"": ""http://15.125.87.81:8774/ffe683d1060449d09dac0bf9d7a371cd/flavors/1"",
- ""rel"": ""bookmark""
- }
- ]
- },
- ""id"": ""1"",
- ""security_groups"": [
- {
- ""name"": ""MyGroup""
- },
- {
- ""name"": ""default""
- }
- ],
- ""OS-SRV-USG:terminated_at"": null,
- ""OS-EXT-AZ:availability_zone"": ""nova"",
- ""user_id"": ""70d48d344b494a1cbe8adbf7c02be7b5"",
- ""name"": ""wfoley1"",
- ""created"": ""2014-06-11T18:04:25Z"",
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""OS-DCF:diskConfig"": ""AUTO"",
- ""os-extended-volumes:volumes_attached"": [],
- ""accessIPv4"": """",
- ""accessIPv6"": """",
- ""progress"": 0,
- ""OS-EXT-STS:power_state"": 1,
- ""config_drive"": """",
- ""metadata"": {}
- }
- }";
-
- [TestMethod]
- public async Task CanGetComputeServerWithOkResponse()
- {
- var content = TestHelper.CreateStream(ServerPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetServer("1");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("wfoley1", result.Name);
- Assert.AreEqual("1", result.Id);
- Assert.AreEqual(ComputeServerStatus.Active, result.Status);
- Assert.AreEqual(0, result.Progress);
- Assert.AreEqual(new Uri("http://someuri.com/v2/servers/1"), result.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/servers/1"), result.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeServerWithNonAuthoritativeResponse()
- {
- var content = TestHelper.CreateStream(ServerPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetServer("1");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("wfoley1", result.Name);
- Assert.AreEqual("1", result.Id);
- Assert.AreEqual(ComputeServerStatus.Active, result.Status);
- Assert.AreEqual(0, result.Progress);
- Assert.AreEqual(new Uri("http://someuri.com/v2/servers/1"), result.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/servers/1"), result.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeServerWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServer("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeServerAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServer("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeServerAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetServer("1");
- }
-
- #endregion
-
- #region Assign Floating IP Tests
-
- [TestMethod]
- public async Task CanAssignFloatingIpWithOkResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.AssignFloatingIp("12345", "172.0.0.1");
- }
-
- [TestMethod]
- public async Task CanDAssignFloatingIpWithAcceptedResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Accepted);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.AssignFloatingIp("12345", "172.0.0.1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenAssigningAFloatingIpAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.AssignFloatingIp("12345", "172.0.0.1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhennAssigningAFloatingIpAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.AssignFloatingIp("12345", "172.0.0.1");
- }
-
- #endregion
-
- #region Update Compute Server Metadata Tests
-
- [TestMethod]
- public async Task CanUpdateComputeServerMetadataWithOkResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateServerMetadata("1", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenUpdatingComputeServerMetadataAndNotAuthed()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateServerMetadata("12345", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenUpdatingComputeServerMetadataAndServerError()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateServerMetadata("12345", metadata);
- }
-
- #endregion
-
- #region Delete Compute Server Metadata Tests
-
- [TestMethod]
- public async Task CanDeleteComputeServerMetadataWithNoContentResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServerMetadata("1", "item1");
- }
-
- [TestMethod]
- public async Task CanDeleteComputeServerMetadataWithOkResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServerMetadata("1", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingComputeServerMetadataAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServerMetadata("1", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingComputeServerMetadataAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteServerMetadata("1", "item1");
- }
-
- #endregion
-
- #region Get Compute Image Tests
-
- [TestMethod]
- public async Task CanGetComputeImageWithOkResponse()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var payload = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minRam"": 512,
- ""minDisk"": 10,
- ""progress"": 100,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetImage("12345");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("image1", result.Name);
- Assert.AreEqual("ACTIVE", result.Status);
- Assert.AreEqual("12345", result.Id);
- Assert.AreEqual(512, result.MinimumRamSize);
- Assert.AreEqual(10, result.MinimumDiskSize);
- Assert.AreEqual(100, result.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), result.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), result.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), result.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), result.PublicUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeImageWithNonAuthoritativeResponse()
- {
- var created = DateTime.Parse("2014-05-30T16:56:32Z").ToUniversalTime();
- var updated = DateTime.Parse("2014-06-30T16:56:32Z").ToUniversalTime();
- var payload = @"{
- ""image"" : {
- ""name"": ""image1"",
- ""status"": ""ACTIVE"",
- ""updated"": ""2014-06-30T16:56:32Z"",
- ""created"": ""2014-05-30T16:56:32Z"",
- ""minRam"": 512,
- ""minDisk"": 10,
- ""progress"": 100,
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""id"": ""12345""
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetImage("12345");
-
- Assert.IsNotNull(result);
- Assert.AreEqual("image1", result.Name);
- Assert.AreEqual("ACTIVE", result.Status);
- Assert.AreEqual("12345", result.Id);
- Assert.AreEqual(512, result.MinimumRamSize);
- Assert.AreEqual(10, result.MinimumDiskSize);
- Assert.AreEqual(100, result.UploadProgress);
- Assert.AreEqual(created.ToLongTimeString(), result.CreateDate.ToLongTimeString());
- Assert.AreEqual(updated.ToLongTimeString(), result.LastUpdated.ToLongTimeString());
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), result.PermanentUri);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), result.PublicUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeImageWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImage("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeImageAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImage("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeImageAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImage("1");
- }
-
- #endregion
-
- #region Get Compute Images Tests
-
- [TestMethod]
- public async Task CanGetComputeImagesWithOkResponse()
- {
- var payload = @"{
- ""images"": [
- {
- ""id"": ""12345"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""name"": ""image1""
- }
- ]
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetImages();
-
- Assert.IsNotNull(result);
-
- var images = result.ToList();
- Assert.AreEqual(1, images.Count());
-
- var image = images.First();
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- }
-
- [TestMethod]
- public async Task CanGetComputeImagesWithNonAuthoritativeResponse()
- {
- var payload = @"{
- ""images"": [
- {
- ""id"": ""12345"",
- ""links"": [
- {
- ""href"": ""http://someuri.com/v2/images/12345"",
- ""rel"": ""self""
- },
- {
- ""href"": ""http://someuri.com/images/12345"",
- ""rel"": ""bookmark""
- }
- ],
- ""name"": ""image1""
- }
- ]
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetImages();
-
- Assert.IsNotNull(result);
-
- var images = result.ToList();
- Assert.AreEqual(1, images.Count());
-
- var image = images.First();
- Assert.AreEqual("image1", image.Name);
- Assert.AreEqual("12345", image.Id);
- Assert.AreEqual(new Uri("http://someuri.com/v2/images/12345"), image.PublicUri);
- Assert.AreEqual(new Uri("http://someuri.com/images/12345"), image.PermanentUri);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeImagesWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImages();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeImagesAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImages();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeImagesAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImages();
- }
-
- #endregion
-
- #region Delete Compute Image Tests
-
- [TestMethod]
- public async Task CanDeleteComputeImageWithNoContentResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImage("12345");
- }
-
- [TestMethod]
- public async Task CanDeleteComputeImageWithOkResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImage("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingAComputeImageAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImage("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingAComputeImageAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImage("12345");
- }
-
- #endregion
-
- #region Get Compute Image Metadata Tests
-
- [TestMethod]
- public async Task CanGetComputeImageMetadataWithNonAuthoritativeResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var content = TestHelper.CreateStream(GenerateMetadataPayload(metadata));
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var respData = await client.GetImageMetadata("12345");
-
- Assert.AreEqual(2, respData.Count);
- Assert.AreEqual("value1", respData["item1"]);
- Assert.AreEqual("value2", respData["item2"]);
- }
-
- [TestMethod]
- public async Task CanGetComputeImageMetadataWithOkResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var content = TestHelper.CreateStream(GenerateMetadataPayload(metadata));
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var respData = await client.GetImageMetadata("12345");
-
- Assert.AreEqual(2, respData.Count);
- Assert.AreEqual("value1", respData["item1"]);
- Assert.AreEqual("value2", respData["item2"]);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeImageMetadataAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImageMetadata("12345");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeImageMetadataAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetImageMetadata("12345");
- }
-
- #endregion
-
- #region Update Compute Image Metadata Tests
-
- [TestMethod]
- public async Task CanUpdateComputeImageMetadataWithOkResponse()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateImageMetadata("12345", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenUpdatingComputeImageMetadataAndNotAuthed()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateImageMetadata("12345", metadata);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenUpdatingComputeImageMetadataAndServerError()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.UpdateImageMetadata("12345", metadata);
- }
-
- #endregion
-
- #region Delete Compute Image Metadata Tests
-
- [TestMethod]
- public async Task CanDeleteComputeImageMetadataWithNoContentResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImageMetadata("12345", "item1");
- }
-
- [TestMethod]
- public async Task CanDeleteComputeImageMetadataWithOkResponse()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImageMetadata("1", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingComputeImageMetadataAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImageMetadata("1", "item1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenDeletingComputeImageMetadataAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.DeleteImageMetadata("1", "item1");
- }
-
- #endregion
-
- #region Get Compute Key Pairs Tests
-
- public string KeyPairsPayload = @"{
- ""keypairs"": [
- {
- ""keypair"": {
- ""public_key"": ""ABCDEF"",
- ""name"": ""MyKey"",
- ""fingerprint"": ""12345""
- }
- }
- ]
- }";
-
- [TestMethod]
- public async Task CanGetComputeKeyPairsWithOkResponse()
- {
- var content = TestHelper.CreateStream(KeyPairsPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetKeyPairs();
-
- Assert.IsNotNull(result);
-
- var pairs = result.ToList();
- Assert.AreEqual(1, pairs.Count());
-
- var keyPair = pairs.First();
- Assert.AreEqual("MyKey", keyPair.Name);
- Assert.AreEqual("ABCDEF", keyPair.PublicKey);
- Assert.AreEqual("12345", keyPair.Fingerprint);
- }
-
- [TestMethod]
- public async Task CanGetComputeKeyPairsWithNonAuthoritativeResponse()
- {
- var content = TestHelper.CreateStream(KeyPairsPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var result = await client.GetKeyPairs();
-
- Assert.IsNotNull(result);
-
- var pairs = result.ToList();
- Assert.AreEqual(1, pairs.Count());
-
- var keyPair = pairs.First();
- Assert.AreEqual("MyKey", keyPair.Name);
- Assert.AreEqual("ABCDEF", keyPair.PublicKey);
- Assert.AreEqual("12345", keyPair.Fingerprint);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeKeyPairsWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPairs();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeKeyPairsAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPairs();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingComputeKeyPairsAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPairs();
- }
-
- #endregion
-
- #region Get Compute Key Pair Tests
-
- public string KeyPairPayload = @"{
- ""keypair"": {
- ""public_key"": ""ABCDEF"",
- ""user_id"": ""70d48d344b494a1cbe8adbf7c02be7b5"",
- ""name"": ""MyKey"",
- ""deleted"": false,
- ""created_at"": ""2014-08-11T21:15:53.000000"",
- ""updated_at"": null,
- ""fingerprint"": ""12345"",
- ""deleted_at"": null,
- ""id"": 1
- }
- }";
-
- [TestMethod]
- public async Task CanGetComputeKeyPairWithOkResponse()
- {
- var content = TestHelper.CreateStream(KeyPairPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var keyPair = await client.GetKeyPair("MyKey");
-
- Assert.IsNotNull(keyPair);
- Assert.AreEqual("MyKey", keyPair.Name);
- Assert.AreEqual("ABCDEF", keyPair.PublicKey);
- Assert.AreEqual("12345", keyPair.Fingerprint);
- }
-
- [TestMethod]
- public async Task CanGetComputeKeyPairWithNonAuthoritativeResponse()
- {
- var content = TestHelper.CreateStream(KeyPairPayload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- var keyPair = await client.GetKeyPair("MyKey");
-
- Assert.IsNotNull(keyPair);
- Assert.AreEqual("MyKey", keyPair.Name);
- Assert.AreEqual("ABCDEF", keyPair.PublicKey);
- Assert.AreEqual("12345", keyPair.Fingerprint);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotGetComputeKeyPairWithNoContent()
- {
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPair("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeKeyPairAndNotAuthed()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPair("1");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task ExceptionthrownWhenGettingAComputeKeyPairAndServerError()
- {
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.ComputeServiceRestClient.Responses.Enqueue(restResp);
-
- var client = new ComputeServicePocoClient(GetValidContext(), this.ServiceLocator);
- await client.GetKeyPair("1");
- }
-
- #endregion
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/ComputeServiceRestClientTests.cs b/OpenStack/OpenStack.Test/Compute/ComputeServiceRestClientTests.cs
deleted file mode 100644
index 5416531..0000000
--- a/OpenStack/OpenStack.Test/Compute/ComputeServiceRestClientTests.cs
+++ /dev/null
@@ -1,1134 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Compute;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Compute
-{
- [TestClass]
- public class ComputeServiceRestClientTests
- {
- internal ComputeRestSimulator simulator;
- internal string authId = "12345";
- internal Uri endpoint = new Uri("http://testcomputeendpoint.com/v2/1234567890");
- internal IServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.simulator = new ComputeRestSimulator();
- this.ServiceLocator = new ServiceLocator();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IHttpAbstractionClientFactory), new ComputeRestSimulatorFactory(simulator));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.simulator = new ComputeRestSimulator();
- this.ServiceLocator = new ServiceLocator();
- }
-
- ServiceClientContext GetValidContext()
- {
- return GetValidContext(CancellationToken.None);
- }
-
- ServiceClientContext GetValidContext(CancellationToken token)
- {
- var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
- creds.SetAccessTokenId(this.authId);
-
- return new ServiceClientContext(creds, token, "Nova", endpoint);
- }
-
- #region Get Flavors Test
-
- [TestMethod]
- public async Task GetComputeFlavorsIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetFlavors();
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeFlavorsFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetFlavors();
-
- Assert.AreEqual(string.Format("{0}/flavors", endpoint), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetFlavors()
- {
- this.simulator.Flavors.Add(new ComputeFlavor("1", "tiny", "4", "2", "10", new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"), new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), new Dictionary()));
-
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetFlavors();
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Get Flavor Test
-
- [TestMethod]
- public async Task GetComputeFlavorIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetFlavor("1");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeFlavorFormsCorrectUrlAndMethod()
- {
- var flavorId = "1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetFlavor(flavorId);
-
- Assert.AreEqual(string.Format("{0}/flavors/{1}", endpoint, flavorId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetFlavor()
- {
- var flavorId = "1";
- this.simulator.Flavors.Add(new ComputeFlavor(flavorId, "tiny", "4", "2", "10", new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"), new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), new Dictionary()));
-
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetFlavor(flavorId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Get Server Metadata Test
-
- [TestMethod]
- public async Task GetComputeServerMetadataIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServerMetadata("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeServerMetadataFormsCorrectUrlAndMethod()
- {
- var serverId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServerMetadata(serverId);
-
- Assert.AreEqual(string.Format("{0}/servers/{1}/metadata", endpoint, serverId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetServerMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var serverId = "1";
- this.simulator.Servers.Add(new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), metadata));
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetServerMetadata(serverId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
-
- var jObj = JObject.Parse(respContent);
- var metaToken = jObj["metadata"];
- Assert.IsNotNull(metaToken);
-
- var item1 = metaToken["item1"];
- Assert.IsNotNull(item1);
- Assert.AreEqual("value1", item1.Value());
-
- var item2 = metaToken["item2"];
- Assert.IsNotNull(item2);
- Assert.AreEqual("value2", item2.Value());
- }
-
- #endregion
-
- #region Create Server Test
-
- [TestMethod]
- public async Task CreateComputeServerIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.CreateServer("MyServer", "1245", "2", "54321", "key", new List() { "MyGroup" });
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task CreateComputeServerIncludesContentTypeHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.CreateServer("MyServer", "1245", "2", "54321", "key", new List() { "MyGroup" });
-
- Assert.IsTrue(this.simulator.ContentType != string.Empty);
- Assert.AreEqual("application/json", this.simulator.ContentType);
- }
-
- [TestMethod]
- public async Task CreateComputeServerFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.CreateServer("MyServer", "1245", "2", "54321", "key", new List() { "MyGroup" });
-
- Assert.AreEqual(string.Format("{0}/servers", endpoint), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanCreateComputeServer()
- {
-
- var srvName = "MyServer";
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.CreateServer(srvName, "1245", "2", "54321", string.Empty, new List() { "MyGroup" });
-
- Assert.AreEqual(HttpStatusCode.Accepted, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
-
- Assert.IsTrue(this.simulator.Servers.Count == 1);
-
- var resSrv = this.simulator.Servers.First();
- Assert.AreEqual(srvName, resSrv.Name);
- }
-
- [TestMethod]
- public async Task CanCreateComputeServerWithKeyName()
- {
-
- var srvName = "MyServer";
- var keyName = "MyKey";
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.CreateServer(srvName, "1245", "2", "54321", keyName, new List() { "MyGroup" });
-
- Assert.AreEqual(HttpStatusCode.Accepted, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
-
- Assert.IsTrue(this.simulator.Servers.Count == 1);
-
- var resSrv = this.simulator.Servers.First();
- Assert.AreEqual(srvName, resSrv.Name);
- }
-
- [TestMethod]
- public async Task CreateComputeServerWithKeyNameFormsCorrectBody()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var serverName = "MyServer";
- var keyName = "MyKey";
- var imageId = "12345";
- var flavorId = "2";
- var networkId = "54321";
- var secGroupName = "MyGroup";
-
- await client.CreateServer(serverName, imageId, flavorId, networkId, keyName, new List() { secGroupName });
-
- this.simulator.Content.Position = 0;
- var reqContent = TestHelper.GetStringFromStream(this.simulator.Content);
-
- var srvObj = JObject.Parse(reqContent);
- Assert.IsNotNull(srvObj["server"]);
- Assert.IsNotNull(srvObj["server"]["name"]);
- Assert.AreEqual(serverName, (string)srvObj["server"]["name"]);
-
- Assert.IsNotNull(srvObj["server"]["imageRef"]);
- Assert.AreEqual(imageId, (string)srvObj["server"]["imageRef"]);
-
- Assert.IsNotNull(srvObj["server"]["flavorRef"]);
- Assert.AreEqual(flavorId, (string)srvObj["server"]["flavorRef"]);
-
- Assert.IsNotNull(srvObj["server"]["max_count"]);
- Assert.AreEqual(1, (int)srvObj["server"]["max_count"]);
-
- Assert.IsNotNull(srvObj["server"]["min_count"]);
- Assert.AreEqual(1, (int)srvObj["server"]["min_count"]);
-
- Assert.IsNotNull(srvObj["server"]["key_name"]);
- Assert.AreEqual(keyName, (string)srvObj["server"]["key_name"]);
-
- Assert.IsNotNull(srvObj["server"]["networks"]);
- Assert.IsNotNull(srvObj["server"]["networks"][0]);
- Assert.IsNotNull(srvObj["server"]["networks"][0]["uuid"]);
- Assert.AreEqual(networkId, (string)srvObj["server"]["networks"][0]["uuid"]);
-
- Assert.IsNotNull(srvObj["server"]["security_groups"]);
- Assert.IsNotNull(srvObj["server"]["security_groups"][0]);
- Assert.IsNotNull(srvObj["server"]["security_groups"][0]["name"]);
- Assert.AreEqual(secGroupName, (string)srvObj["server"]["security_groups"][0]["name"]);
- }
-
- [TestMethod]
- public async Task CreateComputeServerFormsCorrectBody()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var serverName = "MyServer";
- var imageId = "12345";
- var flavorId = "2";
- var networkId = "54321";
- var secGroupName = "MyGroup";
-
- await client.CreateServer(serverName, imageId, flavorId, networkId, string.Empty, new List() { secGroupName });
-
- this.simulator.Content.Position = 0;
- var reqContent = TestHelper.GetStringFromStream(this.simulator.Content);
-
- var srvObj = JObject.Parse(reqContent);
- Assert.IsNotNull(srvObj["server"]);
- Assert.IsNotNull(srvObj["server"]["name"]);
- Assert.AreEqual(serverName, (string)srvObj["server"]["name"]);
-
- Assert.IsNotNull(srvObj["server"]["imageRef"]);
- Assert.AreEqual(imageId, (string)srvObj["server"]["imageRef"]);
-
- Assert.IsNotNull(srvObj["server"]["flavorRef"]);
- Assert.AreEqual(flavorId, (string)srvObj["server"]["flavorRef"]);
-
- Assert.IsNotNull(srvObj["server"]["max_count"]);
- Assert.AreEqual(1, (int)srvObj["server"]["max_count"]);
-
- Assert.IsNotNull(srvObj["server"]["min_count"]);
- Assert.AreEqual(1, (int)srvObj["server"]["min_count"]);
-
- Assert.IsNotNull(srvObj["server"]["networks"]);
- Assert.IsNotNull(srvObj["server"]["networks"][0]);
- Assert.IsNotNull(srvObj["server"]["networks"][0]["uuid"]);
- Assert.AreEqual(networkId, (string)srvObj["server"]["networks"][0]["uuid"]);
-
- Assert.IsNotNull(srvObj["server"]["security_groups"]);
- Assert.IsNotNull(srvObj["server"]["security_groups"][0]);
- Assert.IsNotNull(srvObj["server"]["security_groups"][0]["name"]);
- Assert.AreEqual(secGroupName, (string)srvObj["server"]["security_groups"][0]["name"]);
- }
-
- #endregion
-
- #region Get Servers Test
-
- [TestMethod]
- public async Task GetComputeServersIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServers();
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeServersFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServers();
-
- Assert.AreEqual(string.Format("{0}/servers", endpoint), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetServers()
- {
- var serverId = "12345";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- this.simulator.Servers.Add(server);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetServers();
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Get Server Test
-
- [TestMethod]
- public async Task GetComputeServerIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServer("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeServerFormsCorrectUrlAndMethod()
- {
- var serverId = "1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetServer(serverId);
-
- Assert.AreEqual(string.Format("{0}/servers/{1}", endpoint, serverId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetServer()
- {
- var serverId = "12345";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- this.simulator.Servers.Add(server);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetServer(serverId);
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Assign Floating Ip Test
-
- [TestMethod]
- public async Task AssignFloatingIpIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.AssignFloatingIp("12345", "172.0.0.1");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task AssignFloatingIpIncludesContentTypeHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.AssignFloatingIp("12345", "172.0.0.1");
-
- Assert.IsTrue(this.simulator.ContentType != string.Empty);
- Assert.AreEqual("application/json", this.simulator.ContentType);
- }
-
- [TestMethod]
- public async Task AssignFloatingIpFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
- var serverId = "12345";
- await client.AssignFloatingIp(serverId, "172.0.0.1");
-
- Assert.AreEqual(string.Format("{0}/servers/{1}/action", endpoint, serverId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanAssignFloatingIp()
- {
- var serverId = "12345";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- this.simulator.Servers.Add(server);
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.AssignFloatingIp(serverId, "172.0.0.1");
-
- Assert.AreEqual(HttpStatusCode.Accepted, resp.StatusCode);
- }
-
- [TestMethod]
- public async Task AssignFloatingIpFormsCorrectBody()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var serverId = "12345";
- var ipAddress = "172.0.0.1";
-
- await client.AssignFloatingIp(serverId, ipAddress);
-
- this.simulator.Content.Position = 0;
- var reqContent = TestHelper.GetStringFromStream(this.simulator.Content);
-
- var body = JObject.Parse(reqContent);
- Assert.IsNotNull(body["addFloatingIp"]);
- Assert.IsNotNull(body["addFloatingIp"]["address"]);
- Assert.AreEqual(ipAddress, (string)body["addFloatingIp"]["address"]);
- }
-
- #endregion
-
- #region Delete Server Test
-
- [TestMethod]
- public async Task DeleteComputeServerIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteServer("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task DeleteComputeServerFormsCorrectUrlAndMethod()
- {
- var serverId = "1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteServer(serverId);
-
- Assert.AreEqual(string.Format("{0}/servers/{1}", endpoint, serverId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Delete, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanDeleteServer()
- {
- var serverId = "12345";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- this.simulator.Servers.Add(server);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.DeleteServer(serverId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
- Assert.AreEqual(0, this.simulator.Servers.Count);
- }
-
- #endregion
-
- #region Update Server Metadata Test
-
- [TestMethod]
- public async Task UpdateComputeServerMetadataIncludesAuthHeader()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.UpdateServerMetadata("1", metadata);
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task UpdateComputeServerMetadataFormsCorrectUrlAndMethod()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var serverId = "1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.UpdateServerMetadata(serverId, metadata);
-
- Assert.AreEqual(string.Format("{0}/servers/{1}/metadata", endpoint, serverId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanUpdateServerMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var serverId = "1";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), new Dictionary());
- this.simulator.Servers.Add(server);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.UpdateServerMetadata(serverId, metadata);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- Assert.AreEqual(2, server.Metadata.Count);
- Assert.AreEqual("value1", server.Metadata["item1"]);
- Assert.AreEqual("value2", server.Metadata["item2"]);
- }
-
- #endregion
-
- #region Delete Server Metadata Test
-
- [TestMethod]
- public async Task DeleteComputeServerMetadataIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteServerMetadata("1", "item1");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task DeleteComputeServerMetadataFormsCorrectUrlAndMethod()
- {
- var serverId = "1";
- var key = "item1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteServerMetadata(serverId, key);
-
- Assert.AreEqual(string.Format("{0}/servers/{1}/metadata/{2}", endpoint, serverId, key), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Delete, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanDeleteServerMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var serverId = "1";
- var server = new ComputeServer(serverId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/servers/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/servers/1"), metadata);
- this.simulator.Servers.Add(server);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.DeleteServerMetadata(serverId, "item1");
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- Assert.AreEqual(1, server.Metadata.Count);
- Assert.AreEqual("value2", server.Metadata["item2"]);
- }
-
- #endregion
-
- #region Get Images Test
-
- [TestMethod]
- public async Task GetComputeImagesIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImages();
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeImagesFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImages();
-
- Assert.AreEqual(string.Format("{0}/images/detail", endpoint), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetImages()
- {
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- this.simulator.Images.Add(new ComputeImage("1", "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), new Dictionary(), "ACTIVE", created, updated, 10, 512, 100));
-
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetImages();
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Get Image Test
-
- [TestMethod]
- public async Task GetComputeImageIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImage("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeImageFormsCorrectUrlAndMethod()
- {
- var imageId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImage(imageId);
-
- Assert.AreEqual(string.Format("{0}/images/{1}", endpoint, imageId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetImage()
- {
- var imageId = "12345";
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- this.simulator.Images.Add(new ComputeImage(imageId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), new Dictionary(), "ACTIVE", created, updated, 10, 512, 100));
-
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetImage(imageId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Delete Image Test
-
- [TestMethod]
- public async Task DeleteComputeImageIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteImage("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task DeleteComputeImageFormsCorrectUrlAndMethod()
- {
- var imageId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteImage(imageId);
-
- Assert.AreEqual(string.Format("{0}/images/{1}", endpoint, imageId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Delete, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanDeleteImage()
- {
- var imageId = "12345";
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- this.simulator.Images.Add(new ComputeImage(imageId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), new Dictionary(), "ACTIVE", created, updated, 10, 512, 100));
-
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.DeleteImage(imageId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
- Assert.IsFalse(this.simulator.Images.Any());
- }
-
- #endregion
-
- #region Get Image Metadata Test
-
- [TestMethod]
- public async Task GetComputeImageMetadataIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImageMetadata("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeImageMetadataFormsCorrectUrlAndMethod()
- {
- var imageId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetImageMetadata(imageId);
-
- Assert.AreEqual(string.Format("{0}/images/{1}/metadata", endpoint, imageId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetImageMetadata()
- {
- var imageId = "12345";
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- this.simulator.Images.Add(new ComputeImage(imageId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/flavors/1"),
- new Uri("http://testcomputeendpoint.com/1234567890/flavors/1"), metadata, "ACTIVE", created, updated, 10, 512, 100));
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetImageMetadata(imageId);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
-
- var jObj = JObject.Parse(respContent);
- var metaToken = jObj["metadata"];
- Assert.IsNotNull(metaToken);
-
- var item1 = metaToken["item1"];
- Assert.IsNotNull(item1);
- Assert.AreEqual("value1",item1.Value());
-
- var item2 = metaToken["item2"];
- Assert.IsNotNull(item2);
- Assert.AreEqual("value2", item2.Value());
- }
-
- #endregion
-
- #region Update Image Metadata Test
-
- [TestMethod]
- public async Task UpdateComputeImageMetadataIncludesAuthHeader()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.UpdateImageMetadata("12345", metadata);
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task UpdateComputeImageMetadataFormsCorrectUrlAndMethod()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var imageId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.UpdateImageMetadata(imageId, metadata);
-
- Assert.AreEqual(string.Format("{0}/images/{1}/metadata", endpoint, imageId), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task UpdateComputeImageMetadataSetsCorrectContentType()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var imageId = "12345";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.UpdateImageMetadata(imageId, metadata);
-
- Assert.AreEqual("application/json",this.simulator.ContentType);
- }
-
- [TestMethod]
- public async Task CanUpdateImageMetadata()
- {
- var imageId = "12345";
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var image = new ComputeImage(imageId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/images/12345"),
- new Uri("http://testcomputeendpoint.com/1234567890/images/12345"), new Dictionary(),
- "ACTIVE", created, updated, 10, 512, 100);
- this.simulator.Images.Add(image);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.UpdateImageMetadata(imageId, metadata);
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- Assert.AreEqual(2,image.Metadata.Count);
- Assert.AreEqual("value1",image.Metadata["item1"]);
- Assert.AreEqual("value2", image.Metadata["item2"]);
- }
-
- #endregion
-
- #region Delete Image Metadata Test
-
- [TestMethod]
- public async Task DeleteComputeImageMetadataIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteImageMetadata("12345", "item1");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task DeleteComputeImageMetadataFormsCorrectUrlAndMethod()
- {
- var imageId = "12345";
- var key = "item1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.DeleteImageMetadata(imageId, key);
-
- Assert.AreEqual(string.Format("{0}/images/{1}/metadata/{2}", endpoint, imageId, key), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Delete, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanDeleteImageMetadata()
- {
- var metadata = new Dictionary() { { "item1", "value1" }, { "item2", "value2" } };
- var created = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(10));
- var updated = DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(1));
- var imageId = "12345";
- var image = new ComputeImage(imageId, "tiny",
- new Uri("http://testcomputeendpoint.com/v2/1234567890/images/12345"),
- new Uri("http://testcomputeendpoint.com/1234567890/images/12345"), metadata,
- "ACTIVE", created, updated, 10, 512, 100);
- this.simulator.Images.Add(image);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.DeleteImageMetadata(imageId, "item1");
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- Assert.AreEqual(1, image.Metadata.Count);
- Assert.AreEqual("value2", image.Metadata["item2"]);
- }
-
- #endregion
-
- #region Get Key Pairs Test
-
- [TestMethod]
- public async Task GetComputeKeyPairsIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetKeyPairs();
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeKeyPairsFormsCorrectUrlAndMethod()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetKeyPairs();
-
- Assert.AreEqual(string.Format("{0}/os-keypairs", endpoint), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetKeyPairs()
- {
- var keyPairName = "Key1";
- var keyPair = new ComputeKeyPair(keyPairName, "12345", "ABCDEF");
- this.simulator.KeyPairs.Add(keyPair);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetKeyPairs();
-
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
-
- #region Get Key Pair Test
-
- [TestMethod]
- public async Task GetComputeKeyPairIncludesAuthHeader()
- {
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetKeyPair("12345");
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
- Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
- }
-
- [TestMethod]
- public async Task GetComputeKeyPairFormsCorrectUrlAndMethod()
- {
- var keyPairName = "1";
- var client =
- new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- await client.GetKeyPair(keyPairName);
-
- Assert.AreEqual(string.Format("{0}/os-keypairs/{1}", endpoint, keyPairName), this.simulator.Uri.ToString());
- Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task CanGetKeyPair()
- {
- var keyPairName = "Key1";
- var keyPair = new ComputeKeyPair(keyPairName, "12345", "ABCDEF");
- this.simulator.KeyPairs.Add(keyPair);
-
- var client = new ComputeServiceRestClient(GetValidContext(), this.ServiceLocator);
-
- var resp = await client.GetKeyPair(keyPairName);
- Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
-
- var respContent = TestHelper.GetStringFromStream(resp.Content);
- Assert.IsTrue(respContent.Length > 0);
- }
-
- #endregion
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/TestComputeServicePocoClient.cs b/OpenStack/OpenStack.Test/Compute/TestComputeServicePocoClient.cs
deleted file mode 100644
index f3bb061..0000000
--- a/OpenStack/OpenStack.Test/Compute/TestComputeServicePocoClient.cs
+++ /dev/null
@@ -1,168 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Threading.Tasks;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- public class TestComputeServicePocoClient : IComputeServicePocoClient
- {
- public Func> GetFlavorDelegate { get; set; }
-
- public Func>> GetFlavorsDelegate { get; set; }
-
- public Func> GetImageDelegate { get; set; }
-
- public Func>> GetImagesDelegate { get; set; }
-
- public Func DeleteImageDelegate { get; set; }
-
- public Func, Task> CreateServerDelegate { get; set; }
-
- public Func DeleteServerDelegate { get; set; }
-
- public Func>> GetImageMetadataDelegate { get; set; }
-
- public Func, Task> UpdateImageMetadataDelegate { get; set; }
-
- public Func DeleteImageMetadataDelegate { get; set; }
-
- public Func>> GetServerMetadataDelegate { get; set; }
-
- public Func, Task> UpdateServerMetadataDelegate { get; set; }
-
- public Func DeleteServerMetadataDelegate { get; set; }
-
- public Func AssignFloatingIpDelegate { get; set; }
-
- public Func> GetServerDelegate { get; set; }
-
- public Func>> GetServersDelegate { get; set; }
-
- public Func> GetKeyPairDelegate { get; set; }
-
- public Func>> GetKeyPairsDelegate { get; set; }
-
- public async Task GetFlavor(string flavorId)
- {
- return await this.GetFlavorDelegate(flavorId);
- }
-
- public async Task> GetServerMetadata(string serverId)
- {
- return await this.GetServerMetadataDelegate(serverId);
- }
-
- public async Task UpdateServerMetadata(string serverId, IDictionary metadata)
- {
- await this.UpdateServerMetadataDelegate(serverId, metadata);
- }
-
- public async Task DeleteServerMetadata(string serverId, string key)
- {
- await this.DeleteServerMetadataDelegate(serverId, key);
- }
-
- public async Task> GetKeyPairs()
- {
- return await this.GetKeyPairsDelegate();
- }
-
- public async Task GetKeyPair(string keyPairName)
- {
- return await this.GetKeyPairDelegate(keyPairName);
- }
-
- public async Task> GetImages()
- {
- return await this.GetImagesDelegate();
- }
-
- public async Task GetImage(string imageId)
- {
- return await this.GetImageDelegate(imageId);
- }
-
- public async Task DeleteImage(string imageId)
- {
- await this.DeleteImageDelegate(imageId);
- }
-
- public async Task CreateServer(string name, string imageId, string flavorId, string networkId, string keyName, IEnumerable securityGroups)
- {
- return await this.CreateServerDelegate(name, imageId, flavorId, networkId, keyName, securityGroups);
- }
-
- public async Task DeleteServer(string serverId)
- {
- await this.DeleteServerDelegate(serverId);
- }
-
- public async Task> GetServers()
- {
- return await this.GetServersDelegate();
- }
-
- public async Task GetServer(string serverId)
- {
- return await this.GetServerDelegate(serverId);
- }
-
- public async Task AssignFloatingIp(string serverId, string ipAddress)
- {
- await this.AssignFloatingIpDelegate(serverId, ipAddress);
- }
-
- public async Task> GetImageMetadata(string flavorId)
- {
- return await this.GetImageMetadataDelegate(flavorId);
- }
-
- public async Task UpdateImageMetadata(string flavorId, IDictionary metadata)
- {
- await this.UpdateImageMetadataDelegate(flavorId, metadata);
- }
-
- public async Task DeleteImageMetadata(string flavorId, string key)
- {
- await this.DeleteImageMetadataDelegate(flavorId, key);
- }
-
- public async Task> GetFlavors()
- {
- return await this.GetFlavorsDelegate();
- }
- }
-
- public class TestComputeServicePocoClientFactory : IComputeServicePocoClientFactory
- {
- internal IComputeServicePocoClient client;
-
- public TestComputeServicePocoClientFactory(IComputeServicePocoClient client)
- {
- this.client = client;
- }
-
- public IComputeServicePocoClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
- {
- return client;
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Compute/TestComputeServiceRestClient.cs b/OpenStack/OpenStack.Test/Compute/TestComputeServiceRestClient.cs
deleted file mode 100644
index e35610c..0000000
--- a/OpenStack/OpenStack.Test/Compute/TestComputeServiceRestClient.cs
+++ /dev/null
@@ -1,147 +0,0 @@
-// /* ============================================================================
-// 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.Collections.Generic;
-using System.Threading.Tasks;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Compute;
-
-namespace OpenStack.Test.Compute
-{
- public class TestComputeServiceRestClient : IComputeServiceRestClient
- {
- public TestComputeServiceRestClient()
- {
- this.Responses = new Queue();
- }
-
- public Queue Responses { get; set; }
-
- public Task GetFlavors()
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetFlavor(string flavorId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task AssignFloatingIp(string serverId, string ipAddress)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetServerMetadata(string serverId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task UpdateServerMetadata(string serverId, IDictionary metadata)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task DeleteServerMetadata(string serverId, string key)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetKeyPairs()
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetKeyPair(string keyPairName)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetImages()
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetImage(string imageId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task DeleteImage(string imageId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetImageMetadata(string imageId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task UpdateImageMetadata(string imageId, IDictionary metadata)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task DeleteImageMetadata(string imageId, string key)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- ///
- public Task CreateServer(string name, string imageId, string flavorId, string networkId, IEnumerable securityGroups)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task CreateServer(string name, string imageId, string flavorId, string networkId, string keyName,
- IEnumerable securityGroups)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetServers()
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- public Task GetServer(string serverId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
-
- ///
- public Task DeleteServer(string serverId)
- {
- return Task.Factory.StartNew(() => Responses.Dequeue());
- }
- }
-
- public class TestComputeServiceRestClientFactory : IComputeServiceRestClientFactory
- {
- internal IComputeServiceRestClient Client;
-
- public TestComputeServiceRestClientFactory(IComputeServiceRestClient client)
- {
- this.Client = client;
- }
-
- public IComputeServiceRestClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
- {
- return Client;
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Helper.cs b/OpenStack/OpenStack.Test/Helper.cs
deleted file mode 100644
index b604c10..0000000
--- a/OpenStack/OpenStack.Test/Helper.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-// /* ============================================================================
-// 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.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Text;
-using OpenStack.Common.Http;
-
-namespace OpenStack.Test
-{
- public static class TestHelper
- {
- public static MemoryStream CreateStream(string input)
- {
- byte[] byteArray = Encoding.ASCII.GetBytes(input);
- return new MemoryStream(byteArray);
- }
-
- public static string GetStringFromStream(Stream input)
- {
- var reader = new StreamReader(input);
- return reader.ReadToEnd();
- }
-
- public static IHttpResponseAbstraction CreateErrorResponse()
- {
- return new HttpResponseAbstraction(null, new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- }
-
- public static IHttpResponseAbstraction CreateResponse(HttpStatusCode code)
- {
- return new HttpResponseAbstraction(null, new HttpHeadersAbstraction(), code);
- }
-
- public static IHttpResponseAbstraction CreateResponse(HttpStatusCode code, IEnumerable> headers)
- {
- var abstractionHeaders = new HttpHeadersAbstraction();
- foreach (var header in headers)
- {
- abstractionHeaders.Add(header.Key, header.Value);
- }
- return new HttpResponseAbstraction(null, abstractionHeaders, code);
- }
-
- public static IHttpResponseAbstraction CreateResponse(HttpStatusCode code, IEnumerable> headers, Stream content)
- {
- var abstractionHeaders = new HttpHeadersAbstraction();
- foreach (var header in headers)
- {
- abstractionHeaders.Add(header.Key, header.Value);
- }
- return new HttpResponseAbstraction(content, abstractionHeaders, code);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs b/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs
deleted file mode 100644
index 96a67d5..0000000
--- a/OpenStack/OpenStack.Test/HttpAbstraction/HttpAbstractionClientTests.cs
+++ /dev/null
@@ -1,305 +0,0 @@
-// /* ============================================================================
-// 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 System.Linq;
-using System.Net;
-using System.Net.Http;
-using System.Threading;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common.Http;
-
-namespace OpenStack.Test.HttpAbstraction
-{
- [TestClass]
- public class HttpAbstractionClientTests
- {
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakeGetRequest()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- client.Uri = new Uri("http://httpbin.org/get");
- client.Method = HttpMethod.Get;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- Assert.IsNotNull(response.Content);
- var content = TestHelper.GetStringFromStream(response.Content);
- Assert.AreNotEqual(0, content.Length);
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void ResponsesIncludeContentHeaders()
- {
- using (var client = new HttpAbstractionClientFactory().Create(new TimeSpan(0, 5, 0), CancellationToken.None))
- {
- client.Uri = new Uri("http://httpbin.org/get");
- client.Method = HttpMethod.Get;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- Assert.IsTrue(response.Headers.Contains("Content-Length"));
- Assert.IsTrue(response.Headers.Contains("Content-Type"));
-
- Assert.IsTrue(int.Parse(response.Headers["Content-Length"].First()) > 100);
- Assert.AreEqual("application/json", response.Headers["Content-Type"].First());
-
- Assert.IsNotNull(response.Content);
- var content = TestHelper.GetStringFromStream(response.Content);
- Assert.AreNotEqual(0, content.Length);
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakePutRequest()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- using (var content = TestHelper.CreateStream("Test Text"))
- {
- client.Uri = new Uri("http://httpbin.org/put");
- client.Method = HttpMethod.Put;
- client.Content = content;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- Assert.IsNotNull(response.Content);
-
- var stringContent = TestHelper.GetStringFromStream(response.Content);
- Assert.AreNotEqual(0, stringContent.Length);
- Assert.IsTrue(stringContent.Contains("\"data\": \"Test Text\""));
- }
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakePostRequest()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- using (var content = TestHelper.CreateStream("Test Text"))
- {
- client.Uri = new Uri("http://httpbin.org/post");
- client.Method = HttpMethod.Post;
- client.Content = content;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- var stringContent = TestHelper.GetStringFromStream(response.Content);
-
- Assert.IsTrue(stringContent.Contains("\"data\": \"Test Text\""));
- }
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakePostRequestWithNullContent()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- client.Uri = new Uri("http://httpbin.org/post");
- client.Method = HttpMethod.Post;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- var stringContent = TestHelper.GetStringFromStream(response.Content);
-
- Assert.IsTrue(stringContent.Contains("\"data\": \"\""));
-
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakeDeleteRequest()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
-
- client.Uri = new Uri("http://httpbin.org/delete");
- client.Method = HttpMethod.Delete;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- Assert.IsNotNull(response.Content);
- var content = TestHelper.GetStringFromStream(response.Content);
- Assert.AreNotEqual(0, content.Length);
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void CanMakeMultipleGetRequestsWithSameClient()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
-
- client.Uri = new Uri("http://httpbin.org/get");
- client.Method = HttpMethod.Get;
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
-
- responseTask = client.SendAsync();
- responseTask.Wait();
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void RequestsHonorsClientSideTimeout()
- {
- try
- {
- using (var client = new HttpAbstractionClientFactory().Create(TimeSpan.FromMilliseconds(100)))
- {
- client.Uri = new Uri("http://httpbin.org/delay/30000");
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- }
- }
- catch (AggregateException ex)
- {
- var inner = ex.InnerException;
- Assert.IsInstanceOfType(inner,typeof(TimeoutException));
- Assert.IsTrue(inner.Message.Contains("failed to complete in the given timeout period"));
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void RequestsHonorsCancelationToken()
- {
- var token = new CancellationToken(true);
- var startTime = DateTime.Now;
-
- try
- {
- using (var client = new HttpAbstractionClientFactory().Create(token))
- {
- client.Uri = new Uri("http://httpbin.org/delay/30000");
- client.Timeout = TimeSpan.FromSeconds(31);
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- }
- }
- catch (AggregateException ex)
- {
- var inner = ex.InnerException;
- Assert.IsTrue(DateTime.Now - startTime < TimeSpan.FromSeconds(30));
- Assert.IsTrue(inner.Message.Contains("was canceled"));
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void RequestsHandlesHttpErrors()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- client.Uri = new Uri("http://httpbin.org/status/404");
-
- var responseTask = client.SendAsync();
- responseTask.Wait();
- var response = responseTask.Result;
-
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
-
- var stringContent = TestHelper.GetStringFromStream(response.Content);
-
- Assert.AreEqual(string.Empty, stringContent);
- }
- }
-
- [TestMethod]
- [TestCategory("Integration")]
- [TestCategory("LongRunning")]
- public void RequestsCanSendHeaders()
- {
- using (var client = new HttpAbstractionClientFactory().Create())
- {
- client.Uri = new Uri("http://httpbin.org/get");
- client.Headers.Add("X-Test-Header","TEST");
-
- //Added in order to force httpbin not to cache the responses from any prior get requests/unit tests.
- client.Headers.Add("Cache-Control", "max-age=0");
-
- var responseTask = client.SendAsync();
-
- responseTask.Wait();
- var response = responseTask.Result;
- Assert.IsNotNull(response);
- Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
-
- Assert.IsNotNull(response.Content);
- var content = TestHelper.GetStringFromStream(response.Content);
- Assert.AreNotEqual(0, content.Length);
-
- Assert.IsTrue(content.Contains("\"X-Test-Header\": \"TEST\""));
- }
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/HttpAbstraction/HttpHeadersAbstractionTests.cs b/OpenStack/OpenStack.Test/HttpAbstraction/HttpHeadersAbstractionTests.cs
deleted file mode 100644
index ac0838b..0000000
--- a/OpenStack/OpenStack.Test/HttpAbstraction/HttpHeadersAbstractionTests.cs
+++ /dev/null
@@ -1,85 +0,0 @@
-// /* ============================================================================
-// 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.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common.Http;
-
-namespace OpenStack.Test.HttpAbstraction
-{
- [TestClass]
- public class HttpHeadersAbstractionTests
- {
- [TestMethod]
- public void CanAddHeaders()
- {
- var headers = new HttpHeadersAbstraction();
- headers.Add("Test","Value");
- Assert.IsTrue(headers.Contains("Test"));
- Assert.AreEqual("Value",headers["Test"].First());
- }
-
- [TestMethod]
- public void CanAddRangeHeaders()
- {
- var headers = new HttpHeadersAbstraction();
-
- var rspMsg = new HttpResponseMessage();
- rspMsg.Headers.Add("Test", "Value");
-
- headers.AddRange(rspMsg.Headers);
- Assert.IsTrue(headers.Contains("Test"));
- Assert.AreEqual("Value", headers["Test"].First());
- }
-
- [TestMethod]
- public void CanClearHeaders()
- {
- var headers = new HttpHeadersAbstraction();
- headers.Add("Test", "Value");
- Assert.IsTrue(headers.Contains("Test"));
-
- headers.Clear();
- Assert.AreEqual(0,headers.Count());
- }
-
- [TestMethod]
- public void CanGetValuesHeaders()
- {
- var headers = new HttpHeadersAbstraction();
- var values = new List() {"value1", "value2"};
- headers.Add("Test", values);
- Assert.IsTrue(headers.Contains("Test"));
- Assert.AreEqual(values, headers.GetValues("Test"));
- }
-
- [TestMethod]
- public void CanTryGetValuesHeaders()
- {
- var headers = new HttpHeadersAbstraction();
- var values = new List() { "value1", "value2" };
- headers.Add("Test", values);
-
- IEnumerable resValues = new List();
- Assert.IsTrue(headers.TryGetValue("Test", out resValues));
-
- Assert.AreEqual(2,resValues.Count());
- Assert.AreEqual(values, resValues);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/AccessTokenPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Identity/AccessTokenPayloadConverterTests.cs
deleted file mode 100644
index dca6c92..0000000
--- a/OpenStack/OpenStack.Test/Identity/AccessTokenPayloadConverterTests.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-// /* ============================================================================
-// 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 System.Web;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class AccessTokenPayloadConverterTests
- {
- [TestMethod]
- public void CanConvertJsonPayload()
- {
- var AuthJsonResponseFixture = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- }
- }
- }";
-
- var expectedToken = "HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb";
- var converter = new AccessTokenPayloadConverter();
- var token = converter.Convert(AuthJsonResponseFixture);
- Assert.IsNotNull(token);
- Assert.AreEqual(expectedToken, token);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingTokenId()
- {
- var missingTokenIdFixture = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- }
- }
- }";
-
- var converter = new AccessTokenPayloadConverter();
- converter.Convert(missingTokenIdFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadMissingToken()
- {
- var missingTokenFixture = @"{
- ""access"": { }
- }";
-
- var converter = new AccessTokenPayloadConverter();
- converter.Convert(missingTokenFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadEmptyObject()
- {
- var emptyObjectFixture = @"{ }";
-
- var converter = new AccessTokenPayloadConverter();
- converter.Convert(emptyObjectFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJson()
- {
- var badJsonFixture = @"{ NOT JSON";
-
- var converter = new AccessTokenPayloadConverter();
- converter.Convert(badJsonFixture);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJson()
- {
- var nonObjectJson = @"[]";
-
- var converter = new AccessTokenPayloadConverter();
- converter.Convert(nonObjectJson);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/IdentityRestServiceSimulator.cs b/OpenStack/OpenStack.Test/Identity/IdentityRestServiceSimulator.cs
deleted file mode 100644
index b479e38..0000000
--- a/OpenStack/OpenStack.Test/Identity/IdentityRestServiceSimulator.cs
+++ /dev/null
@@ -1,200 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.IO;
-using System.Net;
-using System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-using OpenStack.Common;
-using OpenStack.Common.Http;
-
-namespace OpenStack.Test.Identity
-{
- public class IdentityRestServiceSimulator : DisposableClass, IHttpAbstractionClient
- {
- #region Authentication Json Response Fixture
-
- internal string AuthJsonResponseFixture = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- },
- ""user"": {
- ""id"": ""10391119133001"",
- ""name"": ""wayne.foley"",
- ""otherAttributes"": {
- ""domainStatus"": ""enabled"",
- ""domainStatusCode"": ""00""
- },
- ""roles"": [ ]
- },
- ""serviceCatalog"": [
- {
- ""name"": ""Networking"",
- ""type"": ""network"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.network.hpcloudsvc.com"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""2.0"",
- ""versionInfo"": ""https://region-a.geo-1.network.hpcloudsvc.com"",
- ""versionList"": ""https://region-a.geo-1.network.hpcloudsvc.com""
- }
- ]
- },
- {
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- },
- {
- ""name"": ""Identity"",
- ""type"": ""identity"",
- ""endpoints"": [
- {
- ""publicURL"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""2.0"",
- ""versionInfo"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357/v2.0/"",
- ""versionList"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357""
- },
- {
- ""publicURL"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3/"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""3.0"",
- ""versionInfo"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357/v3/"",
- ""versionList"": ""https://region-a.geo-1.identity.hpcloudsvc.com:35357""
- },
- {
- ""publicURL"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""2.0"",
- ""versionInfo"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357/v2.0/"",
- ""versionList"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357""
- },
- {
- ""publicURL"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357/v3/"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""3.0"",
- ""versionInfo"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357/v3/"",
- ""versionList"": ""https://region-b.geo-1.identity.hpcloudsvc.com:35357""
- }
- ]
- },
- {
- ""name"": ""Compute"",
- ""type"": ""compute"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.compute.hpcloudsvc.com/v2/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""2"",
- ""versionInfo"": ""https://region-a.geo-1.compute.hpcloudsvc.com/v2/"",
- ""versionList"": ""https://region-a.geo-1.compute.hpcloudsvc.com""
- }
- ]
- }
- ]
- }
- }";
-
-
- #endregion
-
- public HttpMethod Method { get; set; }
- public Uri Uri { get; set; }
- public Stream Content { get; set; }
- public IDictionary Headers { get; private set; }
- public string ContentType { get; set; }
- public TimeSpan Timeout { get; set; }
- //public event EventHandler HttpReceiveProgress;
- //public event EventHandler HttpSendProgress;
-
- public IdentityRestServiceSimulator()
- {
- this.Headers = new Dictionary();
- }
-
- public Task SendAsync()
- {
- var resp = TestHelper.CreateResponse(HttpStatusCode.OK, new List>(),
- this.AuthJsonResponseFixture.ConvertToStream());
- return Task.Factory.StartNew(() => resp);
- }
- }
-
- public class IdentityRestServiceSimulatorFactory : IHttpAbstractionClientFactory
- {
- internal IdentityRestServiceSimulator Simulator;
-
- public IdentityRestServiceSimulatorFactory(IdentityRestServiceSimulator simulator)
- {
- this.Simulator = simulator;
- }
-
- public IHttpAbstractionClient Create()
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(CancellationToken token)
- {
- if (this.Simulator != null)
- {
- this.Simulator.Headers.Clear();
- }
- return this.Simulator ?? new IdentityRestServiceSimulator();
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout)
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout, CancellationToken token)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs
deleted file mode 100644
index 396e02b..0000000
--- a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientDefinitionTests.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using System;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class IdentityServiceClientDefinitionTests
- {
- public IOpenStackCredential GetValidCredentials()
- {
- var endpoint = new Uri("https://someidentityendpoint:35357/v2.0");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- return new OpenStackCredential(endpoint, userName, password, tenantId);
- }
-
- [TestMethod]
- public void CanSupportVersion2()
- {
- var client = new IdentityServiceClientDefinition();
-
- Assert.IsTrue(client.IsSupported(GetValidCredentials(), string.Empty));
- }
-
- [TestMethod]
- public void CannotSupportVersion1()
- {
- var endpoint = new Uri("https://someidentityendpoint:35357/v1.0/tokens");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var creds = new OpenStackCredential(endpoint, userName, password, tenantId);
-
- var client = new IdentityServiceClientDefinition();
-
- Assert.IsFalse(client.IsSupported(creds, string.Empty));
- }
-
- [TestMethod]
- public void Version2Supported()
- {
- var client = new IdentityServiceClientDefinition();
- Assert.IsTrue(client.ListSupportedVersions().Contains("2.0.0.0"));
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs
deleted file mode 100644
index 6e2ca86..0000000
--- a/OpenStack/OpenStack.Test/Identity/IdentityServiceClientTests.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// /* ============================================================================
-// 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 System.Threading;
-using System.Threading.Tasks;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class IdentityServiceClientTests
- {
- internal TestIdentityServicePocoClient pocoClient;
- internal IServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.ServiceLocator = new ServiceLocator();
- this.pocoClient = new TestIdentityServicePocoClient();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IIdentityServicePocoClientFactory), new TestIdentityServicePocoClientFactory(pocoClient));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.pocoClient = new TestIdentityServicePocoClient();
- this.ServiceLocator = new ServiceLocator();
- }
-
- public IOpenStackCredential GetValidCredentials()
- {
- var endpoint = new Uri("https://someidentityendpoint:35357/v2.0/tokens");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- return new OpenStackCredential(endpoint, userName, password, tenantId);
- }
-
- [TestMethod]
- public async Task CanAuthenticate()
- {
- var creds = GetValidCredentials();
- var token = "someToken";
-
- this.pocoClient.AuthenticationDelegate = () =>
- {
- creds.SetAccessTokenId(token);
- return Task.Factory.StartNew(() => creds);
- };
-
- var client = new IdentityServiceClientDefinition().Create(GetValidCredentials(), string.Empty, CancellationToken.None, this.ServiceLocator) as IdentityServiceClient;
- var resp = await client.Authenticate();
-
- Assert.AreEqual(creds, resp);
- Assert.AreEqual(creds,client.Credential);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs
deleted file mode 100644
index e85f199..0000000
--- a/OpenStack/OpenStack.Test/Identity/IdentityServicePocoClientTests.cs
+++ /dev/null
@@ -1,342 +0,0 @@
-// /* ============================================================================
-// 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 System.IO;
-using System.Linq;
-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;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class IdentityServicePocoClientTests
- {
- 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);
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IIdentityServiceRestClientFactory), new TestIdentityServiceRestClientFactory(RestClient));
- manager.RegisterServiceInstance(typeof(IOpenStackRegionResolver), new TestOpenStackRegionResolver(defaultRegion));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.RestClient = new TestIdentityServiceRestClient();
- this.ServiceLocator = new ServiceLocator();
- }
-
- public IOpenStackCredential GetValidCredentials()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- return new OpenStackCredential(endpoint, userName, password, tenantId);
- }
-
-
- [TestMethod]
- public async Task CanAuthenticateWithOkResponse()
- {
- var creds = GetValidCredentials();
-
- var expectedToken = "HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb";
-
- var payload = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- },
- ""serviceCatalog"":[{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }]
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
- this.RestClient.Response = restResp;
-
- var client =
- new IdentityServicePocoClientFactory().Create(creds, "Swift", CancellationToken.None, this.ServiceLocator) as
- IdentityServicePocoClient;
- var result = await client.Authenticate();
-
- Assert.IsNotNull(result);
- Assert.AreEqual(creds.UserName, result.UserName);
- Assert.AreEqual(creds.Password, result.Password);
- Assert.AreEqual(creds.TenantId, result.TenantId);
- Assert.AreEqual(expectedToken, result.AccessTokenId);
- Assert.AreEqual(1,result.ServiceCatalog.Count());
- }
-
- [TestMethod]
- public async Task CanAuthenticateWithNonAuthoritativeInfoResponse()
- {
- var creds = GetValidCredentials();
-
- var expectedToken = "HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb";
-
- var payload = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- },
- ""serviceCatalog"":[{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }]
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- var result = await client.Authenticate();
-
- Assert.IsNotNull(result);
- Assert.AreEqual(creds.UserName, result.UserName);
- Assert.AreEqual(creds.Password, result.Password);
- Assert.AreEqual(creds.TenantId, result.TenantId);
- Assert.AreEqual(expectedToken, result.AccessTokenId);
- Assert.AreEqual(1, result.ServiceCatalog.Count());
- }
-
- [TestMethod]
- public async Task AuthenticationDoesNotResolveRegionIfCredRegionSupplied()
- {
- var expectedRegion = "Some region";
- var creds = GetValidCredentials();
- creds.SetRegion(expectedRegion);
- var payload = @"{
- ""access"": {
- ""token"": {
- ""expires"": ""2014-03-18T10:59:46.355Z"",
- ""id"": ""HPAuth10_af3d1bfe456d18e8d4793e54922f839fa051d9f60f115aca52c9a44f9e3d96fb"",
- ""tenant"": {
- ""id"": ""10244656540440"",
- ""name"": ""10255892528404-Project""
- }
- },
- ""serviceCatalog"":[{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }]
- }
- }";
-
- var content = TestHelper.CreateStream(payload);
-
- var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.NonAuthoritativeInformation);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- var result = await client.Authenticate();
-
- Assert.AreEqual(expectedRegion, result.Region);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithUnauthorizedResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithBadRequestResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.BadRequest);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithInternalServerErrorResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithForbiddenResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Forbidden);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithBadMethodResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.MethodNotAllowed);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithOverLimitResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.RequestEntityTooLarge);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithServiceUnavailableResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.ServiceUnavailable);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public async Task CannotAuthenticateWithNotFoundResponse()
- {
- var creds = GetValidCredentials();
-
- var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NotFound);
- this.RestClient.Response = restResp;
-
- var client = new IdentityServicePocoClient(creds, "Swift", CancellationToken.None, this.ServiceLocator);
- await client.Authenticate();
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs b/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs
deleted file mode 100644
index a70c433..0000000
--- a/OpenStack/OpenStack.Test/Identity/IdentityServiceRestClientTests.cs
+++ /dev/null
@@ -1,119 +0,0 @@
-// /* ============================================================================
-// 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 System.Net.Http;
-using System.Threading;
-using System.Threading.Tasks;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class IdentityServiceRestClientTests
- {
- internal IdentityRestServiceSimulator simulator;
- internal IServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.simulator = new IdentityRestServiceSimulator();
- this.ServiceLocator = new ServiceLocator();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(IHttpAbstractionClientFactory), new IdentityRestServiceSimulatorFactory(simulator));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.simulator = new IdentityRestServiceSimulator();
- this.ServiceLocator = new ServiceLocator();
- }
-
- public IOpenStackCredential GetValidCredentials()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- return new OpenStackCredential(endpoint, userName, password, tenantId);
- }
-
- [TestMethod]
- public async Task AuthenticationMethodAndUriAreValid()
- {
- var creds = GetValidCredentials();
- var client = new IdentityServiceRestClientFactory().Create(creds,CancellationToken.None, this.ServiceLocator);
-
- await client.Authenticate();
- var expectedUri = new Uri(string.Format("{0}/tokens", creds.AuthenticationEndpoint));
- Assert.AreEqual(expectedUri, this.simulator.Uri);
- Assert.AreEqual(HttpMethod.Post, this.simulator.Method);
- }
-
- [TestMethod]
- public async Task AuthenticateIncludesCorrectHeaders()
- {
- var creds = GetValidCredentials();
- var client = new IdentityServiceRestClient(creds, CancellationToken.None, this.ServiceLocator);
-
- await client.Authenticate();
-
- Assert.IsTrue(this.simulator.Headers.ContainsKey("Accept"));
- Assert.AreEqual("application/json", this.simulator.Headers["Accept"]);
- Assert.AreEqual("application/json", this.simulator.ContentType);
- }
-
- [TestMethod]
- public async Task AuthenticateIncludesPayload()
- {
- var creds = GetValidCredentials();
- var client = new IdentityServiceRestClient(creds, CancellationToken.None, this.ServiceLocator);
-
- await client.Authenticate();
-
- Assert.IsNotNull(this.simulator.Content);
-
- var content = TestHelper.GetStringFromStream(this.simulator.Content);
- Assert.IsTrue(content.Length > 0);
- }
-
- [TestMethod]
- public void AuthenticationPayloadIsGeneratedCorrectly()
- {
- var creds = GetValidCredentials();
- var payload = IdentityServiceRestClient.CreateAuthenticationJsonPayload(creds);
-
- var obj = JObject.Parse(payload);
- var userName = obj["auth"]["passwordCredentials"]["username"];
- var password = obj["auth"]["passwordCredentials"]["password"];
- var tenantId = obj["auth"]["tenantName"];
-
- Assert.AreEqual(creds.UserName, userName);
- Assert.AreEqual(creds.Password, password);
- Assert.AreEqual(creds.TenantId, tenantId);
- }
-
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackCredentialTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackCredentialTests.cs
deleted file mode 100644
index 8c1a7ec..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackCredentialTests.cs
+++ /dev/null
@@ -1,180 +0,0 @@
-// /* ============================================================================
-// 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 Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackCredentialTests
- {
- [TestMethod]
- public void CanCreateAnOpenStackCredential()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
-
- Assert.IsNotNull(cred);
- Assert.AreEqual(userName, cred.UserName);
- Assert.AreEqual(endpoint, cred.AuthenticationEndpoint);
- Assert.IsNotNull(cred.Password);
- Assert.AreEqual(tenantId, cred.TenantId);
- }
-
- [TestMethod]
- public void CanSetAcessTokenId()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
- var token = "someToken";
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
- cred.SetAccessTokenId(token);
-
- Assert.AreEqual(token, cred.AccessTokenId);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotSetAcessTokenIdWithNullToken()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
- cred.SetAccessTokenId(null);
- }
-
- [TestMethod]
- public void CanSetServiceCatalog()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var catalog = new OpenStackServiceCatalog();
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
- cred.SetServiceCatalog(catalog);
-
- Assert.AreEqual(catalog, cred.ServiceCatalog);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotSetServiceCatalogWithNullToken()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
- cred.SetServiceCatalog(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotSetAcessTokenIdWithEmptyToken()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, userName, password, tenantId);
- cred.SetAccessTokenId(string.Empty);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotCreateAnOpenStackCredentialWithNullEndpoint()
- {
- var userName = "TestUser";
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(null, userName, password, tenantId);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotCreateAnOpenStackCredentialWithNullUserName()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, null, password, tenantId);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotCreateAnOpenStackCredentialWithEmptyUserName()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var password = "RandomPassword";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, string.Empty, password, tenantId);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotCreateAnOpenStackCredentialWithNullPassword()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var tenantId = "12345";
-
- var cred = new OpenStackCredential(endpoint, userName, null, tenantId);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotCreateAnOpenStackCredentialWithNullTenantId()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
-
- var cred = new OpenStackCredential(endpoint, userName, password, null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotCreateAnOpenStackCredentialWithEmptyTenantId()
- {
- var endpoint = new Uri("https://auth.someplace.com/authme");
- var userName = "TestUser";
- var password = "RandomPassword";
-
- var cred = new OpenStackCredential(endpoint, userName, password, string.Empty);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs
deleted file mode 100644
index 8dd5ec5..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackRegionResolverTests.cs
+++ /dev/null
@@ -1,167 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackRegionResolverTests
- {
- [TestMethod]
- public void CanResolveRegion()
- {
- var expectedRegion = "some region";
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", expectedRegion , "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
-
- catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
- var resolver = new OpenStackRegionResolver();
- var region = resolver.Resolve(new Uri("http://other.endpoint.org/v2/tokens"), catalog, "Test Service");
- Assert.AreEqual(expectedRegion, region);
- }
-
- [TestMethod]
- public void CannotResolveRegionWhenNoEnpointMatches()
- {
- var expectedRegion = string.Empty;
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.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()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
- var resolver = new OpenStackRegionResolver();
- var region = resolver.Resolve(new Uri("http://nomatching.endpoint.org/v2/tokens"), catalog, "Test Service");
- Assert.AreEqual(expectedRegion, region);
- }
-
- [TestMethod]
- public void CannotResolveRegionWhenNoMatchingServices()
- {
- var expectedRegion = string.Empty;
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.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()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
- var resolver = new OpenStackRegionResolver();
- var region = resolver.Resolve(new Uri("http://nomatching.endpoint.org/v2/tokens"), catalog, "No Matching Service");
- Assert.AreEqual(expectedRegion, region);
- }
-
- [TestMethod]
- public void CanResolveRegionWhenNoMatchingServicesButMatchingEndpoint()
- {
- var expectedRegion = "Some Region";
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://the.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()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
- var resolver = new OpenStackRegionResolver();
- var region = resolver.Resolve(new Uri("http://the.endpoint.org/v2/tokens"), catalog, "No Matching Service");
- Assert.AreEqual(expectedRegion, region);
- }
-
- [TestMethod]
- public void CannotResolveRegionWhenMatchingEndpointHasEmptyRegion()
- {
- var expectedRegion = string.Empty;
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "Some Region" , "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
-
- catalog[0].Endpoints.First().Region = string.Empty;
-
- catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
- var resolver = new OpenStackRegionResolver();
- var region = resolver.Resolve(new Uri("http://nomatching.endpoint.org/v2/tokens"), catalog, "Test Service");
- Assert.AreEqual(expectedRegion, region);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotResolveRegionWithNullCatalog()
- {
- var resolver = new OpenStackRegionResolver();
- resolver.Resolve(new Uri("http://other.endpoint.org/v2/tokens"), null, "Test Service");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotResolveRegionWithNullEndpoint()
- {
- var catalog = new OpenStackServiceCatalog();
-
- var resolver = new OpenStackRegionResolver();
- resolver.Resolve(null, catalog, "Test Service");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotResolveRegionWithNullServiceName()
- {
- var catalog = new OpenStackServiceCatalog();
-
- var resolver = new OpenStackRegionResolver();
- resolver.Resolve(new Uri("http://other.endpoint.org/v2/tokens"), catalog, null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotResolveRegionWithEmptyServiceName()
- {
- var catalog = new OpenStackServiceCatalog();
-
- var resolver = new OpenStackRegionResolver();
- resolver.Resolve(new Uri("http://other.endpoint.org/v2/tokens"), catalog, string.Empty);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogPayloadConverterTests.cs
deleted file mode 100644
index 0e4a455..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogPayloadConverterTests.cs
+++ /dev/null
@@ -1,190 +0,0 @@
-// /* ============================================================================
-// 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 System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackServiceCatalogPayloadConverterTests
- {
- [TestMethod]
- public void CanConvertJsonPayload()
- {
- var expectedName = "Object Storage";
- var expectedType = "object-store";
-
- var serviceCatalogPayload = @"{
- ""access"": {
-
- ""serviceCatalog"":[{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }]}}";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- var serviceDefs = converter.Convert(serviceCatalogPayload).ToList();
-
- Assert.AreEqual(1, serviceDefs.Count());
-
- var service = serviceDefs.First(i => i.Name == expectedName);
- Assert.IsNotNull(service);
- Assert.AreEqual(expectedName, service.Name);
- Assert.AreEqual(expectedType, service.Type);
- Assert.AreEqual(2, service.Endpoints.Count());
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithMultipleServiceDefs()
- {
- var expectedName1 = "Object Storage";
- var expectedType1 = "object-store";
-
- var expectedName2 = "Some Other Service";
- var expectedType2 = "other-service";
-
- var serviceCatalogPayload = @"{
- ""access"": {
-
- ""serviceCatalog"":[{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- },
- {
- ""name"": ""Some Other Service"",
- ""type"": ""other-service"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- }
- ]
- }]}}";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- var serviceDefs = converter.Convert(serviceCatalogPayload).ToList();
-
- Assert.AreEqual(2, serviceDefs.Count());
-
- var service1 = serviceDefs.First(i => i.Name == expectedName1);
- Assert.IsNotNull(service1);
- Assert.AreEqual(expectedName1, service1.Name);
- Assert.AreEqual(expectedType1, service1.Type);
- Assert.AreEqual(2, service1.Endpoints.Count());
-
- var service2 = serviceDefs.First(i => i.Name == expectedName2);
- Assert.IsNotNull(service1);
- Assert.AreEqual(expectedName2, service2.Name);
- Assert.AreEqual(expectedType2, service2.Type);
- Assert.AreEqual(1, service2.Endpoints.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithMissingCatalog()
- {
- var serviceCatalogPayload = @"{
- ""access"": {
-
- }}";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- converter.Convert(serviceCatalogPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithEmptyObject()
- {
- var serviceDefPayload = @" { }";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotConvertWithNullJsonPayload()
- {
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- converter.Convert(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonPayload()
- {
- var serviceDefPayload = @" { NOT JSON";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonPayload()
- {
- var serviceDefPayload = @"[]";
-
- var converter = new OpenStackServiceCatalogPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogTests.cs
deleted file mode 100644
index 359c759..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackServiceCatalogTests.cs
+++ /dev/null
@@ -1,203 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackServiceCatalogTests
- {
- [TestMethod]
- public void IfAServiceExistsCatalogReturnsTrue()
- {
- var expectedEndpoint = new Uri("http://public.endpoint.org");
- var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
- var catalog = new OpenStackServiceCatalog { serviceDef };
- Assert.IsTrue(catalog.Exists("Test Service"));
- }
-
- [TestMethod]
- public void IfAServiceDoesNotExistsCatalogReturnsFalse()
- {
- var expectedEndpoint = new Uri("http://public.endpoint.org");
- var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
- var catalog = new OpenStackServiceCatalog { serviceDef };
- Assert.IsFalse(catalog.Exists("NOT IN CATALOG"));
- }
-
- [TestMethod]
- public void CanGetServicesInRegion()
- {
- var expectedEndpoint = new Uri("http://public.endpoint.org");
- var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
- var catalog = new OpenStackServiceCatalog { serviceDef };
- var services = catalog.GetServicesInAvailabilityZone("some region").ToList();
- Assert.AreEqual(1,services.Count());
- Assert.AreEqual("Test Service",services.First().Name);
- }
-
- [TestMethod]
- public void CanGetServicesInRegionWithMultipleServices()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://some.endpoint.com", "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
-
- catalog.Add(new OpenStackServiceDefinition("Other Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint("http://other.endpoint.org", "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- }));
-
- var services = catalog.GetServicesInAvailabilityZone("some region").ToList();
- Assert.AreEqual(2, services.Count());
- }
-
- [TestMethod]
- public void GettingServicesInRegionWhenNonExistReturnsAnEmptyCollection()
- {
- var expectedEndpoint = new Uri("http://public.endpoint.org");
- var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
- var catalog = new OpenStackServiceCatalog { serviceDef };
- var services = catalog.GetServicesInAvailabilityZone("some other region").ToList();
- Assert.AreEqual(0, services.Count());
- }
-
- [TestMethod]
- public void CanGetServicesForRegionWithMultipleEndpoints()
- {
- var expectedEndpoint = new Uri("http://public.endpoint.org");
- var serviceDef = new OpenStackServiceDefinition("Test Service", "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com"),
- new OpenStackServiceEndpoint(expectedEndpoint.ToString(), "some other region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
- var catalog = new OpenStackServiceCatalog { serviceDef };
- var services = catalog.GetServicesInAvailabilityZone("some other region").ToList();
- Assert.AreEqual(1, services.Count());
- }
-
- [TestMethod]
- public void CanGetPublicEndpointForAService()
- {
- var serviceName = "Test Service";
- var regionName = "some region";
- var expectedEndpoint = "http://public.endpoint.org";
- var serviceDef = new OpenStackServiceDefinition(serviceName, "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint, "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
-
- var catalog = new OpenStackServiceCatalog { serviceDef };
- var endpoint = catalog.GetPublicEndpoint(serviceName, regionName);
- Assert.AreEqual(expectedEndpoint, endpoint);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotGetPublicEndpointWithANullServiceName()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.GetPublicEndpoint(null, "Some region");
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotGetPublicEndpointWithANullRegion()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.GetPublicEndpoint("Test Service", null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentException))]
- public void CannotGetPublicEndpointWithAnEmptyServiceName()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.GetPublicEndpoint(string.Empty, "Some region");
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public void CannotGetPublicEndpointForAServiceThatIsNotInTheCatalog()
- {
- var serviceName = "Test Service";
- var regionName = "some region";
- var expectedEndpoint = "http://public.endpoint.org";
- var serviceDef = new OpenStackServiceDefinition(serviceName, "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint, "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
-
- var catalog = new OpenStackServiceCatalog { serviceDef };
- catalog.GetPublicEndpoint("Not-In-Catalog", regionName);
- }
-
- [TestMethod]
- [ExpectedException(typeof(InvalidOperationException))]
- public void CannotGetPublicEndpointForAServiceThatIsNotInTheRegion()
- {
- var serviceName = "Test Service";
- var expectedEndpoint = "http://public.endpoint.org";
- var serviceDef = new OpenStackServiceDefinition(serviceName, "Test-Service",
- new List()
- {
- new OpenStackServiceEndpoint(expectedEndpoint, "some region", "1.0",
- "http://www.someplace.com", "http://www.someplace.com")
- });
-
- var catalog = new OpenStackServiceCatalog { serviceDef };
- catalog.GetPublicEndpoint(serviceName, "Not-in-catalog");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackServiceDefinitionPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackServiceDefinitionPayloadConverterTests.cs
deleted file mode 100644
index e37766e..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackServiceDefinitionPayloadConverterTests.cs
+++ /dev/null
@@ -1,178 +0,0 @@
-// /* ============================================================================
-// 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 System.Linq;
-using System.Web;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackServiceDefinitionPayloadConverterTests
- {
- [TestMethod]
- public void CanConvertJsonPayload()
- {
- var expectedName = "Object Storage";
- var expectedType = "object-store";
-
- var serviceDefPayload = @" {
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- var service = converter.Convert(serviceDefPayload);
-
- Assert.IsNotNull(service);
- Assert.AreEqual(expectedName, service.Name);
- Assert.AreEqual(expectedType, service.Type);
- Assert.AreEqual(2, service.Endpoints.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithMissingName()
- {
- var serviceDefPayload = @"{
- ""type"": ""object-store"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithMissingType()
- {
- var serviceDefPayload = @"{
- ""name"": ""Object Storage"",
- ""endpoints"": [
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1/10244656540440"",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.objects.hpcloudsvc.com/v1.0/"",
- ""versionList"": ""https://region-a.geo-1.objects.hpcloudsvc.com""
- },
- {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/10244656540440"",
- ""region"": ""region-b.geo-1"",
- ""versionId"": ""1"",
- ""versionInfo"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443/v1/"",
- ""versionList"": ""https://region-b.geo-1.objects.hpcloudsvc.com:443""
- }
- ]
- }";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof (FormatException))]
- public void CannotConvertJsonPayloadWithMissingEndpoints()
- {
- var serviceDefPayload = @"{
- ""name"": ""Object Storage"",
- ""type"": ""object-store"",
- }";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithEmptyObject()
- {
- var serviceDefPayload = @" { }";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotConvertWithNullJsonPayload()
- {
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonPayload()
- {
- var serviceDefPayload = @" { NOT JSON";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonPayload()
- {
- var serviceDefPayload = @"[]";
-
- var converter = new OpenStackServiceDefinitionPayloadConverter(new ServiceLocator());
- converter.Convert(serviceDefPayload);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs
deleted file mode 100644
index 207304a..0000000
--- a/OpenStack/OpenStack.Test/Identity/OpenStackServiceEndpointPayloadConverterTests.cs
+++ /dev/null
@@ -1,252 +0,0 @@
-// /* ============================================================================
-// 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 System.Web;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- [TestClass]
- public class OpenStackServiceEndpointPayloadConverterTests
- {
- [TestMethod]
- public void CanConvertJsonPayload()
- {
- var expectedPublicUri = "https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440";
- var expectedRegion = "region-a.geo-1";
- var expectedVersion = "1.0";
- var expectedVersionList = "https://region-a.geo-1.block.hpcloudsvc.com";
- var expectedVersionInfo = "https://region-a.geo-1.block.hpcloudsvc.com/v1";
-
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- var endpoint = converter.Convert(endpointPayload);
-
- Assert.IsNotNull(endpoint);
- Assert.AreEqual(expectedPublicUri, endpoint.PublicUri.ToString());
- Assert.AreEqual(expectedRegion, endpoint.Region);
- Assert.AreEqual(expectedVersion, endpoint.Version);
- Assert.AreEqual(expectedVersionInfo, endpoint.VersionInformation.ToString());
- Assert.AreEqual(expectedVersionList, endpoint.VersionList.ToString());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotConvertWithNullJsonPayload()
- {
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithMissingPublicUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertJsonPayloadWithMissingRegion()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithMissingVersion()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithMissingVersionInfoUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithMissingVersionListUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithBadPublicUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""httpsBAD://reg&VERYBAD&ion-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithBadVersionInfoUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""htBADtps://region&BAD&-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithBadVersionListcUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": ""htBADtps://region-a.ge&BAD&o-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithEmptyVersionInfoUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": """",
- ""versionList"": ""https://region-a.geo-1.block.hpcloudsvc.com""
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- public void CanConvertJsonPayloadWithEmptyVersionListcUri()
- {
- var endpointPayload = @" {
- ""tenantId"": ""10244656540440"",
- ""publicURL"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1/10244656540440"",
- ""publicURL2"": """",
- ""region"": ""region-a.geo-1"",
- ""versionId"": ""1.0"",
- ""versionInfo"": ""https://region-a.geo-1.block.hpcloudsvc.com/v1"",
- ""versionList"": """"
- }";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertInvalidJsonPayload()
- {
- var endpointPayload = @" { NOT JSON";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotConvertNonObjectJsonPayload()
- {
- var endpointPayload = @" [] ";
-
- var converter = new OpenStackServiceEndpointPayloadConverter();
- converter.Convert(endpointPayload);
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs b/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs
deleted file mode 100644
index d4886b3..0000000
--- a/OpenStack/OpenStack.Test/Identity/TestIdentityServicePocoClient.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// /* ============================================================================
-// 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 System.Threading;
-using System.Threading.Tasks;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- public class TestIdentityServicePocoClient : IIdentityServicePocoClient
- {
- public Func> AuthenticationDelegate { get; set; }
-
- public Task Authenticate()
- {
- return AuthenticationDelegate();
- }
- }
-
- public class TestIdentityServicePocoClientFactory : IIdentityServicePocoClientFactory
- {
- internal IIdentityServicePocoClient client;
-
- public TestIdentityServicePocoClientFactory(IIdentityServicePocoClient client)
- {
- this.client = client;
- }
-
- public IIdentityServicePocoClient Create(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
- {
- return client;
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Identity/TestIdentityServiceRestClient.cs b/OpenStack/OpenStack.Test/Identity/TestIdentityServiceRestClient.cs
deleted file mode 100644
index 8918d7a..0000000
--- a/OpenStack/OpenStack.Test/Identity/TestIdentityServiceRestClient.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-// /* ============================================================================
-// 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 System.Threading.Tasks;
-using OpenStack.Common.Http;
-using OpenStack.Common.ServiceLocation;
-using OpenStack.Identity;
-
-namespace OpenStack.Test.Identity
-{
- public class TestIdentityServiceRestClient : IIdentityServiceRestClient
- {
- public IHttpResponseAbstraction Response { get; set; }
-
- public Task Authenticate()
- {
- return Task.Factory.StartNew(() => Response);
- }
- }
-
- public class TestIdentityServiceRestClientFactory : IIdentityServiceRestClientFactory
- {
- internal IIdentityServiceRestClient Client;
-
- public TestIdentityServiceRestClientFactory(IIdentityServiceRestClient client)
- {
- this.Client = client;
- }
-
- public IIdentityServiceRestClient Create(IOpenStackCredential credential, CancellationToken cancellationToken, IServiceLocator serviceLocator)
- {
- return Client;
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Network/FloatingIpPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Network/FloatingIpPayloadConverterTests.cs
deleted file mode 100644
index 519682f..0000000
--- a/OpenStack/OpenStack.Test/Network/FloatingIpPayloadConverterTests.cs
+++ /dev/null
@@ -1,186 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-using OpenStack.Network;
-
-namespace OpenStack.Test.Network
-{
- [TestClass]
- public class FloatingIpPayloadConverterTests
- {
- internal string CreateFloatingIpJsonFixtrue(string id, string ipAddress, FloatingIpStatus status)
- {
- var payloadFixture = @"{{
- ""router_id"": ""fafac59b-a94a-4525-8700-f4f448e0ac97"",
- ""status"": ""{1}"",
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""floating_network_id"": ""3eaab3f7-d3f2-430f-aa73-d07f39aae8f4"",
- ""fixed_ip_address"": ""10.0.0.2"",
- ""floating_ip_address"": ""{2}"",
- ""port_id"": ""9da94672-6e6b-446c-9579-3dd5484b31fd"",
- ""id"": ""{0}""
- }}";
-
- return string.Format(payloadFixture, id, status, ipAddress);
- }
-
- [TestMethod]
- public void CanParseValidFloatingIpsJsonPayloadWithMultipleIps()
- {
- var validMultipleIpJsonFixture = @"{{ ""floatingips"": [ {0} ] }}";
- var firstIp = CreateFloatingIpJsonFixtrue("12345", "172.0.0.1", FloatingIpStatus.Active);
- var secondIp = CreateFloatingIpJsonFixtrue("54321", "172.0.0.2", FloatingIpStatus.Down);
-
- var validMultipleIpsJson = string.Format(validMultipleIpJsonFixture,
- string.Join(",", new List() { firstIp, secondIp }));
-
- var converter = new FloatingIpPayloadConverter();
- var floatingIps = converter.ConvertFloatingIps(validMultipleIpsJson).ToList();
-
- Assert.AreEqual(2, floatingIps.Count());
- var ip1 =
- floatingIps.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
- var ip2 =
- floatingIps.First(o => string.Equals(o.Id, "54321", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(ip1);
- Assert.IsNotNull(ip2);
-
- Assert.AreEqual("12345", ip1.Id);
- Assert.AreEqual("172.0.0.1", ip1.FloatingIpAddress);
- Assert.AreEqual(FloatingIpStatus.Active, ip1.Status);
-
- Assert.AreEqual("54321", ip2.Id);
- Assert.AreEqual("172.0.0.2", ip2.FloatingIpAddress);
- Assert.AreEqual(FloatingIpStatus.Down, ip2.Status);
- }
-
- [TestMethod]
- public void CanConvertValidFloatingIpsJsonPayloadWithSingleNetwork()
- {
- var validSingleIpJsonPayload = @"{{ ""floatingips"": [ {0} ] }}";
- var firstIp = CreateFloatingIpJsonFixtrue("12345", "172.0.0.1", FloatingIpStatus.Active);
-
- var validSingleIpPayload = string.Format(validSingleIpJsonPayload,
- string.Join(",", new List() { firstIp }));
-
- var converter = new FloatingIpPayloadConverter();
- var floatingIps = converter.ConvertFloatingIps(validSingleIpPayload).ToList();
-
- Assert.AreEqual(1, floatingIps.Count());
- var ip1 =
- floatingIps.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
-
- Assert.IsNotNull(ip1);
-
- Assert.AreEqual("12345", ip1.Id);
- Assert.AreEqual("172.0.0.1", ip1.FloatingIpAddress);
- Assert.AreEqual(FloatingIpStatus.Active, ip1.Status);
- }
-
- [TestMethod]
- public void CanParseValidFloatingIpsPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""floatingips"": [ ] }";
-
- var converter = new FloatingIpPayloadConverter();
- var networks = converter.ConvertFloatingIps(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, networks.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyFloatingIpsPayload()
- {
- var payload = string.Empty;
-
- var converter = new FloatingIpPayloadConverter();
- var networks = converter.ConvertFloatingIps(payload).ToList();
-
- Assert.AreEqual(0, networks.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullFloatingIpsPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.ConvertFloatingIps(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFloatingIpsJsonPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.ConvertFloatingIps("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFloatingIpsPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.ConvertFloatingIps("NOT JSON");
- }
-
- [TestMethod]
- public void CanConvertValidFloatingIpJsonPayload()
- {
- var validSingleIpJsonPayload = @"{{ ""floatingip"": {0} }}";
- var firstIp = CreateFloatingIpJsonFixtrue("12345", "172.0.0.1", FloatingIpStatus.Active);
-
- var validSingleIpPayload = string.Format(validSingleIpJsonPayload,
- string.Join(",", new List() { firstIp }));
-
- var converter = new FloatingIpPayloadConverter();
- var ip1 = converter.Convert(validSingleIpPayload);
-
- Assert.IsNotNull(ip1);
- Assert.AreEqual("12345", ip1.Id);
- Assert.AreEqual("172.0.0.1", ip1.FloatingIpAddress);
- Assert.AreEqual(FloatingIpStatus.Active, ip1.Status);
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullFloatingIpPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.Convert(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFloatingIpJsonPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.Convert("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidFloatingIpPayload()
- {
- var converter = new FloatingIpPayloadConverter();
- converter.Convert("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Network/NetworkPayloadConverterTests.cs b/OpenStack/OpenStack.Test/Network/NetworkPayloadConverterTests.cs
deleted file mode 100644
index 3e5b2eb..0000000
--- a/OpenStack/OpenStack.Test/Network/NetworkPayloadConverterTests.cs
+++ /dev/null
@@ -1,146 +0,0 @@
-// /* ============================================================================
-// 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 System.Collections.Generic;
-using System.Linq;
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-using OpenStack.Compute;
-using OpenStack.Network;
-
-namespace OpenStack.Test.Network
-{
- [TestClass]
- public class NetworkPayloadConverterTests
- {
- internal string CreateNetworkJsonFixtrue(string id, string name, NetworkStatus status)
- {
- var NetworkJsonResponseFixture = @"{{
- ""status"": ""{2}"",
- ""subnets"": [
- ""d3839504-ec4c-47a4-b7c7-07af079a48bb""
- ],
- ""name"": ""{1}"",
- ""router:external"": false,
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""admin_state_up"": true,
- ""shared"": false,
- ""id"": ""{0}""
- }}";
-
- return string.Format(NetworkJsonResponseFixture, id, name, status);
- }
-
- [TestMethod]
- public void CanParseValidNetworksJsonPayloadWithMultipleNetworks()
- {
- var validMultipleNetworkJsonFixture = @"{{ ""networks"": [ {0} ] }}";
- var firstNetwork = CreateNetworkJsonFixtrue("12345", "MyNetwork", NetworkStatus.Active);
- var secondNetwork = CreateNetworkJsonFixtrue("54321", "NetworkMy", NetworkStatus.Down);
-
- var validMultipleNetworksJson = string.Format(validMultipleNetworkJsonFixture,
- string.Join(",", new List() { firstNetwork, secondNetwork }));
-
- var converter = new NetworkPayloadConverter();
- var networks = converter.ConvertNetworks(validMultipleNetworksJson).ToList();
-
- Assert.AreEqual(2, networks.Count());
- var ntw1 =
- networks.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
- var ntw2 =
- networks.First(o => string.Equals(o.Id, "54321", StringComparison.InvariantCultureIgnoreCase));
- Assert.IsNotNull(ntw1);
- Assert.IsNotNull(ntw2);
-
- Assert.AreEqual("12345", ntw1.Id);
- Assert.AreEqual("MyNetwork", ntw1.Name);
- Assert.AreEqual(NetworkStatus.Active, ntw1.Status);
-
- Assert.AreEqual("54321", ntw2.Id);
- Assert.AreEqual("NetworkMy", ntw2.Name);
- Assert.AreEqual(NetworkStatus.Down, ntw2.Status);
- }
-
- [TestMethod]
- public void CanConvertValidNetworksJsonPayloadWithSingleNetwork()
- {
- var validMultipleNetworkJsonFixture = @"{{ ""networks"": [ {0} ] }}";
- var firstNetwork = CreateNetworkJsonFixtrue("12345", "MyNetwork", NetworkStatus.Active);
-
- var validMultipleNetworksJson = string.Format(validMultipleNetworkJsonFixture,
- string.Join(",", new List() { firstNetwork }));
-
- var converter = new NetworkPayloadConverter();
- var networks = converter.ConvertNetworks(validMultipleNetworksJson).ToList();
-
- Assert.AreEqual(1, networks.Count());
- var ntw1 =
- networks.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
-
- Assert.IsNotNull(ntw1);
-
- Assert.AreEqual("12345", ntw1.Id);
- Assert.AreEqual("MyNetwork", ntw1.Name);
- Assert.AreEqual(NetworkStatus.Active, ntw1.Status);
- }
-
- [TestMethod]
- public void CanParseValidNetworksPayloadWithEmptyJsonArray()
- {
- var emptyJsonArray = @"{ ""networks"": [ ] }";
-
- var converter = new NetworkPayloadConverter();
- var networks = converter.ConvertNetworks(emptyJsonArray).ToList();
-
- Assert.AreEqual(0, networks.Count());
- }
-
- [TestMethod]
- public void CanParseAnEmptyNetworksPayload()
- {
- var payload = string.Empty;
-
- var converter = new NetworkPayloadConverter();
- var networks = converter.ConvertNetworks(payload).ToList();
-
- Assert.AreEqual(0, networks.Count());
- }
-
- [TestMethod]
- [ExpectedException(typeof(ArgumentNullException))]
- public void CannotParseANullNetworksPayload()
- {
- var converter = new NetworkPayloadConverter();
- converter.ConvertNetworks(null);
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidNetworksJsonPayload()
- {
- var converter = new NetworkPayloadConverter();
- converter.ConvertNetworks("[ { \"SomeAtrib\" }]");
- }
-
- [TestMethod]
- [ExpectedException(typeof(FormatException))]
- public void CannotParseInvalidNetworksPayload()
- {
- var converter = new NetworkPayloadConverter();
- converter.ConvertNetworks("NOT JSON");
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Network/NetworkRestSimulator.cs b/OpenStack/OpenStack.Test/Network/NetworkRestSimulator.cs
deleted file mode 100644
index f3b8bb2..0000000
--- a/OpenStack/OpenStack.Test/Network/NetworkRestSimulator.cs
+++ /dev/null
@@ -1,277 +0,0 @@
-// /* ============================================================================
-// 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 System.CodeDom.Compiler;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Net;
-using System.Net.Mime;
-using System.Text;
-using System.Threading;
-using Newtonsoft.Json;
-using Newtonsoft.Json.Linq;
-using OpenStack.Common;
-using OpenStack.Common.Http;
-using OpenStack.Network;
-
-namespace OpenStack.Test.Network
-{
- public class NetworkRestSimulator : RestSimulator
- {
- internal ICollection Networks { get; private set; }
-
- internal ICollection FloatingIps { get; private set; }
-
- public NetworkRestSimulator() : base()
- {
- this.Networks = new List();
- this.FloatingIps = new List();
- }
-
- public NetworkRestSimulator(CancellationToken token)
- : this()
- {
- }
-
- protected override IHttpResponseAbstraction HandleGet()
- {
- if (this.Uri.Segments.Count() >= 3)
- {
- switch (this.Uri.Segments[2].TrimEnd('/').ToLower())
- {
- case "networks":
- return HandleGetNetworks();
- case "floatingips":
- return HandleGetFloatingIps();
- }
- }
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandleGetNetworks()
- {
- Stream networkContent;
- switch (this.Uri.Segments.Count())
- {
- case 3:
- //no flavor id given, list all flavors
- networkContent = TestHelper.CreateStream(GenerateCollectionPayload(this.Networks, this.GenerateNetworkPayload, "networks"));
- break;
- default:
- //Unknown Uri format
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), networkContent);
- }
-
- internal IHttpResponseAbstraction HandleGetFloatingIps()
- {
- Stream floatingIpContent;
- switch (this.Uri.Segments.Count())
- {
- case 3:
- floatingIpContent = TestHelper.CreateStream(GenerateCollectionPayload(this.FloatingIps, this.GenerateFloatingIpPayload, "floatingips"));
- break;
- case 4:
- var floatId = this.Uri.Segments[3].TrimEnd('/').ToLower();
- return HandleGetFloatingIp(floatId);
- default:
- //Unknown Uri format
- throw new NotImplementedException();
- }
-
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), floatingIpContent);
- }
-
- internal IHttpResponseAbstraction HandleGetFloatingIp(string floatingIpId)
- {
- var payloadFixture = @"{{
- ""floatingip"": {0}
- }}";
-
- var floatIp = this.FloatingIps.FirstOrDefault(ip => ip.Id == floatingIpId);
- if (floatIp == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- var floatIpContent = string.Format(payloadFixture, GenerateFloatingIpPayload(floatIp)).ConvertToStream();
- return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary(), floatIpContent);
- }
-
- protected override IHttpResponseAbstraction HandlePost()
- {
- if (this.Uri.Segments.Count() >= 3)
- {
- switch (this.Uri.Segments[2].TrimEnd('/').ToLower())
- {
- case "floatingips":
- return HandleCreateFloatingIp();
- }
- }
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandleCreateFloatingIp()
- {
- var payloadFixture = @"{{
- ""floatingip"": {0}
- }}";
-
- var ip = new FloatingIp(Guid.NewGuid().ToString(), "172.0.0." +(this.FloatingIps.Count +1), FloatingIpStatus.Active);
- this.FloatingIps.Add(ip);
- var floatIpContent = string.Format(payloadFixture, GenerateFloatingIpPayload(ip)).ConvertToStream();
- return TestHelper.CreateResponse(HttpStatusCode.Created, new Dictionary(), floatIpContent);
- }
-
- protected override IHttpResponseAbstraction HandlePut()
- {
- throw new NotImplementedException();
- }
-
- protected override IHttpResponseAbstraction HandleDelete()
- {
- if (this.Uri.Segments.Count() >= 3)
- {
- switch (this.Uri.Segments[2].TrimEnd('/').ToLower())
- {
- case "floatingips":
- if (this.Uri.Segments.Count() == 4)
- {
- var floatId = this.Uri.Segments[3].TrimEnd('/').ToLower();
- return HandleDeleteFloatingIps(floatId);
- }
- break;
- default:
- throw new NotImplementedException();
- }
- }
- throw new NotImplementedException();
- }
-
- internal IHttpResponseAbstraction HandleDeleteFloatingIps(string floatingIpId)
- {
- var floatIp = this.FloatingIps.FirstOrDefault(ip => ip.Id == floatingIpId);
- if (floatIp == null)
- {
- return TestHelper.CreateResponse(HttpStatusCode.NotFound);
- }
-
- this.FloatingIps.Remove(floatIp);
- return TestHelper.CreateResponse(HttpStatusCode.NoContent, new Dictionary());
- }
-
-
- protected override IHttpResponseAbstraction HandleHead()
- {
- throw new NotImplementedException();
- }
-
- protected override IHttpResponseAbstraction HandleCopy()
- {
- throw new NotImplementedException();
- }
-
- private string GenerateCollectionPayload(IEnumerable collection, Func genFunc,
- string collectionName)
- {
- var payload = new StringBuilder();
- payload.Append(string.Format("{{ \"{0}\": [", collectionName));
- var first = true;
- foreach (var item in collection)
- {
- if (!first)
- {
- payload.Append(",");
- }
-
- payload.Append(genFunc(item));
- first = false;
- }
- payload.Append("] }");
- return payload.ToString();
- }
-
- private string GenerateNetworkPayload(OpenStack.Network.Network network)
- {
- var payloadFixture = @"{{
- ""status"": ""{2}"",
- ""subnets"": [
- ""d3839504-ec4c-47a4-b7c7-07af079a48bb""
- ],
- ""name"": ""{0}"",
- ""router:external"": false,
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""admin_state_up"": true,
- ""shared"": false,
- ""id"": ""{1}""
- }}";
- return string.Format(payloadFixture, network.Name, network.Id, network.Status.ToString().ToUpper());
- }
-
- private string GenerateFloatingIpPayload(FloatingIp floatingIp)
- {
- var payloadFixture = @"{{
- ""router_id"": ""fafac59b-a94a-4525-8700-f4f448e0ac97"",
- ""status"": ""{1}"",
- ""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
- ""floating_network_id"": ""3eaab3f7-d3f2-430f-aa73-d07f39aae8f4"",
- ""fixed_ip_address"": ""10.0.0.2"",
- ""floating_ip_address"": ""{2}"",
- ""port_id"": ""9da94672-6e6b-446c-9579-3dd5484b31fd"",
- ""id"": ""{0}""
- }}";
- return string.Format(payloadFixture, floatingIp.Id, floatingIp.Status.ToString().ToUpper(), floatingIp.FloatingIpAddress);
- }
- }
-
- public class NetworkRestSimulatorFactory : IHttpAbstractionClientFactory
- {
- internal NetworkRestSimulator Simulator = null;
-
- public NetworkRestSimulatorFactory(NetworkRestSimulator simulator)
- {
- this.Simulator = simulator;
- }
-
- public IHttpAbstractionClient Create()
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(CancellationToken token)
- {
- if (this.Simulator != null)
- {
- this.Simulator.Headers.Clear();
- }
- return this.Simulator ?? new NetworkRestSimulator(token);
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout)
- {
- throw new NotImplementedException();
- }
-
- public IHttpAbstractionClient Create(TimeSpan timeout, CancellationToken token)
- {
- throw new NotImplementedException();
- }
- }
-}
diff --git a/OpenStack/OpenStack.Test/Network/NetworkServiceClientTests.cs b/OpenStack/OpenStack.Test/Network/NetworkServiceClientTests.cs
deleted file mode 100644
index 513278e..0000000
--- a/OpenStack/OpenStack.Test/Network/NetworkServiceClientTests.cs
+++ /dev/null
@@ -1,192 +0,0 @@
-// /* ============================================================================
-// 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 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;
-using OpenStack.Network;
-
-namespace OpenStack.Test.Network
-{
- [TestClass]
- public class NetworkServiceClientTests
- {
- internal TestNetworkServicePocoClient ServicePocoClient;
-
- internal string authId = "12345";
- internal string endpoint = "http://testcomputeendpoint.com/v2/1234567890";
- internal ServiceLocator ServiceLocator;
-
- [TestInitialize]
- public void TestSetup()
- {
- this.ServicePocoClient = new TestNetworkServicePocoClient();
- this.ServiceLocator = new ServiceLocator();
-
- var manager = this.ServiceLocator.Locate();
- manager.RegisterServiceInstance(typeof(INetworkServicePocoClientFactory), new TestNetworkServicePocoClientFactory(this.ServicePocoClient));
- }
-
- [TestCleanup]
- public void TestCleanup()
- {
- this.ServicePocoClient = new TestNetworkServicePocoClient();
- this.ServiceLocator = new ServiceLocator();
- }
-
- IOpenStackCredential GetValidCreds()
- {
- var catalog = new OpenStackServiceCatalog();
- catalog.Add(new OpenStackServiceDefinition("Neutron", "Network Service",
- new List()
- {
- new OpenStackServiceEndpoint(endpoint, string.Empty, "some version", "some version info", "1,2,3")
- }));
-
- var creds = new OpenStackCredential(new Uri(this.endpoint), "SomeUser", "Password", "SomeTenant");
- creds.SetAccessTokenId(this.authId);
- creds.SetServiceCatalog(catalog);
- return creds;
- }
-
- [TestMethod]
- public async Task CanGetNetworks()
- {
- var ntw1 = new OpenStack.Network.Network("12345","MyNetwork", NetworkStatus.Active);
- var ntw2 = new OpenStack.Network.Network("54321", "NetworkMy", NetworkStatus.Down);
- var networks = new List