public void GetOrAdd(string cacheKey, string cacheValue, string fakeValue) { #region Arrange // Set up some variables var cache = new NoCache(); #endregion #region Act // 1 Try to save cacheValue1 under cacheKey. var returnedCachValue1 = ((ICache)cache).GetOrAdd(cacheKey, () => { return cacheValue; }); // 2 Try to save cacheValue2 under cacheKey. var returnedCachValue2 = ((ICache)cache).GetOrAdd(cacheKey, () => { return fakeValue; }); #endregion #region Assert // What we get back should equal what we put in, since there is no cache. Assert.AreEqual(cacheValue, returnedCachValue1); Assert.AreEqual(fakeValue, returnedCachValue2); #endregion }
public async Task TestNoCacheObjectAsync() { var cache = new NoCache(); int hits = 0; Func <Task <ScopedValue <string> > > getter = async() => { await Task.Delay(10); hits++; return(new ScopedValue <string>(hits.ToString(), DateTimeOffset.UtcNow)); }; GetScopedResult <string> result; result = await cache.GetScopedAsync("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual("1", result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); result = await cache.GetScopedAsync("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual("2", result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); }
public override int GetHashCode() { int hc = 29; unchecked { hc = hc * 29 + HashCodeCalculator.Calculate(extensions); hc = hc * 29 + MaxAge.GetHashCode(); hc = hc * 29 + MaxStale.GetHashCode(); hc = hc * 29 + MaxStaleLimit.GetHashCode(); hc = hc * 29 + MinFresh.GetHashCode(); hc = hc * 29 + MustRevalidate.GetHashCode(); hc = hc * 29 + HashCodeCalculator.Calculate(no_cache_headers); hc = hc * 29 + NoCache.GetHashCode(); hc = hc * 29 + NoStore.GetHashCode(); hc = hc * 29 + NoTransform.GetHashCode(); hc = hc * 29 + OnlyIfCached.GetHashCode(); hc = hc * 29 + Private.GetHashCode(); hc = hc * 29 + HashCodeCalculator.Calculate(private_headers); hc = hc * 29 + ProxyRevalidate.GetHashCode(); hc = hc * 29 + Public.GetHashCode(); hc = hc * 29 + SharedMaxAge.GetHashCode(); } return(hc); }
public async Task TestNoCacheObjectAsync() { var cache = new NoCache(); int hits = 0; Func <Task <string> > getter = async() => { await Task.Delay(10); hits++; return(hits.ToString()); }; string result; result = await cache.GetAsync("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual("1", result); result = await cache.GetAsync("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual("2", result); }
public AdvancedConfiguration() { Serializers = new List <IContentSerializer>(); ModifiedSinceCache = new NoCache(); ContentNegotiation = true; WebrequestModifier = (req) => { }; RequestTimeout = new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 10); }
/// <summary> /// Load Columns type in cache; /// </summary> /// <param name="dbase"></param> /// <param name="table"></param> private static async System.Threading.Tasks.Task LoadAsync(string dbase, string table) { if (KCore.Stored.Cache.ColumnsStruct == null || !KCore.Stored.Cache.ColumnsStruct.Where(t => t.DBase.Equals(dbase, StringComparison.InvariantCultureIgnoreCase) && t.Table.Equals(table, StringComparison.InvariantCultureIgnoreCase)).Any()) { var ColList = NoCache.Structure(dbase, table); KCore.Stored.Cache.LoadColumnsStruct(new List <ColumnStruct>(ColList)); } }
public void ShouldThrowIfNoneAvailable() { // Arrange var name = GetRandomString(10, 20); var cache = new NoCache(); var executor = new CommandExecutor( new QueryExecutor(cache), cache ); // Act Expect(() => executor.Execute(new CreatePeople(name))) .To.Throw <TransactionScopeRequired>(); // Assert }
private TemplateEngine(string path, ITemplateContext ctx, ICache <string, TemplateAST> cache, ExpressionLanguageEngineConfig cfg) { _ctx = ctx ?? new TemplateContext(); _cache = cache ?? NoCache.GetInstance <string, TemplateAST>(); _cfg = cfg ?? ExpressionLanguageEngineConfig.Default; if (string.IsNullOrEmpty(path)) { _path = Runtime.StartupDirectory; } else { _path = System.IO.Path.GetFullPath(path); } }
public void TestNoCacheObject() { var cache = new NoCache(); int hits = 0; Func <string> getter = () => { hits++; return(hits.ToString()); }; string result; result = cache.Get("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual("1", result); result = cache.Get("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual("2", result); }
public void TestNoCacheStruct() { var cache = new NoCache(); int hits = 0; Func <int> getter = () => { hits++; return(hits); }; int result; result = cache.Get("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual(1, result); result = cache.Get("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual(2, result); }
public static async Task TestCache(HttpClient client, string getUrl) { EntityTagHeaderValue eTag; { var res = await client.GetAsync(getUrl); res.StatusCode.Should().Be(HttpStatusCode.OK); var cacheControlHeader = res.Headers.CacheControl; cacheControlHeader.Should().NotBeNull(); cacheControlHeader !.NoCache.Should().BeTrue(); cacheControlHeader.NoStore.Should().BeFalse(); cacheControlHeader.Private.Should().BeTrue(); cacheControlHeader.Public.Should().BeFalse(); cacheControlHeader.MustRevalidate.Should().BeTrue(); cacheControlHeader.MaxAge.Should().NotBeNull().And.Be(TimeSpan.FromDays(14)); res.Headers.ETag.Should().NotBeNull(); eTag = res.Headers.ETag !; } await client.TestSendAssertErrorAsync(HttpMethod.Get, getUrl, expectedStatusCode : HttpStatusCode.BadRequest, errorCode : ErrorCodes.Common.Header.IfNonMatch_BadFormat, headerSetup : static (headers, _) => { headers.TryAddWithoutValidation("If-None-Match", "\"dsdfd"); }); await client.TestSendAsync(HttpMethod.Get, getUrl, expectedStatusCode : HttpStatusCode.OK, headerSetup : static (headers, _) => { headers.TryAddWithoutValidation("If-None-Match", "\"aaa\""); }); await client.TestSendAsync(HttpMethod.Get, getUrl, expectedStatusCode : HttpStatusCode.NotModified, headerSetup : (headers, _) => { headers.Add("If-None-Match", eTag.ToString()); }); }
public void TestNoCacheObject() { var cache = new NoCache(); int hits = 0; Func <ScopedValue <string> > getter = () => { hits++; return(new ScopedValue <string>(hits.ToString(), DateTimeOffset.UtcNow)); }; GetScopedResult <string> result; result = cache.GetScoped("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual("1", result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); result = cache.GetScoped("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual("2", result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); }
public void ShouldNotThrowIfAvailable() { // Arrange var names = GetRandomArray <string>(5); var cache = new NoCache(); var executor = new CommandExecutor( new QueryExecutor(cache), cache ); var result = new List <int>(); Expect(TimeSpan.Zero.Ticks) .To.Equal(0, () => $"WTF: expected TimeSpan.Zero to be zero, but it's {TimeSpan.Zero}"); // Act using (var scope = TransactionScopes.ReadCommitted(TransactionScopeOption.RequiresNew ) ) { Expect(() => { result.AddRange(executor.Execute(new CreatePeople(names))); }).Not.To.Throw(); scope.Complete(); } // Assert Expect(result).Not.To.Be.Empty(); Expect(result).To.Contain.Exactly(names.Length).Items(); var queryExecutor = new QueryExecutor(cache); result.ForEach(id => { var inDb = queryExecutor.Execute(new FindPersonById(id)); Expect(names).To.Contain(inDb.Name); }); }
public void TestNoCacheStruct() { var cache = new NoCache(); int hits = 0; Func <ScopedValue <int> > getter = () => { hits++; return(new ScopedValue <int>(hits, DateTimeOffset.UtcNow)); }; GetScopedResult <int> result; using (CacheDirectives.SetScope(CacheMethod.GetOrSet, DateTimeOffset.UtcNow)) { result = cache.GetScoped("key", getter); Assert.AreEqual(1, hits); Assert.AreEqual(1, result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); result = cache.GetScoped("key", getter); Assert.AreEqual(2, hits); Assert.AreEqual(2, result.ScopedValue.Value); Assert.AreEqual(CacheMethodTaken.None, result.MethodTaken); } }
public void Remove(string cacheKey, string cacheValue1, string cacheValue2) { #region Arrange // Set up some variables var cache = new NoCache(); #endregion #region Act // 1 Try to save cacheValue1 under cacheKey. var returnedCachValue1 = ((ICache)cache).GetOrAdd(cacheKey, () => { return cacheValue1; }); // 2 Remove the cacheKey ((ICache)cache).Remove(cacheKey); #endregion #region Assert // There is no cache. There is nothing to assert. // Just make sure NoCache.Remove() doesn't throw an exception #endregion }
public NoCacheTests() { cache = new NoCache(); }
public ExpressionLanguageEngineConfig(IEvalExceptionHandlingPolicy policy = null, object fallbackValue = null, ICache <string, ExpressionLanguageAST> cache = null) { _policy = policy ?? EvalExceptionHandlingPolicy.ThrowPolicy; _fallbackValue = fallbackValue; _cache = cache ?? NoCache.GetInstance <string, ExpressionLanguageAST>(); }
public static ValidatorFactory CreateInstance(ICache <Type, IValidator> cache = null) { return(new ValidatorFactory(cache ?? NoCache.GetInstance <Type, IValidator>())); }
public void TestCacheManagerSetGetRemoveApi() { var cm = new CacheManagerInternals(new CacheManagerSettings()); CollectionAssert.AreEqual(new string[0], cm.GetCacheNames().ToList()); CollectionAssert.AreEqual(new string[0], cm.GetNotifierNames().ToList()); CollectionAssert.AreEqual(new string[0], cm.GetConnectionStringNames().ToList()); var cs1 = new PlainConnectionString("cs1", string.Empty); var cs2 = new PlainConnectionString("cs2", string.Empty); var cs3 = new PlainConnectionString("cs3", string.Empty); cm.SetConnectionString("cs1", cs1); cm.SetConnectionString("cs2", cs2); cm.SetConnectionString("cs3", cs3); var n1 = new NoNotifier("n1", new NoNotifierPolicy { ConnectionString = "1.1.1.1" }); var n2 = new NoNotifier("n2", new NoNotifierPolicy { ConnectionString = "2.2.2.2" }); var n3 = new NoNotifier("n3", new NoNotifierPolicy { ConnectionString = "3.3.3.3" }); cm.SetNotifier("n1", n1); cm.SetNotifier("n2", n2); cm.SetNotifier("n3", n3); var c1 = new NoCache("c1"); var c2 = new NoCache("c2"); var c3 = new NoCache("c3"); cm.SetCache("c1", c1); cm.SetCache("c2", c2); cm.SetCache("c3", c3); cm.Associate(c1, n2); cm.Associate(c2, n1); cm.Associate(c3, n3); CollectionAssert.AreEqual(new[] { "cs1", "cs2", "cs3" }, cm.GetConnectionStringNames().OrderBy(_ => _).ToList()); Assert.AreSame(cs1, cm.GetConnectionString("cs1")); Assert.AreSame(cs2, cm.GetConnectionString("cs2")); Assert.AreSame(cs3, cm.GetConnectionString("cs3")); CollectionAssert.AreEqual(new[] { "n1", "n2", "n3" }, cm.GetNotifierNames().OrderBy(_ => _).ToList()); Assert.AreSame(n1, cm.GetNotifier("n1")); Assert.AreSame(n2, cm.GetNotifier("n2")); Assert.AreSame(n3, cm.GetNotifier("n3")); CollectionAssert.AreEqual(new[] { "c1", "c2", "c3" }, cm.GetCacheNames().OrderBy(_ => _).ToList()); Assert.AreSame(c1, cm.GetCache("c1")); Assert.AreSame(c2, cm.GetCache("c2")); Assert.AreSame(c3, cm.GetCache("c3")); Assert.AreSame(n2, cm.GetAssociatedNotifier(c1)); Assert.AreSame(n1, cm.GetAssociatedNotifier(c2)); Assert.AreSame(n3, cm.GetAssociatedNotifier(c3)); cm.RemoveAssociation(c3); Assert.IsNull(cm.GetAssociatedNotifier(c3)); cm.RemoveCache("c3"); CollectionAssert.AreEqual(new[] { "c1", "c2" }, cm.GetCacheNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetCache("c3")); cm.RemoveNotifier("n3"); CollectionAssert.AreEqual(new[] { "n1", "n2" }, cm.GetNotifierNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetNotifier("n3")); cm.RemoveConnectionString("cs3"); CollectionAssert.AreEqual(new[] { "cs1", "cs2" }, cm.GetConnectionStringNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetConnectionString("cs3")); cm.RemoveAllNotifiers(); cm.RemoveAllCaches(); cm.RemoveAllNotifiers(); cm.RemoveAllConnectionStrings(); Assert.IsNull(cm.GetAssociatedNotifier(c2)); Assert.IsNull(cm.GetAssociatedNotifier(c1)); CollectionAssert.AreEqual(new string[0], cm.GetCacheNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetCache("c2")); Assert.IsNull(cm.GetCache("c1")); CollectionAssert.AreEqual(new string[0], cm.GetNotifierNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetNotifier("n2")); Assert.IsNull(cm.GetNotifier("n1")); CollectionAssert.AreEqual(new string[0], cm.GetConnectionStringNames().OrderBy(_ => _).ToList()); Assert.IsNull(cm.GetConnectionString("cs2")); Assert.IsNull(cm.GetConnectionString("cs1")); }