public void Should_build_key_from_methodInfo_and_context() { // Arrange var invocation = Substitute.For<_IInvocation>(); invocation.Arguments.Returns(new object[] {new Guid ("5e31d440-c9f8-4110-b94d-fdf8affdc675") }); invocation.GetArgumentValue(Arg.Any<int>()).Returns(ct => invocation.Arguments[ct.Arg<int>()]); invocation.Method.Returns(typeof(IUserService).GetMethod(nameof(IUserService.GetById), BindingFlags.Instance | BindingFlags.Public)); var provider = new DefaultCacheKeyProvider(); var invocationContext = new Dictionary<string, object>(); invocationContext[Global.__flatwhite_outputcache_attribute] = new OutputCacheAttribute { VaryByCustom = "query.source, headers.UserAgent, headers.CacheControl.Public, headers.CacheControl.NonExistProperty", VaryByParam = "userId" }; invocationContext["query"] = new Dictionary<string, object> { { "source","a"}, { "source2","b"}, }; var r = new HttpRequestMessage(); r.Headers.CacheControl = new CacheControlHeaderValue { Public = true }; r.Headers.Add("User-Agent", "Flatwhite.UnitTest"); invocationContext["headers"] = r.Headers; // Action var key = provider.GetCacheKey(invocation, invocationContext); // Assert Assert.AreEqual("Flatwhite::Flatwhite.Tests.IUserService.GetById(Guid:5e31d440-c9f8-4110-b94d-fdf8affdc675) :: query.source:a, headers.UserAgent:Flatwhite.UnitTest, headers.CacheControl.Public:True, , ", key); }
static Global() { Cache = new MethodInfoCache(); ContextProvider = new EmptyContextProvider(); CacheStrategyProvider = new DefaultCacheStrategyProvider(); AttributeProvider = new DefaulAttributeProvider(); HashCodeGeneratorProvider = new DefaultHashCodeGeneratorProvider(); CacheKeyProvider = new DefaultCacheKeyProvider(HashCodeGeneratorProvider); CacheStoreProvider = new DefaultCacheStoreProvider(); ServiceActivator = new ServiceActivator(); Logger = new NullLogger(); }
internal static void Init() { Cache = new MethodInfoCache(); ContextProvider = new EmptyContextProvider(); CacheStrategyProvider = new DefaultCacheStrategyProvider(); AttributeProvider = new DefaulAttributeProvider(); HashCodeGeneratorProvider = new DefaultHashCodeGeneratorProvider(); CacheKeyProvider = new DefaultCacheKeyProvider(HashCodeGeneratorProvider); CacheStoreProvider = new DefaultCacheStoreProvider(); ServiceActivator = new DefaultServiceActivator(); Logger = new NullLogger(); BackgroundTaskManager = new DefaultBackgroundTaskManager(); var configFolder = AppDomain.CurrentDomain.SetupInformation.ApplicationBase; CacheProfileProvider = new YamlCacheProfileProvider(Path.Combine(configFolder ?? "", "cacheProfile.yaml")); }