Skip to content

Commit

Permalink
Merge pull request #134 from contentful/feature/add-environment-endpo…
Browse files Browse the repository at this point in the history
…ints

Feature/add environment endpoints
  • Loading branch information
Roblinde authored Apr 16, 2018
2 parents f632dfb + a285de9 commit 17ab01f
Show file tree
Hide file tree
Showing 21 changed files with 1,726 additions and 105 deletions.
6 changes: 3 additions & 3 deletions Contentful.AspNetCore/Contentful.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Description>Official .NET SDK for the Contentful Content Delivery and Management API for ASP.NET core.</Description>
<PackageId>contentful.aspnetcore</PackageId>
<NeutralLanguage>en-US</NeutralLanguage>
<VersionPrefix>2.0.3</VersionPrefix>
<VersionPrefix>2.1.0</VersionPrefix>
<TargetFramework>netstandard1.6</TargetFramework>
<Authors>Contentful</Authors>
<Copyright>Contentful GmbH.</Copyright>
Expand All @@ -14,13 +14,13 @@
<PackageLicenseUrl>https://github.com/contentful/contentful.net/master/LICENSE</PackageLicenseUrl>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>git://github.com/contentful/contentful.net</RepositoryUrl>
<Version>2.0.3</Version>
<Version>2.1.0</Version>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.5\Contentful.AspNetCore.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="contentful.csharp" Version="2.0.3" />
<PackageReference Include="contentful.csharp" Version="2.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Razor" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="1.1.2" />
Expand Down
5 changes: 5 additions & 0 deletions Contentful.Core.Tests/ClientTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,22 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
VerifyRequest?.Invoke(request);
VerificationBeforeSend?.Invoke();

await Task.Delay(Delay);

if (Responses.Count > 0)
{
cancellationToken.ThrowIfCancellationRequested();
return await Task.FromResult(Responses.Dequeue());
}

cancellationToken.ThrowIfCancellationRequested();
return await Task.FromResult(Response);
}
public Action<HttpRequestMessage> VerifyRequest { get; set; }
public Action VerificationBeforeSend { get; set; }
public Queue<HttpResponseMessage> Responses { get; set; }
public HttpResponseMessage Response { get; set; }
public int Delay { get; set; }
}

public class TwoAssets
Expand Down
4 changes: 4 additions & 0 deletions Contentful.Core.Tests/Contentful.Core.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
</PropertyGroup>
<ItemGroup>
<None Remove="JsonFiles\EntriesCollectionWithSelfreference.json" />
<None Remove="JsonFiles\EnvironmentsCollection.json" />
<None Remove="JsonFiles\SampleContentTypeFields.json" />
<None Remove="JsonFiles\SampleEnvironment.json" />
<None Remove="JsonFiles\SampleUser.json" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="JsonFiles\EnvironmentsCollection.json" />
<EmbeddedResource Include="JsonFiles\EntriesCollectionWithSelfreference.json" />
<EmbeddedResource Include="JsonFiles\NestedSharedStructure.json" />
<EmbeddedResource Include="JsonFiles\EntriesCollectionWithoutSys.json" />
Expand All @@ -22,6 +25,7 @@
<EmbeddedResource Include="JsonFiles\MultipleLinksSameAsset.json" />
<EmbeddedResource Include="JsonFiles\SampleAssetManagementUnprocessed.json" />
<EmbeddedResource Include="JsonFiles\SampleContentTypeFields.json" />
<EmbeddedResource Include="JsonFiles\SampleEnvironment.json" />
<EmbeddedResource Include="JsonFiles\SampleSnapshotContentType.json" />
<EmbeddedResource Include="JsonFiles\SampleUser.json" />
<EmbeddedResource Include="JsonFiles\TokensCollection.json" />
Expand Down
147 changes: 143 additions & 4 deletions Contentful.Core.Tests/ContentfulClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -711,16 +711,17 @@ public async Task SyncInitialRecursiveShouldSyncAllPagesOfSyncIntoSingleSyncResu
}

[Fact]
public void CancellingRequestShouldSuccesfulAbortRequest()
public async Task CancellingRequestShouldSuccesfulAbortRequest()
{
//Arrange
var source = new CancellationTokenSource(1500);
_handler.VerificationBeforeSend = async () => { await Task.Delay(3000); };
_handler.Response = GetResponseFromFile(@"SampleEntry.json");
_handler.Delay = 3000;
//Act
var ex = Assert.ThrowsAsync<OperationCanceledException>(async () => await _client.GetEntry<Entry<dynamic>>("123", "", source.Token));
var ex = await Assert.ThrowsAsync<OperationCanceledException>(async () => await _client.GetEntry<Entry<dynamic>>("123", "", source.Token));

//Assert
Assert.Equal(TaskStatus.Faulted,ex.Status);
Assert.Equal("The operation was canceled.",ex.Message);
}

[Fact]
Expand Down Expand Up @@ -887,5 +888,143 @@ public async Task ComplexStructureWithSelfReferenceInArrayIsDeserializedCorrectl
Assert.Equal(5, res.Count());
Assert.Equal(res.First().SubCategories.First().Sys.Id, res.Skip(3).First().Sys.Id);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForSingleAsset()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"SampleAsset.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetAsset("434");

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/assets/434", path);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForAssets()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"AssetsCollection.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetAssets();

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/assets/", path);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForSingleEntry()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"SampleEntry.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetEntry<dynamic>("444");

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/entries/444", path);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForEntries()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"EntriesCollection.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetEntries<dynamic>();

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/entries", path);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForSingleContentType()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"SampleContentType.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetContentType("123");

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/content_types/123", path);
}

[Fact]
public async Task SettingEnvironmentShouldYieldCorrectUrlForContentTypes()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"ContenttypesCollection.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};
//Act
await client.GetContentTypes();

//Assert
Assert.Equal("https://cdn.contentful.com/spaces/564/environments/special/content_types/", path);
}

[Fact]
public async Task SettingEnvironmentShouldThroworSyncInitial()
{
//Arrange
var client = GetClientWithEnvironment();
_handler.Response = GetResponseFromFile(@"InitialSyncNoNextPage.json");
var path = "";
_handler.VerifyRequest = (HttpRequestMessage request) =>
{
path = request.RequestUri.ToString();
};

//Act
var res = await Assert.ThrowsAsync<NotSupportedException>(async () => { await client.SyncInitial(); });
}

private ContentfulClient GetClientWithEnvironment(string env = "special")
{
var httpClient = new HttpClient(_handler);
var options = new ContentfulOptions
{
DeliveryApiKey = "123",
PreviewApiKey = "3123",
Environment = env,
SpaceId = "564"
};
var client = new ContentfulClient(httpClient, options);
return client;
}
}
}
Loading

0 comments on commit 17ab01f

Please sign in to comment.