public void Default_keyed_by_form_header_query() { //Arrange var keyGen = new DefaultCacheKeyGenerator(new string[] { nameof(FORM), nameof(QUERY), nameof(ACCEPT) }); var request = new FakeRequest( method: METHOD, path: PATH, headers: acceptHeader, body: null, protocol: PROTOCOL, query: QUERY); request.Form[FORM] = FORM_VALUE; //Act string key = keyGen.Get(request); //Assert Assert.Contains(ACCEPT, key); Assert.Contains(ACCEPT_VALUE, key); Assert.Contains(QUERY, key); Assert.Contains(FORM, key); Assert.Contains(FORM_VALUE, key); Assert.Contains(PATH, key); }
public void Setup() { calculateMethod = typeof(CachingTarget).GetMethod("Calculate"); serializeXmlMethod = typeof(CachingTarget).GetMethod("SerializeXml"); sometimesReturnsNullMethod = typeof(CachingTarget).GetMethod("SometimesReturnsNull"); keyGenerator = new DefaultCacheKeyGenerator(); }
public void Default_keyed_by_header_and_query_and_disabled_query() { //Arrange string disabled = string.Concat("&", Defaults.RemoveCache.Key); string query = string.Concat(QUERY, disabled); var keyGen = new DefaultCacheKeyGenerator(new string[] { nameof(QUERY), nameof(ACCEPT) }); var request = new FakeRequest( method: METHOD, path: PATH, headers: acceptHeader, body: null, protocol: PROTOCOL, query: query); //Act string key = keyGen.Get(request); //Assert Assert.Contains(ACCEPT, key); Assert.Contains(ACCEPT_VALUE, key); Assert.Contains(QUERY, key); Assert.Contains(PATH, key); Assert.DoesNotContain(disabled, key); }
public void APartialCacheKeyIsGeneratedFromTheTypeSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof(DummyClass); var key = generator.GeneratePartialCacheKey(type); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass")); }
public void APartialCacheKeyIsGeneratedFromTheTypeSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof(DummyClass); var key = generator.GeneratePartialCacheKey(type); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass")); }
public void APartialCacheKeyIsGeneratedFromTheMethodSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof(DummyClass); var method = type.GetMethod("CachedMethodWithSettings"); var key = generator.GeneratePartialCacheKey(method); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethodWithSettings")); }
public void APartialCacheKeyIsGeneratedFromTheMethodSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof(DummyClass); var method = type.GetMethod("CachedMethodWithSettings"); var key = generator.GeneratePartialCacheKey(method); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethodWithSettings")); }
public void Default_keyed_null() { //Arrange var keyGen = new DefaultCacheKeyGenerator(); //Act string key = keyGen.Get(null); //Assert Assert.Empty(key); }
public void ACacheKeyIsGeneratedFromTheMethodSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof (DummyClass); var method = type.GetMethod("CachedMethodWithSettings"); var key = generator.GenerateCacheKey(method, new object[]{"test", 1}); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethodWithSettings(test, 1)")); var method2 = type.GetMethod("CachedMethod"); var key2 = generator.GenerateCacheKey(method2); Assert.That(key2, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethod()")); }
public void DefaultCacheKeyGenerator_GetCacheKey_Returns_CompositeKeyWithDnsSafeHost() { var url = new Uri("http://myurl"); var mockRequest = new Mock <HttpRequestBase>(); mockRequest.SetupGet(p => p.ServerVariables).Returns(new NameValueCollection()); mockRequest.SetupGet(p => p.Url).Returns(url); var mockContext = new Mock <HttpContextBase>(); mockContext.SetupGet(p => p.Request).Returns(mockRequest.Object); var provider = new DefaultCacheKeyGenerator(); var generatedKey = provider.GetCacheKey(mockContext.Object, "TEST"); Assert.That(generatedKey, Is.EqualTo("myurl:TEST")); }
public void ACacheKeyIsGeneratedFromTheMethodSignature() { var generator = new DefaultCacheKeyGenerator(); var type = typeof(DummyClass); var method = type.GetMethod("CachedMethodWithSettings"); var key = generator.GenerateCacheKey(method, new object[] { "test", 1 }); Assert.That(key, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethodWithSettings(test, 1)")); var method2 = type.GetMethod("CachedMethod"); var key2 = generator.GenerateCacheKey(method2); Assert.That(key2, Is.EqualTo("AspectCache.Tests.DummyClass.CachedMethod()")); }
public void DefaultCacheKeyGenerator_GetCacheKey_Returns_CompositeKeyWithHttpHost() { var nvc = new NameValueCollection() { { "HTTP_HOST", "MYSITE" } }; var mockRequest = new Mock <HttpRequestBase>(); mockRequest.SetupGet(p => p.ServerVariables).Returns(nvc); var mockContext = new Mock <HttpContextBase>(); mockContext.SetupGet(p => p.Request).Returns(mockRequest.Object); var provider = new DefaultCacheKeyGenerator(); var generatedKey = provider.GetCacheKey(mockContext.Object, "TEST"); Assert.That(generatedKey, Is.EqualTo("MYSITE:TEST")); }
public void Default_keyed_by_url_only_with_removal_key() { //Arrange var keyGen = new DefaultCacheKeyGenerator(); var request = new FakeRequest( method: METHOD, path: PATH, headers: acceptHeader, body: null, protocol: PROTOCOL, query: string.Concat(QUERY, "?RapidCacheRemove=true")); //Act string key = keyGen.Get(request); //Assert Assert.DoesNotContain(ACCEPT, key); Assert.DoesNotContain(QUERY, key); Assert.Contains(PATH, key); }
public void Default_keyed_by_query() { //Arrange var keyGen = new DefaultCacheKeyGenerator(new string[] { nameof(QUERY) }); var request = new FakeRequest( method: METHOD, path: PATH, headers: acceptHeader, body: null, protocol: PROTOCOL, query: QUERY); //Act string key = keyGen.Get(request); //Assert Assert.DoesNotContain(ACCEPT, key); Assert.Contains(QUERY, key); Assert.Contains(PATH, key); }
/// <summary> /// Creates a <see cref="T:Cedar.Framwork.Caching.Interception.CachingCallHandler" /> that uses the given expiration /// time. /// </summary> /// <param name="expirationTime"> /// Length of time the cached data goes unused before it is eligible for /// reclamation. /// </param> public CachingCallHandler(TimeSpan expirationTime) { KeyGenerator = new DefaultCacheKeyGenerator(); ExpirationTime = expirationTime; }
/// <summary> /// Creates a <see cref="T:Cedar.Framwork.Caching.Interception.CachingCallHandler" /> that uses the given expiration /// time. /// </summary> /// <param name="expirationTime"> /// Length of time the cached data goes unused before it is eligible for /// reclamation. /// </param> /// <param name="order">Order in which handler will be executed.</param> public CachingCallHandler(TimeSpan expirationTime, int order) { KeyGenerator = new DefaultCacheKeyGenerator(); ExpirationTime = expirationTime; Order = order; }
public FrameworkConfiguation() { CacheKeyGenerator = new DefaultCacheKeyGenerator(); }