mirror of https://github.com/Squidex/squidex.git
14 changed files with 190 additions and 21 deletions
@ -0,0 +1,67 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System.Threading.Tasks; |
|||
using LoadTest.Model; |
|||
using LoadTest.Utils; |
|||
using Squidex.ClientLibrary; |
|||
using Xunit; |
|||
|
|||
namespace LoadTest |
|||
{ |
|||
public class ManyItemsTests |
|||
{ |
|||
private readonly SquidexClient<TestEntity, TestEntityData> client; |
|||
|
|||
public ManyItemsTests() |
|||
{ |
|||
client = TestClient.BuildAsync("multiple").Result; |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_read_many_async() |
|||
{ |
|||
var contents = await client.GetAsync(); |
|||
|
|||
for (var i = contents.Total; i < 20000; i++) |
|||
{ |
|||
await client.CreateAsync(new TestEntityData |
|||
{ |
|||
String = RandomString.Create(1000) |
|||
}, publish: true); |
|||
} |
|||
|
|||
var found = await client.GetAll2Async(); |
|||
|
|||
Assert.Equal(20000, found.Items.Count); |
|||
} |
|||
} |
|||
|
|||
public static class SquidexClientExtensions |
|||
{ |
|||
public static async Task<SquidexEntities<TEntity, TData>> GetAll2Async<TEntity, TData>(this SquidexClient<TEntity, TData> client, int batchSize = 200) |
|||
where TEntity : SquidexEntityBase<TData> |
|||
where TData : class, new() |
|||
{ |
|||
var query = new ODataQuery { Top = batchSize, Skip = 0 }; |
|||
|
|||
var entities = new SquidexEntities<TEntity, TData>(); |
|||
do |
|||
{ |
|||
var getResult = await client.GetAsync(query); |
|||
|
|||
entities.Total = getResult.Total; |
|||
entities.Items.AddRange(getResult.Items); |
|||
|
|||
query.Skip += getResult.Items.Count; |
|||
} |
|||
while (query.Skip < entities.Total); |
|||
|
|||
return entities; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Security.Cryptography; |
|||
using System.Text; |
|||
|
|||
namespace LoadTest.Utils |
|||
{ |
|||
public static class RandomHash |
|||
{ |
|||
public static string New() |
|||
{ |
|||
return Guid.NewGuid() |
|||
.ToString().Sha256Base64() |
|||
.ToLowerInvariant() |
|||
.Replace("+", "x") |
|||
.Replace("=", "x") |
|||
.Replace("/", "x"); |
|||
} |
|||
|
|||
public static string Simple() |
|||
{ |
|||
return Guid.NewGuid().ToString().Replace("-", string.Empty); |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,28 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
|
|||
namespace LoadTest.Utils |
|||
{ |
|||
public static class RandomString |
|||
{ |
|||
private static readonly Random Random = new Random(); |
|||
|
|||
public static string Create(int length) |
|||
{ |
|||
var chars = new char[length]; |
|||
|
|||
for (var i = 0; i < length; i++) |
|||
{ |
|||
chars[i] = (char)Random.Next(48, 122); |
|||
} |
|||
|
|||
return new string(chars); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue