public void Setup() { challenge = new Class { ApiKey = new Guid(), VatId = "IT01180680397", SubscriptionId = "sub_1234", SubscriptionIsActive = true }; var challengeJson = JsonConvert.SerializeObject(challenge); db = new Mock <IDatabase>(); redis = new Mock <IConnectionMultiplexer>(); redis .Setup(_ => _.IsConnected).Returns(true); redis .Setup(_ => _.GetDatabase(It.IsAny <int>(), It.IsAny <object>())) .Returns(db.Object); box = new RedisBox() { Multiplexer = redis.Object }; box.MetaFields.Id = "ApiKey"; }
private static void Main(string[] args) { // unless otherwise stated, all values presented are the default if not specified var memory = MemoryBox.GetInstance( new MemoryConfiguration { DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), ExpirationScanFrequency = new TimeSpan(0, 1, 0, 0), PoolSize = 1 // hardcoded to 1 on creation of connectionpool }); // redis connection assumes SSL is enabled; if not you must adjust port and UseSSL var redis = RedisBox.GetInstance( new RedisConfiguration { DatabaseID = 0, DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), Host = "<host>", // defaults to 127.0.0.1 Password = "******", // only required if using ssl, defaults to "" PoolSize = 5, Port = 6379, // defaults to 6380 UseSSL = false // defaults to true }); // for documentDB you must replace the string values with whatever you have setup // the backing DB of your cosmosDB MUST be SQL and partitioned/sharded based on /_partitionKey var documentDB = DocumentDBBox.GetInstance( new DocumentDBConfiguration { Collection = "<collection>", ConnectionPolicy = new ConnectionPolicy(), // defaults to nothing configured Database = "<database>", DefaultTimeToLive = new TimeSpan(1, 0, 0, 0), DefaultTimeToRefresh = new TimeSpan(0, 0, 5, 0), EndpointURI = new Uri("https://<account>.documents.azure.com:443"), PartitionKey = "cache", // defaults to cache, but you can specify what you want PoolSize = 5, PrimaryKey = "<auth_key>" }); // create a new tenancy object` var tenancy = new Tenancy( new ILitterBox[] { memory, redis, documentDB }); // subscribe to internal errors tenancy.ExceptionEvent += TenancyOnExceptionEvent; // set an item (will backfill all three caches) var x = tenancy.SetItem( "foo", new LitterBoxItem <dynamic> { Value = new { Args = "boo" } }).GetAwaiter().GetResult(); // get item from cache, checks in order of array initialization. in this case memory -> redis -> documentDB var y = tenancy.GetItem <dynamic>("foo").GetAwaiter().GetResult(); Console.ReadKey(); }