mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
93 lines
2.6 KiB
93 lines
2.6 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using TestSuite.Fixtures;
|
|
using TestSuite.Model;
|
|
|
|
#pragma warning disable SA1300 // Element should begin with upper-case letter
|
|
|
|
namespace TestSuite.ApiTests;
|
|
|
|
[Trait("Category", "NotAutomated")]
|
|
public class CDNTests(ClientCloudFixture fixture) : IClassFixture<ClientCloudFixture>
|
|
{
|
|
public ClientCloudFixture _ { get; } = fixture;
|
|
|
|
[Fact]
|
|
public void Should_provide_asset_url_from_cdn()
|
|
{
|
|
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
|
|
|
|
var url = _.CDNClient.GenerateImageUrl(id);
|
|
|
|
Assert.StartsWith("https://assets.squidex.io/", url, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_download_asset_url_from_cdn()
|
|
{
|
|
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
|
|
|
|
var url = _.CDNClient.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 = _.CloudClient.GenerateImageUrl(id);
|
|
|
|
Assert.StartsWith("https://cloud.squidex.io/", url, StringComparison.Ordinal);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_download_asset_url_from_cloud_when_cdn_not_configured()
|
|
{
|
|
var id = "ef4286f9-8b1d-4dda-bd52-c5bd191c47bb";
|
|
|
|
var url = _.CloudClient.GenerateImageUrl(id);
|
|
|
|
await DownloadAsync(url!);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_get_blog_items_from_cdn()
|
|
{
|
|
var client = _.CDNClient.Contents<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 = _.CloudClient.Contents<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);
|
|
}
|
|
}
|
|
}
|
|
|