Skip to content

Commit

Permalink
Xunit integration tests (#98)
Browse files Browse the repository at this point in the history
* comment out all the things

* do a bit less

* more fixy

* moar

* more

* more

* moar

* more

* stupid tests are stupid

* all async client

* More

* clean up

* fix dumb test

* vhost per test

* restore more tests

* more

* async is annoying

* configure await false
  • Loading branch information
jonnii authored Nov 15, 2017
1 parent ffb5c77 commit 67840a7
Show file tree
Hide file tree
Showing 25 changed files with 892 additions and 919 deletions.
53 changes: 7 additions & 46 deletions src/Chinchilla.Api/IRabbitAdmin.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Threading.Tasks;

namespace Chinchilla.Api
{
public interface IRabbitAdmin
{
Task<IEnumerable<VirtualHost>> VirtualHostsAsync();
Task<VirtualHost[]> VirtualHostsAsync();

Task<IEnumerable<Connection>> ConnectionsAsync();
Task<Connection[]> ConnectionsAsync();

Task<IEnumerable<Exchange>> ExchangesAsync(VirtualHost virtualHost);
Task<Exchange[]> ExchangesAsync(VirtualHost virtualHost);

Task<IEnumerable<Queue>> QueuesAsync(VirtualHost virtualHost);
Task<Queue[]> QueuesAsync(VirtualHost virtualHost);

Task<IEnumerable<Permissions>> PermissionsAsync(VirtualHost virtualHost);
Task<Permissions[]> PermissionsAsync(VirtualHost virtualHost);

Task<bool> CreateAsync(VirtualHost virtualHost);

Expand All @@ -39,44 +38,6 @@ public interface IRabbitAdmin

Task<bool> DeleteAsync(Connection connection);

Task<IEnumerable<Message>> MessagesAsync(VirtualHost virtualHost, Queue queue);



IEnumerable<VirtualHost> VirtualHosts();

IEnumerable<Connection> Connections();

IEnumerable<Exchange> Exchanges(VirtualHost virtualHost);

IEnumerable<Queue> Queues(VirtualHost virtualHost);

IEnumerable<Permissions> Permissions(VirtualHost virtualHost);

bool Create(VirtualHost virtualHost);

bool Create(VirtualHost virtualHost, Queue queue);

bool Create(VirtualHost virtualHost, Queue queue, QueueOptions options);

bool Create(VirtualHost virtualHost, Exchange exchange);

bool Create(VirtualHost virtualHost, Exchange exchange, ExchangeOptions options);

bool Create(VirtualHost virtualHost, User user, Permission permission);

bool Create(VirtualHost virtualHost, Exchange exchange, Queue queue);

bool Create(VirtualHost virtualHost, Exchange exchange, Queue queue, BindingOptions options);

bool Exists(VirtualHost virtualHost, Queue queue);

bool Exists(VirtualHost virtualHost, Exchange exchange);

bool Delete(VirtualHost virtualHost);

bool Delete(Connection connection);

IEnumerable<Message> Messages(VirtualHost virtualHost, Queue queue);
Task<Message[]> MessagesAsync(VirtualHost virtualHost, Queue queue);
}
}
120 changes: 15 additions & 105 deletions src/Chinchilla.Api/RabbitAdmin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ public RabbitAdmin(string root, string username, string password)
httpClient = new RabbitHttpClient(root.FormatWithReplacements(), username, password);
}

public Task<IEnumerable<VirtualHost>> VirtualHostsAsync()
public Task<VirtualHost[]> VirtualHostsAsync()
{
return httpClient.ExecuteList<VirtualHost>("vhosts");
}

public Task<IEnumerable<Connection>> ConnectionsAsync()
public Task<Connection[]> ConnectionsAsync()
{
return httpClient.ExecuteList<Connection>("connections");
}

public Task<IEnumerable<Exchange>> ExchangesAsync(VirtualHost virtualHost)
public Task<Exchange[]> ExchangesAsync(VirtualHost virtualHost)
{
return httpClient.ExecuteList<Exchange>("exchanges/{vhost}", new Dictionary<string, string> { { "vhost", virtualHost.Name } });
}

public Task<IEnumerable<Queue>> QueuesAsync(VirtualHost virtualHost)
public Task<Queue[]> QueuesAsync(VirtualHost virtualHost)
{
return httpClient.ExecuteList<Queue>("queues/{vhost}", new Dictionary<string, string> { { "vhost", virtualHost.Name } });
}

public Task<IEnumerable<Permissions>> PermissionsAsync(VirtualHost virtualHost)
public Task<Permissions[]> PermissionsAsync(VirtualHost virtualHost)
{
return httpClient.ExecuteList<Permissions>("vhosts/{name}/permissions", new Dictionary<string, string> { { "name", virtualHost.Name } });
}
Expand All @@ -53,7 +53,7 @@ public async Task<bool> CreateAsync(VirtualHost virtualHost)
new Dictionary<string, string>
{
{"name", virtualHost.Name}
});
}).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.Created;
}
Expand All @@ -72,7 +72,7 @@ public async Task<bool> CreateAsync(VirtualHost virtualHost, Queue queue, QueueO
{"vhost", virtualHost.Name},
{"name", queue.Name}
},
options);
options).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.NoContent;
}
Expand All @@ -91,7 +91,7 @@ public async Task<bool> CreateAsync(VirtualHost virtualHost, Exchange exchange,
{"vhost", virtualHost.Name},
{"name", exchange.Name}
},
options);
options).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.NoContent;
}
Expand All @@ -107,7 +107,7 @@ public async Task<bool> CreateAsync(VirtualHost virtualHost, Exchange exchange,
HttpMethod.Post,
"bindings/{vhost}/e/{exchange}/q/{queue}",
new Dictionary<string, string> { { "vhost", virtualHost.Name }, { "exchange", exchange.Name }, { "queue", queue.Name } },
options);
options).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.Created;
}
Expand All @@ -119,7 +119,7 @@ public async Task<bool> DeleteAsync(VirtualHost virtualHost)
new Dictionary<string, string>
{
{"name", virtualHost.Name}
});
}).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.NoContent;
}
Expand All @@ -131,7 +131,7 @@ public async Task<bool> DeleteAsync(Connection connection)
new Dictionary<string, string>
{
{"name", connection.Name}
});
}).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.NoContent;
}
Expand All @@ -143,25 +143,25 @@ public async Task<bool> CreateAsync(VirtualHost virtualHost, User user, Permissi
"permissions/{vhost}/{user}",
new Dictionary<string, string> { { "vhost", virtualHost.Name }, { "user", user.Name } },
permission
);
).ConfigureAwait(false);

return response.StatusCode == HttpStatusCode.NoContent;
}

public async Task<bool> ExistsAsync(VirtualHost virtualHost, Queue queue)
{
var queues = await QueuesAsync(virtualHost);
var queues = await QueuesAsync(virtualHost).ConfigureAwait(false);
return queues.Any(q => q.Name == queue.Name);
}

public async Task<bool> ExistsAsync(VirtualHost virtualHost, Exchange exchange)
{
var exchanges = await ExchangesAsync(virtualHost);
var exchanges = await ExchangesAsync(virtualHost).ConfigureAwait(false);

return exchanges.Any(e => e.Name == exchange.Name);
}

public Task<IEnumerable<Message>> MessagesAsync(VirtualHost virtualHost, Queue queue)
public Task<Message[]> MessagesAsync(VirtualHost virtualHost, Queue queue)
{
var options = new
{
Expand All @@ -180,95 +180,5 @@ public Task<IEnumerable<Message>> MessagesAsync(VirtualHost virtualHost, Queue q
options
);
}

public IEnumerable<VirtualHost> VirtualHosts()
{
return VirtualHostsAsync().Result;
}

public IEnumerable<Connection> Connections()
{
return ConnectionsAsync().Result;
}

public IEnumerable<Exchange> Exchanges(VirtualHost virtualHost)
{
return ExchangesAsync(virtualHost).Result;
}

public IEnumerable<Queue> Queues(VirtualHost virtualHost)
{
return QueuesAsync(virtualHost).Result;
}

public IEnumerable<Permissions> Permissions(VirtualHost virtualHost)
{
return PermissionsAsync(virtualHost).Result;
}

public bool Create(VirtualHost virtualHost)
{
return CreateAsync(virtualHost).Result;
}

public bool Create(VirtualHost virtualHost, Queue queue)
{
return CreateAsync(virtualHost, queue).Result;
}

public bool Create(VirtualHost virtualHost, Queue queue, QueueOptions options)
{
return CreateAsync(virtualHost, queue, options).Result;
}

public bool Create(VirtualHost virtualHost, Exchange exchange)
{
return CreateAsync(virtualHost, exchange).Result;
}

public bool Create(VirtualHost virtualHost, Exchange exchange, ExchangeOptions options)
{
return CreateAsync(virtualHost, exchange, options).Result;
}

public bool Create(VirtualHost virtualHost, User user, Permission permission)
{
return CreateAsync(virtualHost, user, permission).Result;
}

public bool Create(VirtualHost virtualHost, Exchange exchange, Queue queue)
{
return CreateAsync(virtualHost, exchange, queue).Result;
}

public bool Create(VirtualHost virtualHost, Exchange exchange, Queue queue, BindingOptions options)
{
return CreateAsync(virtualHost, exchange, queue, options).Result;
}

public bool Exists(VirtualHost virtualHost, Queue queue)
{
return ExistsAsync(virtualHost, queue).Result;
}

public bool Exists(VirtualHost virtualHost, Exchange exchange)
{
return ExistsAsync(virtualHost, exchange).Result;
}

public bool Delete(VirtualHost virtualHost)
{
return DeleteAsync(virtualHost).Result;
}

public bool Delete(Connection connection)
{
return DeleteAsync(connection).Result;
}

public IEnumerable<Message> Messages(VirtualHost virtualHost, Queue queue)
{
return MessagesAsync(virtualHost, queue).Result;
}
}
}
22 changes: 11 additions & 11 deletions src/Chinchilla.Api/RabbitHttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,31 @@ public async Task<T> Execute<T>(
{
var request = CreateRequest(resource, parameters, HttpMethod.Get, body);

var response = await client.SendAsync(request);
return await DeserializeResponse<T>(response);
var response = await client.SendAsync(request).ConfigureAwait(false);
return await DeserializeResponse<T>(response).ConfigureAwait(false);
}

public async Task<IEnumerable<T>> ExecuteList<T>(
public async Task<T[]> ExecuteList<T>(
string resource,
IEnumerable<KeyValuePair<string, string>> parameters = null,
object body = null)
{
var request = CreateRequest(resource, parameters, HttpMethod.Get, body);

var response = await client.SendAsync(request);
return await DeserializeResponse<List<T>>(response);
var response = await client.SendAsync(request).ConfigureAwait(false);
return await DeserializeResponse<T[]>(response).ConfigureAwait(false);
}

public async Task<IEnumerable<T>> ExecuteList<T>(
public async Task<T[]> ExecuteList<T>(
HttpMethod method,
string resource,
IEnumerable<KeyValuePair<string, string>> parameters = null,
object body = null)
{
var request = CreateRequest(resource, parameters, method, body);

var response = await client.SendAsync(request);
return await DeserializeResponse<List<T>>(response);
var response = await client.SendAsync(request).ConfigureAwait(false);
return await DeserializeResponse<T[]>(response).ConfigureAwait(false);
}

public async Task<T> Execute<T>(
Expand All @@ -90,13 +90,13 @@ public async Task<T> Execute<T>(
{
var request = CreateRequest(resource, parameters, method, body);

var response = await client.SendAsync(request);
return await DeserializeResponse<T>(response);
var response = await client.SendAsync(request).ConfigureAwait(false);
return await DeserializeResponse<T>(response).ConfigureAwait(false);
}

private async Task<T> DeserializeResponse<T>(HttpResponseMessage response)
{
var content = await response.Content.ReadAsStreamAsync();
var content = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);

using (var streamReader = new StreamReader(content))
{
Expand Down
9 changes: 5 additions & 4 deletions src/Chinchilla.Integration/Chinchilla.Integration.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,16 @@

<ItemGroup>
<PackageReference Include="Castle.Core" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="nunit" Version="3.8.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
<PackageReference Include="RabbitMq.Client" Version="5.0.1" />

<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="xunit" Version="2.3.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Chinchilla.Api\Chinchilla.Api.csproj" />
<ProjectReference Include="..\Chinchilla.Serializers.JsonNET\Chinchilla.Serializers.JsonNET.csproj" />
<ProjectReference Include="..\Chinchilla.Serializers.MsgPack\Chinchilla.Serializers.MsgPack.csproj" />
<ProjectReference Include="..\Chinchilla\Chinchilla.csproj" />
</ItemGroup>
Expand Down
Loading

0 comments on commit 67840a7

Please sign in to comment.