public void ContainsKey() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.True(service.ContainsKey(_appId)); }
public void Count() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.Single(service); }
public void Keys() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.Single(service.Keys); Assert.Equal(_appId, service.Keys.Single()); }
public void Values() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.Single(service.Values); Assert.NotNull(service.Values.Single()); Assert.Equal(_secretKey, service.Values.Single()); }
public void GenerateApiKeyTest() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); string apiKey = service.GenerateApiKey(); Assert.NotNull(apiKey); Assert.Equal(32, Convert.FromBase64String(apiKey).Length); }
public void Add() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); service.Add(_appId2, _secretKey2); Assert.Equal(2, service.Count); Assert.Equal(_secretKey2, service[_appId2]); }
public void BasicApiKeyServiceUsage() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.NotEmpty(service); Assert.Single(service); Assert.Equal(_appId, service.Single().Key); Assert.Equal(_secretKey, service.Single().Value); }
public void Contains() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); KeyValuePair <string, string> item = new KeyValuePair <string, string>(_appId2, _secretKey2); Assert.DoesNotContain(item, service); service.Add(item); Assert.Contains(item, service); }
public void Indexing() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); service[_appId2] = _secretKey2; Assert.Equal(2, service.Count); string retrieved = service[_appId2]; Assert.Equal(_secretKey2, retrieved); }
public void Clear() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); Assert.Single(service); Assert.Equal(_secretKey, service[_appId]); service.Clear(); Assert.Empty(service); }
public void AddKvp() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); KeyValuePair <string, string> item = new KeyValuePair <string, string>(_appId2, _secretKey2); service.Add(item); string result = service[_appId2]; Assert.Equal(_secretKey2, result); }
private static T GetService <T>(Func <ILoggingService, IApiKeyService, ICachingService, T> constructor, MemoryCachingService cachingService = null) where T : AuthenticationService { MemoryCachingService memoryCachingService = cachingService ?? new MemoryCachingService(TimeSpan.FromMinutes(5)); Json serializationService = new Json(); CacheLoggingService loggingService = new CacheLoggingService(memoryCachingService, serializationService); BasicApiKeyService apiKeyService = new BasicApiKeyService(GetBackingKeys()); T service = constructor(loggingService, apiKeyService, memoryCachingService); return(service); }
public void TryGetValue() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); string result; Assert.False(service.TryGetValue(_appId2, out result)); service.Add(_appId2, _secretKey2); bool success = service.TryGetValue(_appId2, out result); Assert.True(success); Assert.Equal(_secretKey2, result); }
public void CopyTo() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); string retrieved = service[_appId]; KeyValuePair <string, string>[] cache = new KeyValuePair <string, string> [1]; service.CopyTo(cache, 0); Assert.NotNull(cache); Assert.NotEmpty(cache); Assert.Single(cache); Assert.Equal(retrieved, cache[0].Value); Assert.Equal(_appId, cache[0].Key); }
public void Remove() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); string retrievedSecret = service[_appId]; service.Remove(_appId); string retrievedSecret2 = null; Assert.Throws <KeyNotFoundException>(() => retrievedSecret2 = service[_appId]); Assert.Empty(service); Assert.NotNull(retrievedSecret); Assert.Null(retrievedSecret2); }
public void TestEnumerators() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); IEnumerator <KeyValuePair <string, string> > typedEnumerator = service.GetEnumerator(); IEnumerator enumerator = ((IEnumerable)service).GetEnumerator(); typedEnumerator.MoveNext(); enumerator.MoveNext(); Assert.Equal(_secretKey, (typedEnumerator.Current).Value); Assert.Equal(_secretKey, ((KeyValuePair <string, string>)enumerator.Current).Value); }
public void RemoveKvp() { Dictionary <string, string> backingKeys = GetBackingKeys(); BasicApiKeyService service = new BasicApiKeyService(backingKeys); service.Clear(); KeyValuePair <string, string> item = new KeyValuePair <string, string>(_appId2, _secretKey2); bool succeded = service.Remove(item); Assert.False(succeded); service.Add(item); string result = service[_appId2]; Assert.Equal(_secretKey2, result); succeded = service.Remove(item); Assert.True(succeded); Assert.Empty(service); }