Skip to content

Commit

Permalink
Add a failing unit test (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
daveleek committed Apr 28, 2021
1 parent 0e731fa commit 2809b36
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
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
{
[Test]
public async Task FetchToggles_ForProject()
{
var apiUri = new Uri("http://unleash.herokuapp.com/api/");
var project = "testproject";

var jsonSerializer = new DynamicNewtonsoftJsonSerializer();
jsonSerializer.TryLoad();

var requestHeaders = new UnleashApiClientRequestHeaders
{
AppName = "api-test-client",
InstanceTag = "instance1",
CustomHttpHeaders = null,
CustomHttpHeaderProvider = null
};

var messageHandler = new MockHttpMessageHandler();
var httpClient = new HttpClient(messageHandler)
{
BaseAddress = apiUri,
Timeout = TimeSpan.FromSeconds(5)
};

var client = new UnleashApiClient(httpClient, jsonSerializer, requestHeaders, project);
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);
}
}
}
1 change: 1 addition & 0 deletions tests/Unleash.Tests/Unleash.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
<ItemGroup>
<Compile Include="BaseTest.cs" />
<Compile Include="Communication\BaseUnleashApiClientTest.cs" />
<Compile Include="Communication\UnleashApiClient_Project_Tests.cs" />
<Compile Include="Communication\UnleashApiClient_RegisterClient_Tests.cs" />
<Compile Include="Communication\UnleashApiClient_SendMetrics_Tests.cs" />
<Compile Include="Communication\UnleashHttpClientFactory_RegisterHttpClient_Tests.cs" />
Expand Down

0 comments on commit 2809b36

Please sign in to comment.