Пример #1
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 ActorConfigurationBuilder()
                                    .AddCertificateModule(container)
                                    .Build()
                                    .ToActorManager();

            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));
        }
Пример #2
0
        public async Task DisableQueueSuccessTestApi()
        {
            QueueDetailContractV1 result;
            IEnumerable <QueueDetailContractV1> list;
            var context = _workContext.WithTag(_tag);

            list = (await _client.Management.GetQueueList(context, false)).Value.Items;
            list.Should().NotBeNull();
            list.Count().Should().Be(0);

            list = (await _client.Management.GetQueueList(context, true)).Value.Items;
            list.Should().NotBeNull();
            list.Count().Should().Be(0);

            const string queueName = "test-queue";
            var          request   = new SetQueueContractV1
            {
                QueueName         = queueName,
                CurrentSizeLimit  = 10,
                CurrentRetryLimit = 11,
                LockValidForSec   = 12,
            };

            await _client.Management.SetQueue(context, request);

            list = (await _client.Management.GetQueueList(context, false)).Value.Items;
            list.Should().NotBeNull();
            list.Count().Should().Be(1);

            result = (await _client.Management.GetQueue(context, queueName)).Value;
            result.Should().NotBeNull();
            result.QueueName.Should().Be(queueName);

            await _client.Management.DisableQueue(context, queueName);

            await Verify.AssertExceptionAsync <RestNotFoundException>(async() => await _client.Management.GetQueue(context, queueName));

            list = (await _client.Management.GetQueueList(context, true)).Value.Items;
            list.Should().NotBeNull();
            list.Count().Should().Be(1);
            result = list.First();
            result.QueueName.Should().Be(queueName);
            result.Disable.Should().BeTrue();

            await _client.Management.EnableQueue(context, queueName);

            result = (await _client.Management.GetQueue(context, queueName)).Value;
            result.Should().NotBeNull();
            result.QueueName.Should().Be(queueName);

            list = (await _client.Management.GetQueueList(context, false)).Value.Items;
            list.Should().NotBeNull();
            list.Count().Should().Be(1);
        }
Пример #3
0
        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 ActorConfigurationBuilder()
                                    .AddIdentityModule(container)
                                    .Build()
                                    .ToActorManager();

            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));
        }
Пример #4
0
        public async Task SetDuplicateQueueFailedTestsApi()
        {
            IEnumerable <QueueDetailContractV1> rows;
            var context = _workContext.WithTag(_tag);

            rows = (await _client.Management.GetQueueList(context)).Value.Items;
            rows.Should().NotBeNull();
            rows.Count().Should().Be(0);

            const string queueName = "test-queue";
            var          request   = new SetQueueContractV1
            {
                QueueName         = queueName,
                CurrentSizeLimit  = 10,
                CurrentRetryLimit = 11,
                LockValidForSec   = 12,
            };

            await _client.Management.SetQueue(context, request);

            QueueDetailContractV1 result = (await _client.Management.GetQueue(context, queueName)).Value;

            result.Should().NotBeNull();
            result.QueueName.Should().Be(queueName);

            rows = (await _client.Management.GetQueueList(context)).Value.Items;
            rows.Should().NotBeNull();
            rows.Count().Should().Be(1);

            await _client.Management.SetQueue(context, request);

            rows = (await _client.Management.GetQueueList(context)).Value.Items;
            rows.Should().NotBeNull();
            rows.Count().Should().Be(1);

            await _client.Management.DeleteQueue(context, queueName);

            rows = (await _client.Management.GetQueueList(context)).Value.Items;
            rows.Should().NotBeNull();
            rows.Count().Should().Be(0);

            await Verify.AssertExceptionAsync <RestNotFoundException>(async() => await _client.Management.GetQueue(context, queueName));
        }
Пример #5
0
        public async Task SetQueueSuccessTestsApi()
        {
            var context = _workContext.WithTag(_tag);

            const string queueName = "test-queue";

            await Verify.AssertExceptionAsync <RestNotFoundException>(async() => await _client.Management.GetQueue(context, queueName));

            RestResponse <QueueDetailContractV1> check = await _client.Management.GetQueue(context, queueName, new HttpStatusCode[] { HttpStatusCode.NotFound });

            check.StatusCode.Should().Be(HttpStatusCode.NotFound);

            var request = new SetQueueContractV1
            {
                QueueName         = queueName,
                CurrentSizeLimit  = 10,
                CurrentRetryLimit = 11,
                LockValidForSec   = 12,
            };

            await _client.Management.SetQueue(context, request);

            QueueDetailContractV1 result = (await _client.Management.GetQueue(context, queueName)).Value;

            result.Should().NotBeNull();
            result.QueueName.Should().Be(queueName);
            result.CurrentSizeLimit.Should().Be(10);
            result.CurrentRetryLimit.Should().Be(11);
            result.LockValidForSec.Should().Be(12);
            result.Disable.Should().BeFalse();
            result.QueueLength.Should().Be(0);

            await _client.Management.DeleteQueue(context, queueName);

            await Verify.AssertExceptionAsync <RestNotFoundException>(async() => await _client.Management.GetQueue(context, queueName));
        }
Пример #6
0
        public async Task QueueSizeLimitTestApi()
        {
            const int messageSize = 10;
            var       context     = _workContext.WithTag(_tag);

            AgentContractV1 agent = await _utility.SetupAgentAndQueue(_queueName, _agentName, queueSize : 10);

            var messageList     = new List <EnqueueMessageContractV1>();
            var readMessageList = new List <MessageContractV1>();

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                EnqueueMessageContractV1 message = _utility.CreateMessage(context, agent.AgentId, _queueName);
                messageList.Add(message);

                await _client.Message.EnqueueMessage(context, message);
            }

            await Verify.AssertExceptionAsync <RestConflictException>(async() =>
            {
                EnqueueMessageContractV1 message = _utility.CreateMessage(context, agent.AgentId, _queueName);
                await _client.Message.EnqueueMessage(context, message);
            });

            await _utility.VerifyQueue(context, _queueName, messageSize, 0);

            MessageContractV1 readMessage;

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                readMessage = (await _client.Message.DequeueMessageWithLock(context, _queueName, agent, null)).Value;
                readMessage.Should().NotBeNull();
                readMessageList.Add(readMessage);
            }

            readMessage = (await _client.Message.DequeueMessageWithLock(context, _queueName, agent, null)).Value;
            readMessage.Should().BeNull();

            var zip = messageList
                      .OrderBy(x => x.ClientMessageId)
                      .Zip(readMessageList.OrderBy(x => x.ClientMessageId), (f, s) => new Tuple <EnqueueMessageContractV1, MessageContractV1>(f, s));

            foreach (var item in zip)
            {
                _utility.VerifyMessage(item.Item1, item.Item2, agent.AgentId, true);
            }

            foreach (var item in readMessageList)
            {
                var settleMessage = new SettleMessageContractV1
                {
                    AgentId    = agent.AgentId,
                    QueueName  = _queueName,
                    SettleType = SettleType.Processed,
                    MessageId  = item.MessageId,
                };

                await _client.Message.SettleMessage(context, settleMessage);
            }

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            foreach (var item in readMessageList)
            {
                HistoryContractV1 history = (await _client.History.GetHistory(context, item.MessageId)).Value;
                _utility.VerifyHistoryMessage(item, history, _queueName, _agentName);
            }
        }
Пример #7
0
        public async Task QueueSizeLimitTest()
        {
            const int messageSize = 10;
            var       context     = _workContext.WithTag(_tag);

            int agentId = await _utility.SetupAgentAndQueue(_queueName, _agentName, queueSize : 10);

            var messageList     = new List <InternalEnqueueMessageV1>();
            var readMessageList = new List <InternalMessageV1>();

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);
                messageList.Add(message);

                await _message.EnqueueMessage(context, message);
            }

            await Verify.AssertExceptionAsync <QueueFullException>(async() =>
            {
                InternalEnqueueMessageV1 message = _utility.CreateMessage(context, agentId, _queueName);
                await _message.EnqueueMessage(context, message);
            });

            await _utility.VerifyQueue(context, _queueName, messageSize, 0);

            InternalMessageV1 readMessage;

            foreach (int index in Enumerable.Range(0, messageSize))
            {
                readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

                readMessage.Should().NotBeNull();
                readMessageList.Add(readMessage);
            }

            readMessage = await _message.DequeueMessageWithLock(context, _queueName, agentId);

            readMessage.Should().BeNull();

            var zip = messageList
                      .OrderBy(x => x.ClientMessageId)
                      .Zip(readMessageList.OrderBy(x => x.ClientMessageId), (f, s) => new Tuple <InternalEnqueueMessageV1, InternalMessageV1>(f, s));

            foreach (var item in zip)
            {
                _utility.VerifyMessage(item.Item1, item.Item2, agentId, true);
            }

            foreach (var item in readMessageList)
            {
                await _message.SettleMessage(context, item.MessageId, agentId, SettleType.Processed);
            }

            await _utility.VerifyQueue(context, _queueName, 0, 0);

            foreach (var item in readMessageList)
            {
                InternalHistoryV1 history = await _management.GetHistory(context, item.MessageId);

                _utility.VerifyHistoryMessage(item, history, _queueName, _agentName);
            }
        }