forked from mkrypka/dotnet-caching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathResourceFactory.cs
81 lines (67 loc) · 2.38 KB
/
ResourceFactory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using StackExchange.Redis;
using Vtex.Caching.Backends.InProcess;
using Vtex.Caching.Backends.Redis;
using Vtex.Caching.Interfaces;
using Vtex.RabbitMQ.Messaging;
using Vtex.RabbitMQ.Messaging.Interfaces;
namespace Vtex.Caching.Tests
{
public static class ResourceFactory
{
public static IRedisAdapter GetRedisAdapter()
{
var multiplexer = ConnectionMultiplexer.Connect("localhost:6379");
return new RedisAdapter(multiplexer);
}
public static RedisCache GetRedisCache()
{
return new RedisCache(GetRedisAdapter());
}
public static InProcessCache GetInProcessCache()
{
return new InProcessCache("IntegrationTests");
}
public static Stack<IRawCache> GetCacheStack()
{
return new Stack<IRawCache>(new List<IRawCache>{GetRedisCache(), GetInProcessCache()});
}
public static Stack<IRawCache> GetCacheStack(params IRawCache[] cacheBackends)
{
return new Stack<IRawCache>(cacheBackends);
}
public static HybridCache GetHybridCache()
{
return new HybridCache(GetCacheStack(), GetQueueClient());
}
public static HybridCache GetHybridCache(params IRawCache[] cacheBackends)
{
return new HybridCache(GetCacheStack(cacheBackends), GetQueueClient());
}
public static IQueueClient GetQueueClient()
{
return new RabbitMQClient("guest:guest@localhost:5672/testing");
}
private static string GenerateString(int length)
{
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
var random = new Random((int)DateTime.Now.Ticks);
return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}
public static string GenerateKey()
{
return String.Format("testKey:{0}", GenerateString(8));
}
public static Dictionary<string, string> GenerateDictionary(int size)
{
var dictionary = new Dictionary<string, string>();
for (var i = 0; i < size; i++)
{
dictionary.Add(GenerateKey() + i, GenerateString(10));
}
return dictionary;
}
}
}