// ========================================================================== // 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(); private readonly BackgroundRequestLogStore sut; public BackgroundRequestLogStoreTests() { sut = new BackgroundRequestLogStore(requestLogRepository, A.Fake()); } [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 Batch(string from, string to) { return A>.That.Matches(x => x.First().Key == from && x.Last().Key == to); } } }