Esempio n. 1
0
        public void GlobalPartitionName()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p       = factory.GetGlobal();

            p.DisplayName.Is("Tenant1");
        }
Esempio n. 2
0
        public void CanGetItemFromCache()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p       = factory.GetGlobal();

            p.CreateEntry("Test", "Value").Is(true);

            p.TryGetValue <string>("Test", out var value).Is(true);
            value.Is("Value");
        }
Esempio n. 3
0
        public void ReturnsSamePartition()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p       = factory.GetOrCreatePartition("Part3");

            // Same as factory1
            var factory2 = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p2       = factory2.GetOrCreatePartition("Part3");

            ReferenceEquals(p, p2).Is(true);
        }
Esempio n. 4
0
        public void Cache_Invalidate()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p       = factory.GetGlobal();

            p.CreateEntry("Green", "Value").Is(true);

            p.TryGetValue <string>("Green", out _).Is(true);
            p.Invalidate();
            p.TryGetValue <string>("Green", out _).Is(false);
        }
Esempio n. 5
0
        public void PartitionName()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var p       = factory.GetOrCreatePartition("Part1");

            p.DisplayName.Is("Tenant1>Part1");

            var factory2 = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, RequestScope.Static("Tenant2"));
            var p2       = factory2.GetOrCreatePartition("Part2");

            p2.DisplayName.Is("Tenant2>Part2");
        }
Esempio n. 6
0
        public void Global_Misses_Partition()
        {
            var factory   = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var partition = factory.GetOrCreatePartition("Part1");

            partition.CreateEntry("Blue", "Value").Is(true);

            var global = factory.GetGlobal();

            global.TryGetValue <string>("Blue", out var value).Is(false);
            partition.TryGetValue <string>("Blue", out value).Is(true);
        }
Esempio n. 7
0
        public void Partitions()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, RequestScope.Static("Tenant3"));

            factory.Partitions.Should().BeEmpty();

            var tenantPartition = factory.GetOrCreatePartition("TenantPartition");

            factory.Partitions.Should()
            .ContainSingle()
            .And
            .Contain(tenantPartition);
            GlobalFactory.Partitions.Should().NotContain(tenantPartition);
        }
Esempio n. 8
0
        public void TenantGlobal_andGlobalNotSame()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            var tg      = factory.GetGlobal();

            var g = GlobalFactory.GetGlobal();

            // Not same
            ReferenceEquals(tg, g).Is(false);

            // Extra checks that when we cache something they are different
            tg.CreateEntry("Key1", "Value1").Is(true);
            g.TryGetValue <string>("Key1", out _).Is(false);
            tg.TryGetValue <string>("Key1", out _).Is(true);
        }
Esempio n. 9
0
        public void Wrong_Key_Add()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);

            var g = factory.GetGlobal();
            var p = factory.GetOrCreatePartition("Matrix7");

            var globalKey          = new PartitionObjectKeyString(g.PartitionKey, "Yellow3");
            var partitionObjectKey = new PartitionObjectKeyString(p.PartitionKey, "Purple3");

            g.CreateEntry(globalKey, "Value").Is(true);
            p.CreateEntry(globalKey, "Value2").Is(false);

            g.CreateEntry(partitionObjectKey, "Value").Is(false);
            p.CreateEntry(partitionObjectKey, "Value2").Is(true);
        }
Esempio n. 10
0
        public void Wrong_Key_TryGetValue()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);
            // Setup
            var g                  = factory.GetGlobal();
            var p                  = factory.GetOrCreatePartition("Matrix5");
            var globalKey          = new PartitionObjectKeyString(g.PartitionKey, "Yellow");
            var partitionObjectKey = new PartitionObjectKeyString(p.PartitionKey, "Purple");

            g.CreateEntry(globalKey, "Value").Is(true);
            p.CreateEntry(partitionObjectKey, "Value2").Is(true);

            // Cant get global cache key from Partition
            p.TryGetValue <string>(globalKey, out _).Is(false);
            g.TryGetValue <string>(globalKey, out _).Is(true);

            // Cant get partition key from global
            g.TryGetValue <string>(partitionObjectKey, out _).Is(false);
            p.TryGetValue <string>(partitionObjectKey, out _).Is(true);
        }
Esempio n. 11
0
        public void Wrong_Key_Remove()
        {
            var factory = new TenantSpecificMemoizerFactory(NullLoggerFactory.Instance, _requestScope);

            // Setup
            var g = factory.GetGlobal();
            var p = factory.GetOrCreatePartition("Matrix6");

            var globalKey          = new PartitionObjectKeyString(g.PartitionKey, "Yellow2");
            var partitionObjectKey = new PartitionObjectKeyString(p.PartitionKey, "Purple2");

            g.CreateEntry(globalKey, "Value").Is(true);
            p.CreateEntry(partitionObjectKey, "Value2").Is(true);

            // Cant remove global cache key from Partition
            g.Remove(globalKey).Is(true);
            p.Remove(globalKey).Is(false);

            // Cant remove partition key from global
            g.Remove(partitionObjectKey).Is(false);
            p.Remove(partitionObjectKey).Is(true);
        }