コード例 #1
0
        public void When_receiving_known_favourite_should_not_store_in_cache()
        {
            using (var realCache = new MemoryCache(new MemoryCacheOptions()))
            {
                var favourite        = DeltaHelper.GetFavouriteDelta(_hashProvider);
                var candidateListKey = DeltaElector.GetCandidateListCacheKey(favourite);

                AddVoterAsExpectedProducer(favourite.VoterId);

                var elector = new DeltaElector(realCache, _deltaProducersProvider, _reputationManager, _logger);

                elector.OnNext(favourite);
                elector.OnNext(favourite);

                realCache.TryGetValue(candidateListKey, out IDictionary <FavouriteDeltaBroadcast, bool> retrieved)
                .Should().BeTrue();

                retrieved.Keys.Count.Should().Be(1);
                retrieved.Should().ContainKey(favourite);
            }
        }
コード例 #2
0
        public void When_receiving_new_valid_favourite_should_store_in_cache()
        {
            var favourite        = DeltaHelper.GetFavouriteDelta(_hashProvider);
            var candidateListKey = DeltaElector.GetCandidateListCacheKey(favourite);

            AddVoterAsExpectedProducer(favourite.VoterId);

            var elector = new DeltaElector(_cache, _deltaProducersProvider, _reputationManager, _logger);

            var addedEntry = Substitute.For <ICacheEntry>();

            _cache.CreateEntry(Arg.Is <string>(s => s.Equals(candidateListKey)))
            .Returns(addedEntry);

            elector.OnNext(favourite);

            _cache.Received(1).TryGetValue(Arg.Is <string>(s => s.Equals(candidateListKey)), out Arg.Any <object>());
            _cache.Received(1).CreateEntry(Arg.Is <string>(s => s.Equals(candidateListKey)));

            var addedValue = addedEntry.Value;

            addedValue.Should().BeAssignableTo <IDictionary <FavouriteDeltaBroadcast, bool> >();
            ((IDictionary <FavouriteDeltaBroadcast, bool>)addedValue).Should().ContainKey(favourite);
        }