Files
openstack-sdk-dotnet/OpenStack/OpenStack.Test/Compute/TestComputeServiceRestClient.cs
Wayne Foley a952269947 Adding support for creating, updating and deleting metadata on images and servers.
Updating. and adding unit tests.
Changing "ListImages" and "ListFlavors" to be more consistent with the GetX sematic.

Partially implements blueprint support-compute-api
Change-Id: Ia31599a20cb1fa42595fc92b504c00c936976c21
2014-06-12 10:29:31 -07:00

105 lines
3.5 KiB
C#

// /* ============================================================================
// 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<IHttpResponseAbstraction>();
}
public Queue<IHttpResponseAbstraction> Responses { get; set; }
public Task<IHttpResponseAbstraction> GetFlavors()
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> GetFlavor(string flavorId)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> GetServerMetadata(string serverId)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> UpdateServerMetadata(string serverId, IDictionary<string, string> metadata)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> DeleteServerMetadata(string serverId, string key)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> GetImages()
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> GetImage(string imageId)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> DeleteImage(string imageId)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> GetImageMetadata(string imageId)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> UpdateImageMetadata(string imageId, IDictionary<string, string> metadata)
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
public Task<IHttpResponseAbstraction> DeleteImageMetadata(string imageId, string key)
{
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;
}
}
}