-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from Unleash/feature/supporting-project-query
feat: support project query parameter (#69)
- Loading branch information
Showing
7 changed files
with
126 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/Unleash.Tests/Communication/UnleashApiClient_Project_Tests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using Unleash.Communication; | ||
using Unleash.Serialization; | ||
using Unleash.Tests.Mock; | ||
|
||
namespace Unleash.Tests.Communication | ||
{ | ||
public class UnleashApiClient_Project_Tests | ||
{ | ||
private UnleashApiClient NewTestableClient(string project, MockHttpMessageHandler messageHandler) | ||
{ | ||
var apiUri = new Uri("http://unleash.herokuapp.com/api/"); | ||
|
||
var jsonSerializer = new DynamicNewtonsoftJsonSerializer(); | ||
jsonSerializer.TryLoad(); | ||
|
||
var requestHeaders = new UnleashApiClientRequestHeaders | ||
{ | ||
AppName = "api-test-client", | ||
InstanceTag = "instance1", | ||
CustomHttpHeaders = null, | ||
CustomHttpHeaderProvider = null | ||
}; | ||
|
||
var httpClient = new HttpClient(messageHandler) | ||
{ | ||
BaseAddress = apiUri, | ||
Timeout = TimeSpan.FromSeconds(5) | ||
}; | ||
|
||
return new UnleashApiClient(httpClient, jsonSerializer, requestHeaders, project); | ||
} | ||
|
||
[Test] | ||
public async Task FetchToggles_ForProject() | ||
{ | ||
var project = "testproject"; | ||
var messageHandler = new MockHttpMessageHandler(); | ||
var client = NewTestableClient(project, messageHandler); | ||
|
||
var toggles = await client.FetchToggles("", CancellationToken.None); | ||
toggles.Should().NotBeNull(); | ||
|
||
messageHandler.SentMessages.Count.Should().Be(1); | ||
messageHandler.SentMessages.First().RequestUri.Query.Should().Be("?project=" + project); | ||
} | ||
|
||
[Test] | ||
public async Task FetchToggles_WithoutProject() | ||
{ | ||
string project = null; | ||
var messageHandler = new MockHttpMessageHandler(); | ||
var client = NewTestableClient(project, messageHandler); | ||
|
||
var toggles = await client.FetchToggles("", CancellationToken.None); | ||
toggles.Should().NotBeNull(); | ||
|
||
messageHandler.SentMessages.Count.Should().Be(1); | ||
messageHandler.SentMessages.First().RequestUri.Query.Should().Be(""); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Unleash.Tests.Mock | ||
{ | ||
public class MockHttpMessageHandler : HttpMessageHandler | ||
{ | ||
public List<HttpRequestMessage> SentMessages = new List<HttpRequestMessage>(); | ||
|
||
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
SentMessages.Add(request); | ||
|
||
return Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.OK) | ||
{ | ||
Content = new StringContent("{}", Encoding.UTF8, "application/json") | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters