Browse Source

TestSuite adapted for new CDN endpoints.

pull/487/head
Sebastian 6 years ago
parent
commit
fdca9a013c
  1. 102
      backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs
  2. 6
      backend/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs
  3. 4
      backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs
  4. 16
      backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs
  5. 10
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/ClientManagerFixture.cs
  6. 39
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/CloudFixture.cs
  7. 4
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentFixture.cs
  8. 2
      backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentQueryFixture.cs
  9. 2
      backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs
  10. 2
      backend/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs
  11. 2
      backend/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj

102
backend/tools/TestSuite/TestSuite.ApiTests/CDNTests.cs

@ -0,0 +1,102 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Net.Http;
using System.Threading.Tasks;
using TestSuite.Fixtures;
using TestSuite.Model;
using Xunit;
#pragma warning disable SA1300 // Element should begin with upper-case letter
#pragma warning disable SA1507 // Code should not contain multiple blank lines in a row
namespace TestSuite.ApiTests
{
public sealed class CDNTests : IClassFixture<CloudFixture>
{
public CloudFixture _ { get; }
public CDNTests(CloudFixture fixture)
{
_ = fixture;
}
[Fact]
public void Should_provide_asset_url_from_cdn()
{
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
var url = _.CDNClientManager.GenerateImageUrl(id);
Assert.StartsWith("https://assets.squidex.io/", url);
}
[Fact]
public async Task Should_download_asset_url_from_cdn()
{
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
var url = _.CDNClientManager.GenerateImageUrl(id);
await DownloadAsync(url);
}
[Fact]
public void Should_provide_asset_url_from_cloud_when_cdn_not_configured()
{
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
var url = _.ClientManager.GenerateImageUrl(id);
Assert.StartsWith("https://cloud.squidex.io/", url);
}
[Fact]
public async Task Should_download_asset_url_from_cloud_when_cdn_not_configured()
{
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
var url = _.ClientManager.GenerateImageUrl(id);
await DownloadAsync(url);
}
[Fact]
public async Task Should_get_blog_items_from_cdn()
{
var client = _.CDNClientManager.CreateContentsClient<TestEntity, TestEntityData>("blog");
var result = await client.GetAsync();
Assert.NotEmpty(result.Items);
}
[Fact]
public async Task Should_get_blog_items_from_cloud_when_cdn_not_configured()
{
var client = _.ClientManager.CreateContentsClient<TestEntity, TestEntityData>("blog");
var result = await client.GetAsync();
Assert.NotEmpty(result.Items);
}
private static async Task DownloadAsync(string url)
{
using (var client = new HttpClient())
{
var response = await client.GetAsync(url);
response.EnsureSuccessStatusCode();
var buffer = await response.Content.ReadAsByteArrayAsync();
Assert.True(buffer.Length > 1000);
}
}
}
}

6
backend/tools/TestSuite/TestSuite.ApiTests/ContentCleanupTests.cs

@ -34,7 +34,7 @@ namespace TestSuite.ApiTests
// STEP 1: Create a schema.
var schema = await TestEntity.CreateSchemaAsync(_.Schemas, _.AppName, schemaName);
var contents = _.ClientManager.GetClient<TestEntity, TestEntityData>(schemaName);
var contents = _.ClientManager.CreateContentsClient<TestEntity, TestEntityData>(schemaName);
// STEP 2: Create a content for this schema.
@ -64,7 +64,7 @@ namespace TestSuite.ApiTests
// STEP 1: Create a schema.
await TestEntityWithReferences.CreateSchemaAsync(_.Schemas, _.AppName, schemaName);
var contents = _.ClientManager.GetClient<TestEntityWithReferences, TestEntityWithReferencesData>(schemaName);
var contents = _.ClientManager.CreateContentsClient<TestEntityWithReferences, TestEntityWithReferencesData>(schemaName);
// STEP 2: Create a referenced content.
@ -74,7 +74,7 @@ namespace TestSuite.ApiTests
// STEP 3: Create a content with a reference.
var dataB = new TestEntityWithReferencesData { References = new[] { Guid.Parse(contentA_1.Id) } };
var dataB = new TestEntityWithReferencesData { References = new[] { contentA_1.Id } };
var contentB_1 = await contents.CreateAsync(dataB);

4
backend/tools/TestSuite/TestSuite.ApiTests/ContentQueryTests.cs

@ -35,7 +35,7 @@ namespace TestSuite.ApiTests
{
var items = await _.Contents.GetAsync(new ContentQuery { OrderBy = "data/number/iv asc" });
var itemsById = await _.Contents.GetAsync(new HashSet<Guid>(items.Items.Take(3).Select(x => x.EntityId)));
var itemsById = await _.Contents.GetAsync(new HashSet<Guid>(items.Items.Take(3).Select(x => x.Id)));
Assert.Equal(3, itemsById.Items.Count);
Assert.Equal(3, itemsById.Total);
@ -249,7 +249,7 @@ namespace TestSuite.ApiTests
public int Number { get; set; }
}
private void AssertItems(SquidexEntities<TestEntity, TestEntityData> entities, int total, int[] expected)
private void AssertItems(ContentsResult<TestEntity, TestEntityData> entities, int total, int[] expected)
{
Assert.Equal(total, entities.Total);
Assert.Equal(expected, entities.Items.Select(x => x.Data.Number).ToArray());

16
backend/tools/TestSuite/TestSuite.ApiTests/ContentUpdateTests.cs

@ -41,7 +41,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -60,7 +60,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -79,7 +79,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -99,7 +99,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -120,7 +120,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -142,7 +142,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -165,7 +165,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}
@ -188,7 +188,7 @@ namespace TestSuite.ApiTests
}
finally
{
if (content.Id != null)
if (content != null)
{
await _.Contents.DeleteAsync(content.Id);
}

10
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ClientManagerFixture.cs

@ -24,10 +24,14 @@ namespace TestSuite.Fixtures
public ClientManagerFixture()
{
ClientManager = new SquidexClientManager(ServerUrl, AppName, ClientId, ClientSecret)
ClientManager = new SquidexClientManager(new SquidexOptions
{
ReadResponseAsString = true
};
AppName = AppName,
ClientId = ClientId,
ClientSecret = ClientSecret,
ReadResponseAsString = true,
Url = ServerUrl
});
}
public virtual void Dispose()

39
backend/tools/TestSuite/TestSuite.Shared/Fixtures/CloudFixture.cs

@ -0,0 +1,39 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Squidex.ClientLibrary;
namespace TestSuite.Fixtures
{
public sealed class CloudFixture
{
public SquidexClientManager ClientManager { get; private set; }
public SquidexClientManager CDNClientManager { get; private set; }
public CloudFixture()
{
ClientManager = new SquidexClientManager(
new SquidexOptions
{
AppName = "squidex-website",
ClientId = "squidex-website:reader",
ClientSecret = "yy9x4dcxsnp1s34r2z19t88wedbzxn1tfq7uzmoxf60x"
});
CDNClientManager = new SquidexClientManager(
new SquidexOptions
{
AppName = "squidex-website",
AssetCDN = "https://assets.squidex.io",
ClientId = "squidex-website:reader",
ClientSecret = "yy9x4dcxsnp1s34r2z19t88wedbzxn1tfq7uzmoxf60x",
ContentCDN = "https://contents.squidex.io",
});
}
}
}

4
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentFixture.cs

@ -14,7 +14,7 @@ namespace TestSuite.Fixtures
{
public class ContentFixture : CreatedAppFixture
{
public SquidexClient<TestEntity, TestEntityData> Contents { get; }
public IContentsClient<TestEntity, TestEntityData> Contents { get; }
public string SchemaName { get; }
@ -42,7 +42,7 @@ namespace TestSuite.Fixtures
}
}).Wait();
Contents = ClientManager.GetClient<TestEntity, TestEntityData>(SchemaName);
Contents = ClientManager.CreateContentsClient<TestEntity, TestEntityData>(SchemaName);
}
}
}

2
backend/tools/TestSuite/TestSuite.Shared/Fixtures/ContentQueryFixture.cs

@ -36,7 +36,7 @@ namespace TestSuite.Fixtures
{
Task.Run(async () =>
{
var contents = await Contents.GetAllAsync();
var contents = await Contents.GetAsync();
foreach (var content in contents.Items)
{

2
backend/tools/TestSuite/TestSuite.Shared/Model/TestEntity.cs

@ -13,7 +13,7 @@ using Squidex.ClientLibrary.Management;
namespace TestSuite.Model
{
public sealed class TestEntity : SquidexEntityBase<TestEntityData>
public sealed class TestEntity : Content<TestEntityData>
{
public static async Task<SchemaDetailsDto> CreateSchemaAsync(ISchemasClient schemas, string appName, string name)
{

2
backend/tools/TestSuite/TestSuite.Shared/Model/TestEntityWithReferences.cs

@ -14,7 +14,7 @@ using Squidex.ClientLibrary.Management;
namespace TestSuite.Model
{
public sealed class TestEntityWithReferences : SquidexEntityBase<TestEntityWithReferencesData>
public sealed class TestEntityWithReferences : Content<TestEntityWithReferencesData>
{
public static async Task<SchemaDetailsDto> CreateSchemaAsync(ISchemasClient schemas, string appName, string name)
{

2
backend/tools/TestSuite/TestSuite.Shared/TestSuite.Shared.csproj

@ -4,7 +4,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
<PackageReference Include="Squidex.ClientLibrary" Version="4.1.1" />
<PackageReference Include="Squidex.ClientLibrary" Version="4.2.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.4.1" />
</ItemGroup>

Loading…
Cancel
Save