Esempio n. 1
0
            public void Get_WithLocalCachedItem_Null_Distributed_NotNull()
            {
                var memoryCache = new MemoryCache(new Microsoft.Extensions.Options.OptionsWrapper <MemoryCacheOptions>(
                                                      new MemoryCacheOptions()));

                memoryCache.Set("UserByName_admin$Generation$", (ulong)641427502);
                memoryCache.Set("UserGenerationKey", (ulong)641427502);
                memoryCache.Set <UserDefinition>("UserByName_admin", null);
                var distributedCache = new MemoryDistributedCache(
                    new Microsoft.Extensions.Options.OptionsWrapper <MemoryDistributedCacheOptions>(
                        new MemoryDistributedCacheOptions()));

                distributedCache.Set("UserByName_admin$Generation$", BitConverter.GetBytes((ulong)641427502));
                distributedCache.SetAutoJson("UserByName_admin", new UserDefinition {
                    Username = "******", UserId = 1
                });
                distributedCache.Set("UserGenerationKey", BitConverter.GetBytes((ulong)641427502));
                var cache     = new TwoLevelCache(memoryCache, distributedCache);
                var loadCount = 0;
                var user      = GetUserByName(cache, "admin", ref loadCount);

                Assert.Equal("admin", user?.Username);
                Assert.Equal(0, loadCount);
            }