forked from ddrilling/AsbCloudServer
62 lines
2.0 KiB
C#
62 lines
2.0 KiB
C#
using AsbCloudApp.Data;
|
|
using AsbCloudApp.Services;
|
|
using AsbCloudDb.Model;
|
|
using AsbCloudInfrastructure.EfCache;
|
|
using DocumentFormat.OpenXml.Spreadsheet;
|
|
using Mapster;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
|
|
namespace AsbCloudWebApi.Tests.CacheTests
|
|
{
|
|
public class CacheTest
|
|
{
|
|
private readonly string userCacheTag = "Users";
|
|
private static readonly TimeSpan cacheObsolence = TimeSpan.FromMinutes(15);
|
|
public IEnumerable<User> UsersCache = new List<User> {
|
|
new User { Id = 1, Name = "test1", Email = "test1@mail.com" },
|
|
new User { Id = 2, Name = "test2", Email = "test2@mail.com" },
|
|
new User { Id = 3, Name = "test3", Email = "test3@mail.com" },
|
|
new User { Id = 4, Name = "test4", Email = "test4@mail.com" },
|
|
new User { Id = 5, Name = "test5", Email = "test5@mail.com" },
|
|
new User { Id = 6, Name = "test6", Email = "test6@mail.com" },
|
|
new User { Id = 7, Name = "test7", Email = "test7@mail.com" }
|
|
};
|
|
|
|
[Fact]
|
|
public void Send_n_requests_cache_user()
|
|
{
|
|
const int iterations = 1230;
|
|
var cache = UsersCache.AsQueryable();
|
|
var cacheCount = UsersCache.Count();
|
|
var fail = false;
|
|
|
|
var tasks = new int[iterations].Select(_=> new Task(() =>
|
|
{
|
|
var data = cache.FromCache(userCacheTag, cacheObsolence, Convert).ToArray();
|
|
if (data.Count() != cacheCount)
|
|
fail = true;
|
|
}))
|
|
.ToArray();
|
|
|
|
foreach(var task in tasks)
|
|
task.Start();
|
|
|
|
Task.WaitAll(tasks);
|
|
Assert.False(fail);
|
|
}
|
|
|
|
private UserExtendedDto Convert(User entity)
|
|
{
|
|
var dto = entity.Adapt<UserExtendedDto>();
|
|
return dto;
|
|
}
|
|
}
|
|
}
|