Exemple #1
0
        public void Multi_Keys_Get_Test()
        {
            var cache1       = new MyCache1("cache 1");
            var cacheValues1 = cache1.GetOrDefault(new[] { "A", "B" });

            cacheValues1.ShouldNotBeNull();
            cacheValues1.Length.ShouldBe(2);
            cacheValues1[0].ShouldBe(0);
            cacheValues1[1].ShouldBe(0);

            cacheValues1 = cache1.Get(new[] { "A", "B" }, (key) => 11);
            cacheValues1.ShouldNotBeNull();
            cacheValues1.Length.ShouldBe(2);
            cacheValues1[0].ShouldBe(11);
            cacheValues1[1].ShouldBe(11);

            var cache2       = new MyCache2("cache 2");
            var cacheValues2 = cache2.GetOrDefault(new[] { "C", "D" });

            cacheValues2.ShouldNotBeNull();
            cacheValues2.Length.ShouldBe(2);
            cacheValues2[0].ShouldBeNull();
            cacheValues2[1].ShouldBeNull();

            cacheValues2 = cache2.Get(new[] { "C", "D" }, (key) => 22);
            cacheValues2.ShouldNotBeNull();
            cacheValues2.Length.ShouldBe(2);
            cacheValues2[0].ShouldBe(22);
            cacheValues2[1].ShouldBe(22);
        }
Exemple #2
0
        public void Single_Key_Get_Test()
        {
            var cache1      = new MyCache1("cache 1");
            var cacheValue1 = cache1.GetOrDefault("A");

            cacheValue1.ShouldBe(0);

            cacheValue1 = cache1.Get("A", (key) => 1);
            cacheValue1.ShouldBe(1);

            var cache2      = new MyCache2("cache 2");
            var cacheValue2 = cache2.GetOrDefault("B");

            cacheValue2.ShouldBeNull();

            cacheValue2 = cache2.Get("B", (key) => 2);
            cacheValue2.ShouldBe(2);
        }