Ejemplo n.º 1
0
        public async Task RemoveWithCaching()
        {
            var identities = new List <Identity> {
                IdentityGenerator.Default, IdentityGenerator.Generate()
            };
            await _identityRepository.AddAsync(identities, addToCache : true);

            Assert.Equal(2, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(0, _cache.Misses);

            await _identityRepository.RemoveAsync(identities.First());

            Assert.Equal(1, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(0, _cache.Misses);

            await _identityRepository.RemoveAsync(identities);

            Assert.Equal(0, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(0, _cache.Misses);

            await _client.RefreshAsync();

            Assert.Equal(0, await _identityRepository.CountAsync());
        }
        public async Task RemoveByIdsWithCachingAsync()
        {
            var identity = await _identityRepository.AddAsync(IdentityGenerator.Default, o => o.ImmediateConsistency());

            Assert.Equal(0, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(0, _cache.Misses);

            await _identityRepository.RemoveAsync(identity.Id, o => o.ImmediateConsistency());

            Assert.Equal(0, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(1, _cache.Misses);

            identity = await _identityRepository.AddAsync(IdentityGenerator.Generate(), o => o.Cache().ImmediateConsistency());

            Assert.Equal(1, _cache.Count);
            Assert.Equal(0, _cache.Hits);
            Assert.Equal(1, _cache.Misses);

            await _identityRepository.RemoveAsync(identity.Id, o => o.ImmediateConsistency());

            Assert.Equal(0, _cache.Count);
            Assert.Equal(1, _cache.Hits);
            Assert.Equal(1, _cache.Misses);

            Assert.Equal(0, await _identityRepository.CountAsync());
        }