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.
52 lines
1.7 KiB
52 lines
1.7 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using FakeItEasy;
|
|
using Xunit;
|
|
|
|
namespace Squidex.Infrastructure.Log.Store
|
|
{
|
|
public class BackgroundRequestLogStoreTests
|
|
{
|
|
private readonly IRequestLogRepository requestLogRepository = A.Fake<IRequestLogRepository>();
|
|
private readonly BackgroundRequestLogStore sut;
|
|
|
|
public BackgroundRequestLogStoreTests()
|
|
{
|
|
sut = new BackgroundRequestLogStore(requestLogRepository, A.Fake<ISemanticLog>());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Should_log_in_batches()
|
|
{
|
|
for (var i = 0; i < 2500; i++)
|
|
{
|
|
await sut.LogAsync(new Request { Key = i.ToString() });
|
|
}
|
|
|
|
sut.Next();
|
|
sut.Dispose();
|
|
|
|
A.CallTo(() => requestLogRepository.InsertManyAsync(Batch("0", "999")))
|
|
.MustHaveHappened();
|
|
|
|
A.CallTo(() => requestLogRepository.InsertManyAsync(Batch("1000", "1999")))
|
|
.MustHaveHappened();
|
|
|
|
A.CallTo(() => requestLogRepository.InsertManyAsync(Batch("2000", "2499")))
|
|
.MustHaveHappened();
|
|
}
|
|
|
|
private static IEnumerable<Request> Batch(string from, string to)
|
|
{
|
|
return A<IEnumerable<Request>>.That.Matches(x => x.First().Key == from && x.Last().Key == to);
|
|
}
|
|
}
|
|
}
|
|
|