Beispiel #1
0
        public void GetLookupKey_sucess()
        {
            var lookup = new CacheLookup <CacheItem>()
                         .Add(x => x.LookupKey)
                         .Add(x => x.LookupKeyOther);

            var key = lookup.GetLookupKey(new CacheItem {
                LookupKey = 1, LookupKeyOther = "other"
            });

            Assert.That(key, Is.EqualTo("1_other"));
        }
Beispiel #2
0
        public async Task Run_with_lookups_concurrent_run_single_result_success()
        {
            const int cacheTime = 300;
            var       cache     = Substitute.For <ICache>();
            var       items     = new Dictionary <string, object>();
            var       taskKey   = typeof(CacheItem).FullName;
            var       lookup    = new CacheLookup <CacheItem>().Add(x => x.LookupKey);

            var task = new CacheTask <CacheItem>(_task, taskKey).Span(cacheTime);

            task.Lookup(lookup);

            void Save(string key, object value)
            {
                items[key] = value;
            }

            await task.Run(cache, Save).ConfigureAwait(false);

            var lookups = items["Lookup_CacheItem_LookupKey"] as ILookup <string, CacheItem>;
            var all     = items[taskKey] as IEnumerable <CacheItem>;

            Assert.That(items.Count, Is.EqualTo(2));
            Assert.That(all.Count(), Is.EqualTo(3));
            Assert.That(lookups.Count(), Is.EqualTo(2));

            var lookupKey1 = lookup.GetLookupKey(new CacheItem {
                LookupKey = 1
            });
            var lookupKey2 = lookup.GetLookupKey(new CacheItem {
                LookupKey = 2
            });

            Assert.That(lookups[lookupKey1].Count(), Is.EqualTo(2));
            Assert.That(lookups[lookupKey2].Count(), Is.EqualTo(1));
        }