Пример #1
0
        public async Task ActorMethodTest()
        {
            int count = 0;

            ActorManager manager = new ActorManager();

            manager.Register <ICache>(_context, (c, x, m) => new StringCache(x, m, y => count += y));

            ActorKey key1   = new ActorKey("Cache/Test1");
            ICache   cache1 = await manager.CreateProxyAsync <ICache>(_context, key1);

            count.Should().Be(1);

            const string firstText = "first";

            bool test = await cache1.IsCached(firstText);

            test.Should().BeFalse();
            await cache1.Add(firstText);

            test = await cache1.IsCached(firstText);

            test.Should().BeTrue();

            await manager.DeactivateAsync <ICache>(_context, key1);

            count.Should().Be(0);

            await manager.DeactivateAllAsync(_context);
        }
Пример #2
0
        public async Task ActorMultipleTest()
        {
            int count = 0;

            ActorManager manager = new ActorManager();

            manager.Register <ICache>(_context, (c, x, m) => new StringCache(x, m, y => count += y));

            ActorKey key1   = new ActorKey("Cache/Test1");
            ICache   cache1 = await manager.CreateProxyAsync <ICache>(_context, key1);

            count.Should().Be(1);

            ActorKey key2   = new ActorKey("Cache/Test2");
            ICache   cache2 = await manager.CreateProxyAsync <ICache>(_context, key2);

            count.Should().Be(2);

            await manager.DeactivateAsync <ICache>(_context, key1);

            count.Should().Be(1);

            await manager.DeactivateAsync <ICache>(_context, key2);

            count.Should().Be(0);

            await manager.DeactivateAllAsync(_context);
        }
Пример #3
0
        public async Task ActorAutoFacActionSimpleTest()
        {
            IActorManager manager = new ActorManager();

            var builder = new ContainerBuilder();

            builder.RegisterType <StringCache>().As <ICache>();
            builder.RegisterInstance(manager).As <IActorManager>();
            IContainer container = builder.Build();

            using (container.BeginLifetimeScope())
            {
                manager.Register <ICache>(_context,
                                          (c, k, m) =>
                {
                    return(container.Resolve <ICache>(new TypedParameter(typeof(ActorKey), k)));
                });

                ActorKey key   = new ActorKey("cache/test");
                ICache   cache = await manager.CreateProxyAsync <ICache>(_context, key);

                (await cache.GetCount()).Should().Be(1);
                await manager.DeactivateAsync <ICache>(_context, key);

                (await cache.GetCount()).Should().Be(2);
            }

            await manager.DeactivateAllAsync(_context);
        }
Пример #4
0
        public async Task ActorSameInstanceTest()
        {
            int count = 0;

            var manager = new ActorManager();

            manager.Register <ICache>(_context, (c, x, m) => new StringCache(x, manager, y => count += y));

            ActorKey key1   = new ActorKey("Cache/Test1");
            ICache   cache1 = await manager.CreateProxyAsync <ICache>(_context, key1);

            count.Should().Be(1);

            ActorKey key2   = new ActorKey("Cache/Test2");
            ICache   cache2 = await manager.CreateProxyAsync <ICache>(_context, key2);

            count.Should().Be(2);

            const string firstText  = "first";
            const string secondText = "secondFirst";

            await cache1.Add(firstText);

            bool test = await cache1.IsCached(firstText);

            test.Should().BeTrue();

            await cache2.Add(secondText);

            bool test2 = await cache2.IsCached(secondText);

            test2.Should().BeTrue();

            ICache cache1Dup = await manager.CreateProxyAsync <ICache>(_context, key1);

            test = await cache1Dup.IsCached(firstText);

            test.Should().BeTrue();
            test = await cache1Dup.IsCached(secondText);

            test.Should().BeFalse();

            await manager.DeactivateAsync <ICache>(_context, key1);

            await manager.DeactivateAsync <ICache>(_context, key2);

            count.Should().Be(0);

            await manager.DeactivateAllAsync(_context);
        }
Пример #5
0
        public async Task ActorDeactivateAllTest()
        {
            int count = 0;

            var manager = new ActorManager();

            manager.Register <ICache>(_context, (c, x, m) => new StringCache(x, m, y => count += y));

            ActorKey key   = new ActorKey("cache/test");
            ICache   cache = await manager.CreateProxyAsync <ICache>(_context, key);

            count.Should().Be(1);
            await manager.DeactivateAllAsync(_context);

            count.Should().Be(0);
        }