Example #1
0
        public async Task ActorSingleChainTest()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <ActorNode>().As <IActorNode>();
            builder.RegisterType <ActorSum>().As <IActorSum>();
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorManagerBuilder()
                                    .Register <IActorNode>((c, k, m) => container.Resolve <IActorNode>(new TypedParameter(typeof(ActorKey), k), new TypedParameter(typeof(IActorManager), m)))
                                    .Register <IActorSum>((c, k, m) => container.Resolve <IActorSum>(new TypedParameter(typeof(ActorKey), k), new TypedParameter(typeof(IActorManager), m)))
                                    .Build();

            using (container)
            {
                ActorKey   key  = new ActorKey("node/test");
                IActorNode node = await manager.CreateProxyAsync <IActorNode>(_context, key);

                int sum = 0;
                for (int i = 0; i < 10; i++)
                {
                    await node.Add(_context, i);

                    sum += i;
                }

                IActorSum sumActor = await manager.CreateProxyAsync <IActorSum>(_context, new ActorKey(sumActorName));

                (await sumActor.GetSum()).Should().Be(sum);
            }

            await manager.DeactivateAllAsync(_context);
        }
Example #2
0
        public async Task CertificateSetGetTest()
        {
            const string testData = "Test data, test, data";
            IWorkContext context  = _workContext.WithMethodName();

            var builder = new ContainerBuilder();

            builder.RegisterModule(new CertificateAutoFacModule());
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorManagerBuilder()
                                    .AddCertificateModule(container)
                                    .Build();

            using (ILifetimeScope scopeContainer = container.BeginLifetimeScope())
                using (manager)
                {
                    var key = new LocalCertificateKey(StoreLocation.LocalMachine, StoreName.My, Constants.JwtVaultTestCertificateThumbprint, true);

                    ICertificateActor actor = await manager.CreateProxyAsync <ICertificateActor>(context, key.CreateActorKey());

                    byte[] rawBytes       = Encoding.UTF8.GetBytes(testData);
                    byte[] encryptedBytes = await actor.Encrypt(context, rawBytes);

                    byte[] unencrypted = await actor.Decrypt(context, encryptedBytes);

                    string result = Encoding.UTF8.GetString(unencrypted);

                    result.Should().Be(testData);
                }

            await Verify.AssertExceptionAsync <ArgumentException>(async() => await manager.DeactivateAllAsync(_workContext));
        }
        public async Task CertificateSetGetTest()
        {
            IWorkContext context = _workContext.WithMethodName();

            var identityRepository = new IdentityInMemoryStore()
                                     .Set(_workContext, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User).With(new ApiKey("API Key1", DateTime.UtcNow.AddYears(1))))
                                     .Set(_workContext, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User).With(new ApiKey("API Key2", DateTime.UtcNow.AddYears(1))));

            var builder = new ContainerBuilder();

            builder.RegisterModule(new IdentityActorAutoFacModule());
            builder.RegisterInstance(identityRepository).As <IIdentityStore>();
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorManagerBuilder()
                                    .AddIdentityModule(container)
                                    .Build();

            using (ILifetimeScope scopeContainer = container.BeginLifetimeScope())
                using (manager)
                {
                    IIdentityActor clientActor1 = await manager.CreateProxyAsync <IIdentityActor>(context, new ActorKey("*****@*****.**"));

                    IdentityPrincipal client1 = await clientActor1.Get(context);

                    client1.Should().NotBeNull();
                    client1.PrincipalId.Value.Should().Be("*****@*****.**");
                    client1.ApiKey.Value.Should().Be("API Key1");

                    IIdentityActor clientActor2 = await manager.CreateProxyAsync <IIdentityActor>(context, new ActorKey("*****@*****.**"));

                    IdentityPrincipal client2 = await clientActor2.Get(context);

                    client2.Should().NotBeNull();
                    client2.PrincipalId.Value.Should().Be("*****@*****.**");
                    client2.ApiKey.Value.Should().Be("API Key2");

                    await clientActor2.Remove(context);

                    (await clientActor2.Get(context)).Should().BeNull();

                    identityRepository.Get(context, new PrincipalId("*****@*****.**")).Should().BeNull();

                    await clientActor2.Set(context, new IdentityPrincipal(new PrincipalId("*****@*****.**"), IdentityPrincipalType.User));

                    (await clientActor2.Get(context)).Should().NotBeNull();
                    identityRepository.Get(context, new PrincipalId("*****@*****.**")).Should().NotBeNull();
                }

            await Verify.AssertExceptionAsync <ArgumentException>(async() => await manager.DeactivateAllAsync(_workContext));
        }
Example #4
0
        public async Task ActorAutoFacSimpleTest()
        {
            var builder = new ContainerBuilder();

            builder.RegisterType <StringCache>().As <ICache>();
            ILifetimeScope container = builder.Build();

            IActorManager manager = new ActorManagerBuilder()
                                    .Register <ICache>((c, k, m) => container.Resolve <ICache>(new TypedParameter(typeof(ActorKey), k), new TypedParameter(typeof(IActorManager), m)))
                                    .Build();

            using (container.BeginLifetimeScope())
            {
                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);
        }