Exemplo n.º 1
0
        public void Cache_MultipleEntries()
        {
            var sourceConfig1 = new Mock <ICFamilyRulesConfig>().Object;
            var sourceConfig2 = new Mock <ICFamilyRulesConfig>().Object;

            var sourceSettings1 = new RulesSettings();
            var sourceSettings2 = new RulesSettings();

            var effectiveConfig1 = new Mock <ICFamilyRulesConfig>().Object;
            var effectiveConfig2 = new Mock <ICFamilyRulesConfig>().Object;

            var testSubject = new EffectiveRulesConfigCalculator.RulesConfigCache();

            // 1. Empty cache -> cache miss
            testSubject.FindConfig("key1", sourceConfig1, sourceSettings1).Should().BeNull();

            // 2. Add first entry to cache
            testSubject.Add("key1", sourceConfig1, sourceSettings1, effectiveConfig1);
            testSubject.CacheCount.Should().Be(1);

            // 3. Find second language - not found
            testSubject.FindConfig("key2", sourceConfig2, sourceSettings2).Should().BeNull();

            // 4. Add second entry to cache
            testSubject.Add("key2", sourceConfig2, sourceSettings2, effectiveConfig2);
            testSubject.CacheCount.Should().Be(2);

            // 5. Check can find both entries
            testSubject.FindConfig("key1", sourceConfig1, sourceSettings1).Should().BeSameAs(effectiveConfig1);
            testSubject.FindConfig("key2", sourceConfig2, sourceSettings2).Should().BeSameAs(effectiveConfig2);
        }
Exemplo n.º 2
0
        public void Cache_DifferentSourceConfig_NotFound_AndEntryCleared()
        {
            var sourceConfig1    = new Mock <ICFamilyRulesConfig>().Object;
            var sourceSettings1  = new UserSettings();
            var effectiveConfig1 = new Mock <ICFamilyRulesConfig>().Object;

            var testSubject = new EffectiveRulesConfigCalculator.RulesConfigCache();

            testSubject.Add("key1", sourceConfig1, sourceSettings1, effectiveConfig1);
            testSubject.CacheCount.Should().Be(1);

            // 1. Search for added item -> found
            testSubject.FindConfig("key1", sourceConfig1, sourceSettings1).Should().BeSameAs(effectiveConfig1);
            testSubject.CacheCount.Should().Be(1);

            // 2. Different source config -> not found
            testSubject.FindConfig("key1", new Mock <ICFamilyRulesConfig>().Object, sourceSettings1).Should().BeNull();
            testSubject.CacheCount.Should().Be(0);
        }
Exemplo n.º 3
0
 public void TestInitialize()
 {
     testSubject = new EffectiveRulesConfigCalculator.RulesConfigCache();
 }