public void AddOrGetExisting() { var cache2 = new CacheTest(); var cache3 = new CacheTest(); var cache4 = new CacheTest(); System.Runtime.Caching.MemoryCache cache = System.Runtime.Caching.MemoryCache.Default; int cache1_1 = cache.AddOrGetExisting("cache1", 1); int cache1_2 = cache.AddOrGetExisting("cache1", 2); int cache2_1 = cache.AddOrGetExisting("cache2", i => cache2.Increment()); int cache2_2 = cache.AddOrGetExisting("cache2", i => cache2.Increment()); int cache3_1 = cache.AddOrGetExisting("cache3", i => cache3.Increment(), new CacheItemPolicy()); int cache3_2 = cache.AddOrGetExisting("cache3", i => cache3.Increment(), new CacheItemPolicy()); int cache4_1 = cache.AddOrGetExisting("cache4", i => cache4.Increment(), new DateTimeOffset(new DateTime(2100, 01, 01))); int cache4_2 = cache.AddOrGetExisting("cache4", i => cache4.Increment(), new DateTimeOffset(new DateTime(2100, 01, 01))); Assert.AreEqual(1, cache1_1); Assert.AreEqual(1, cache1_2); Assert.AreEqual(1, cache2_1); Assert.AreEqual(1, cache2_2); Assert.AreEqual(1, cache3_1); Assert.AreEqual(1, cache3_2); Assert.AreEqual(1, cache4_1); Assert.AreEqual(1, cache4_2); }
public async Task GetByCodeTest() { var country = new Country() { Alpha2Code = "US", Name = "United States of America" }; var cache = new CacheTest(); cache.Result = country; var reqCreator = new Mock <IAPIRequestCreator>(); var service = new CountryService(cache, reqCreator.Object); var countryToTest = await service.GetByCode("US"); Assert.AreEqual(country.Name, countryToTest.Name); Assert.AreEqual(country.Alpha2Code, countryToTest.Alpha2Code); }
private ICache CacheCountry() { var country = new Country() { Alpha2Code = "US", Name = "United States of America", Currencies = new List <Currency>() { new Currency() { Code = "USD" } } }; var cache = new CacheTest(); cache.Result = country; return(cache); }
public void TestQueryInsteadOfCache() { CacheTest notNull = new CacheTest { Age = 0, Name = string.Empty, Tags = new List <string>(), Ids = new List <int>() }; string expectedQuery = "Age=0&Name="; Assert.Equal(expectedQuery, notNull.ToQuery()); CacheTest nullable = new CacheTest { Age = null, Name = null, Tags = null, Ids = null }; string expectedQuery2 = string.Empty; Assert.Equal(expectedQuery2, nullable.ToQuery()); CacheTest defaultTest = new CacheTest { Age = 0, Name = string.Empty, Tags = new List <string> { string.Empty }, Ids = new List <int> { 0 } }; string expectedQuery3 = "Age=0&Name=&Tags=&Ids=0"; Assert.Equal(expectedQuery3, defaultTest.ToQuery()); Assert.NotEqual(nullable.ToQuery(), defaultTest.ToQuery()); Assert.NotEqual(notNull.ToQuery(), defaultTest.ToQuery()); Assert.NotEqual(notNull.ToQuery(), nullable.ToQuery()); }
public void FromCache() { var cache1 = new CacheTest(); var cache2 = new CacheTest(); int cache1_1 = cache1.FromCache(i => cache1.Increment()); int cache1_2 = cache1.FromCache(i => cache1.Increment()); int cache2_1 = cache1.FromCache("CustomKey", i => cache2.Increment()); int cache2_2 = cache1.FromCache("CustomKey", i => cache2.Increment()); int cache3_1 = cache1.FromCache("CustomKeyWithValue", 1); int cache3_2 = cache1.FromCache("CustomKeyWithValue", 2); Assert.AreEqual(1, cache1_1); Assert.AreEqual(1, cache1_2); Assert.AreEqual(1, cache2_1); Assert.AreEqual(1, cache2_2); Assert.AreEqual(1, cache3_1); Assert.AreEqual(1, cache3_2); }
public void CanIndexManyCoincidentPointsTest() { IFeatureClass featureClass = CreatePointFeatureClass("CanIndexManyCoincidentPointsTest", 0.001); AddPointFeature(featureClass, 2637000, 1193000); AddPointFeature(featureClass, 2638000, 1194000); // add 1000 coincident points const int count = 1000; for (int i = 0; i < count; i++) { AddPointFeature(featureClass, 2637887, 1193150.273400001); } // when encountering many coincident points, the BoxTree for the features must not be split "eternally" var test = new CacheTest(featureClass); var container = new TestContainer.TestContainer(); container.AddTest(test); container.Execute(); }