public async Task StopsWhenTokenIsCancelled()
        {
            keyFactory
            .Setup(x => x.FindAllAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <IKeyId>());

            var op = new MultiKeyOperation <int>(keyFactory.Object,
                                                 (keyId, ct) =>
            {
                Assert.Fail();
                return(Task.FromResult(0));
            },
                                                 i =>
            {
                Assert.Fail();
                return(false);
            });

            var token = new CancellationTokenSource();

            var task = op.RunOperationAsync(token.Token);

            token.Cancel();
            await task;
        }
        public async Task DiscoverNewKeys()
        {
            int counter = 0;

            keyFactory
            .Setup(x => x.FindAllAsync(It.IsAny <CancellationToken>()))
            .Returns((CancellationToken ct) =>
            {
                if (counter++ == 2)
                {
                    return(Task.FromResult((ICollection <IKeyId>) new List <IKeyId> {
                        testKeyId
                    }));
                }
                return(Task.FromResult((ICollection <IKeyId>) new List <IKeyId>()));
            });

            var op = new MultiKeyOperation <int>(keyFactory.Object,
                                                 (keyId, ct) =>
            {
                Assert.AreEqual(testKeyId, keyId);
                return(Task.FromResult(42));
            },
                                                 i => i == 42,
                                                 TimeSpan.FromMilliseconds(100),
                                                 TimeSpan.FromMilliseconds(100));

            var token = new CancellationTokenSource(TimeSpan.FromSeconds(10));

            var result = await op.RunOperationAsync(token.Token);

            Assert.AreEqual(42, result);
        }
Exemplo n.º 3
0
 public Task<RegisterOperationResult> RegisterAsync(ICollection<KeyRegisterRequest> registerRequests, ICollection<KeySignRequest> signRequests,
     CancellationToken cancellationToken = new CancellationToken())
 {
     var signer = new MultiKeyOperation<RegisterOperationResult>(
         keyFactory,
         (keyId, ct) => new RegisterOperation(keyId, registerRequests).AuthenticateAsync(ct),
         r => r.IsSuccess
         );
     return signer.RunOperationAsync(cancellationToken);
 }
Exemplo n.º 4
0
 public Task<SignOperationResult> SignAsync(ICollection<KeySignRequest> requests, CancellationToken cancellationToken = new CancellationToken(),
     bool invididualAttestation = false)
 {
     var signer = new MultiKeyOperation<SignOperationResult>(
         keyFactory,
         (keyId, ct) => new SignOperation(keyId, requests).SignAsync(ct),
         r => r.IsSuccess
         );
     return signer.RunOperationAsync(cancellationToken);
 }
        public async Task CallOperationWithKey()
        {
            keyFactory
            .Setup(x => x.FindAllAsync(It.IsAny <CancellationToken>()))
            .ReturnsAsync(new List <IKeyId> {
                testKeyId
            });

            var op = new MultiKeyOperation <int>(keyFactory.Object,
                                                 (keyId, ct) =>
            {
                Assert.AreEqual(testKeyId, keyId);
                return(Task.FromResult(42));
            },
                                                 i => i == 42);

            var token = new CancellationTokenSource(TimeSpan.FromSeconds(30));

            var result = await op.RunOperationAsync(token.Token);

            Assert.AreEqual(42, result);
        }