public void TestMemoryCacheClear() { // Prepare var cache = new MemoryCache(); cache.Add(new CacheItem("Key", new object())); // Act cache.Clear(); // Assert Assert.IsFalse(cache.Any()); }
public Usuario GetUsuario() { var usuarioAD = ((Thread.CurrentPrincipal is WindowsPrincipal || Thread.CurrentPrincipal is GenericPrincipal) && Thread.CurrentPrincipal.Identity.IsAuthenticated && Thread.CurrentPrincipal.Identity.Name.Contains(@"\")) ? Thread.CurrentPrincipal.Identity.Name.ToUpperInvariant() : WindowsIdentity.GetCurrent().Name.ToUpperInvariant(); if (!_Usuarios.Any(x => x.Key == $"{usuarioAD}")) { var user = _usuarioBiz.GetByIdUsuarioAplicacion(usuarioAD, "ACC"); _Usuarios.Add($"{usuarioAD}", user, new System.DateTimeOffset(DateTime.Now.AddMinutes(10))); return(user); } else { return((Usuario)_Usuarios.Single(x => x.Key == $"{usuarioAD}").Value); } }
/// <summary> /// Starts the health check and returns <see cref="HealthCheckResult"/> /// </summary> public HealthCheckResult StartHealthCheck() { return(_cache.Any() ? HealthCheckResult.Healthy($"Cache has {_cache.Count()} items.") : HealthCheckResult.Healthy("Cache is empty.")); }
public bool IsExist(string key) { //format istenildiği gibi olmazsa exception fırlatır! Contract.Assert(!string.IsNullOrEmpty(key)); return(_cache.Any(x => x.Key == key)); }
private bool HasPendingOrders() { lock (_pendingEntryOrdersLocker) return(PendingEntryOrders.Any()); }
public bool IsExist(string key) { System.Diagnostics.Contracts.Contract.Assert(!string.IsNullOrEmpty(key)); //key değerinin null veya boş olmadığından emin ol, yoksa exception fırlat return(_cache.Any(i => i.Key == key)); }
public bool IsExist(string key) { return(_cache.Any(_ => _.Key == key)); }
public static bool ExistUserId(string key, string userId) => _memoryCache.Any(x => x.Value.ToString() == userId);
public void PlayerProfileGetsCached() { const string callType = "GetPlayerProfileAsync"; Assert.AreEqual(0, _dataRouterManager.GetCallCount(callType), "Should be called exactly 0 times."); Assert.IsTrue(!_memoryCache.Any()); var player = _profileCache.GetPlayerProfileAsync(CreatePlayerUrn(1), TestData.Cultures).Result; Assert.IsNotNull(player); Assert.AreEqual(1, _memoryCache.Count()); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly {TestData.Cultures.Count} times."); //if we call again, should not fetch again player = _profileCache.GetPlayerProfileAsync(CreatePlayerUrn(1), TestData.Cultures).Result; Assert.IsNotNull(player); Assert.AreEqual(1, _memoryCache.Count()); Assert.AreEqual(TestData.Cultures.Count, _dataRouterManager.GetCallCount(callType), $"{callType} should be called exactly {TestData.Cultures.Count} times."); }