mirror of https://github.com/Squidex/squidex.git
Browse Source
* Fix resizer url. * Fix app routing. * Fix logic? * Fix schema resolver. * Cleanup. * Unused classes removed. * Fixpull/870/head
committed by
GitHub
35 changed files with 419 additions and 422 deletions
@ -0,0 +1,47 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using Squidex.ClientLibrary; |
|||
using TestSuite.Fixtures; |
|||
using TestSuite.Model; |
|||
|
|||
namespace TestSuite.ApiTests |
|||
{ |
|||
public sealed class ContentQueryFixture : TestSchemaFixtureBase |
|||
{ |
|||
public ContentQueryFixture() |
|||
: base("my-reads") |
|||
{ |
|||
} |
|||
|
|||
public override async Task InitializeAsync() |
|||
{ |
|||
await base.InitializeAsync(); |
|||
|
|||
await DisposeAsync(); |
|||
|
|||
for (var i = 10; i > 0; i--) |
|||
{ |
|||
var data = TestEntity.CreateTestEntry(i); |
|||
|
|||
await Contents.CreateAsync(data, ContentCreateOptions.AsPublish); |
|||
} |
|||
} |
|||
|
|||
public override async Task DisposeAsync() |
|||
{ |
|||
await base.DisposeAsync(); |
|||
|
|||
var contents = await Contents.GetAsync(); |
|||
|
|||
foreach (var content in contents.Items) |
|||
{ |
|||
await Contents.DeleteAsync(content); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using TestSuite.Fixtures; |
|||
|
|||
namespace TestSuite.ApiTests |
|||
{ |
|||
public sealed class ContentReferencesFixture : TestSchemaWithReferencesFixtureBase |
|||
{ |
|||
public ContentReferencesFixture() |
|||
: base("my-references") |
|||
{ |
|||
} |
|||
} |
|||
} |
|||
@ -1,33 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
namespace TestSuite |
|||
{ |
|||
public static class ClientManagerFactory |
|||
{ |
|||
private static Task<ClientManagerWrapper> manager; |
|||
|
|||
public static Task<ClientManagerWrapper> CreateAsync() |
|||
{ |
|||
if (manager == null) |
|||
{ |
|||
manager = CreateInternalAsync(); |
|||
} |
|||
|
|||
return manager; |
|||
} |
|||
|
|||
private static async Task<ClientManagerWrapper> CreateInternalAsync() |
|||
{ |
|||
var clientManager = new ClientManagerWrapper(); |
|||
|
|||
await clientManager.ConnectAsync(); |
|||
|
|||
return clientManager; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Concurrent; |
|||
|
|||
namespace TestSuite |
|||
{ |
|||
public static class Factories |
|||
{ |
|||
private static readonly ConcurrentDictionary<string, Task<object>> Instances = new ConcurrentDictionary<string, Task<object>>(); |
|||
|
|||
public static async Task<T> CreateAsync<T>(string key, Func<Task<T>> factory) |
|||
{ |
|||
return (T)await Instances.GetOrAdd(key, async (_, f) => await f(), factory); |
|||
} |
|||
} |
|||
} |
|||
@ -1,77 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Globalization; |
|||
using Newtonsoft.Json.Linq; |
|||
using Squidex.ClientLibrary; |
|||
using TestSuite.Model; |
|||
|
|||
namespace TestSuite.Fixtures |
|||
{ |
|||
public class ContentQueryFixture1to10 : ContentFixture |
|||
{ |
|||
public ContentQueryFixture1to10() |
|||
: this("my-reads") |
|||
{ |
|||
} |
|||
|
|||
protected ContentQueryFixture1to10(string schemaName = "my-schema") |
|||
: base(schemaName) |
|||
{ |
|||
Task.Run(async () => |
|||
{ |
|||
#pragma warning disable MA0056 // Do not call overridable members in constructor
|
|||
Dispose(); |
|||
#pragma warning restore MA0056 // Do not call overridable members in constructor
|
|||
|
|||
for (var i = 10; i > 0; i--) |
|||
{ |
|||
var text = i.ToString(CultureInfo.InvariantCulture); |
|||
|
|||
var data = new TestEntityData |
|||
{ |
|||
String = text, |
|||
Json = JObject.FromObject(new |
|||
{ |
|||
nested1 = new |
|||
{ |
|||
nested2 = i |
|||
} |
|||
}), |
|||
Number = i, |
|||
}; |
|||
|
|||
if (i % 2 == 0) |
|||
{ |
|||
data.Geo = new { type = "Point", coordinates = new[] { i, i } }; |
|||
} |
|||
else |
|||
{ |
|||
data.Geo = new { longitude = i, latitude = i }; |
|||
} |
|||
|
|||
await Contents.CreateAsync(data, ContentCreateOptions.AsPublish); |
|||
} |
|||
}).Wait(); |
|||
} |
|||
|
|||
public override void Dispose() |
|||
{ |
|||
Task.Run(async () => |
|||
{ |
|||
var contents = await Contents.GetAsync(); |
|||
|
|||
foreach (var content in contents.Items) |
|||
{ |
|||
await Contents.DeleteAsync(content); |
|||
} |
|||
}).Wait(); |
|||
|
|||
GC.SuppressFinalize(this); |
|||
} |
|||
} |
|||
} |
|||
@ -1,3 +0,0 @@ |
|||
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
|||
<Lazy /> |
|||
</Weavers> |
|||
@ -1,47 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
|
|||
namespace TestSuite.Utils |
|||
{ |
|||
public static class RandomHash |
|||
{ |
|||
public static string New() |
|||
{ |
|||
return Guid.NewGuid() |
|||
.ToString().Sha256Base64() |
|||
.ToLowerInvariant() |
|||
.Replace("+", "x", StringComparison.Ordinal) |
|||
.Replace("=", "x", StringComparison.Ordinal) |
|||
.Replace("/", "x", StringComparison.Ordinal); |
|||
} |
|||
|
|||
public static string Simple() |
|||
{ |
|||
return Guid.NewGuid().ToString().Replace("-", string.Empty, StringComparison.Ordinal); |
|||
} |
|||
|
|||
public static string Sha256Base64(this string value) |
|||
{ |
|||
return Sha256Base64(Encoding.UTF8.GetBytes(value)); |
|||
} |
|||
|
|||
public static string Sha256Base64(this byte[] bytes) |
|||
{ |
|||
using (var sha = SHA256.Create()) |
|||
{ |
|||
var bytesHash = sha.ComputeHash(bytes); |
|||
|
|||
var result = Convert.ToBase64String(bytesHash); |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -1,68 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Collections.Concurrent; |
|||
using System.Diagnostics; |
|||
using Xunit; |
|||
|
|||
namespace TestSuite.Utils |
|||
{ |
|||
public static class Run |
|||
{ |
|||
public static async Task Parallel(int numUsers, int numIterationsPerUser, Func<Task> action, int expectedAvg = 100) |
|||
{ |
|||
var elapsedMs = new ConcurrentBag<long>(); |
|||
|
|||
var errors = 0; |
|||
|
|||
async Task RunAsync() |
|||
{ |
|||
for (var i = 0; i < numIterationsPerUser; i++) |
|||
{ |
|||
try |
|||
{ |
|||
var watch = Stopwatch.StartNew(); |
|||
|
|||
await action(); |
|||
|
|||
watch.Stop(); |
|||
|
|||
elapsedMs.Add(watch.ElapsedMilliseconds); |
|||
} |
|||
catch |
|||
{ |
|||
Interlocked.Increment(ref errors); |
|||
} |
|||
} |
|||
} |
|||
|
|||
var tasks = new List<Task>(); |
|||
|
|||
for (var i = 0; i < numUsers; i++) |
|||
{ |
|||
tasks.Add(Task.Run(RunAsync)); |
|||
} |
|||
|
|||
await Task.WhenAll(tasks); |
|||
|
|||
var count = elapsedMs.Count; |
|||
|
|||
var max = elapsedMs.Max(); |
|||
var min = elapsedMs.Min(); |
|||
|
|||
var avg = elapsedMs.Average(); |
|||
|
|||
Assert.Equal(0, errors); |
|||
Assert.Equal(count, numUsers * numIterationsPerUser); |
|||
|
|||
Assert.InRange(max, 0, expectedAvg * 10); |
|||
Assert.InRange(min, 0, expectedAvg); |
|||
|
|||
Assert.InRange(avg, 0, expectedAvg); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue