Ejemplo n.º 1
0
        public void BeforeCallIgnoreTokenNone()
        {
            var token = new CancellationTokenProxy(CancellationToken.None);

            var operation = _sut.BeforeCall("x", token);

            Assert.IsNull(operation);
        }
Ejemplo n.º 2
0
        public async Task <OperationResult> RunOperationAsync(TimeSpan delay, CancellationTokenProxy token)
        {
            var timer = Stopwatch.StartNew();

            try
            {
                await Task.Delay(delay, token).ConfigureAwait(false);
            }
            catch (TaskCanceledException ex) when(ex.CancellationToken == token)
            {
            }

            return(new OperationResult
            {
                ExecutionTime = timer.Elapsed,
                IsCanceled = token.IsCancellationRequested
            });
        }
Ejemplo n.º 3
0
        public void BeforeCallFixExpectedType()
        {
            using (var source = new CancellationTokenSource())
            {
                var token  = new CancellationTokenProxy(source.Token);
                var inputs = new object[] { token };

                _manager
                .Setup(m => m.BeforeCall(_operation.FullName, token))
                .Returns((OperationInfo)null);

                var actual = _sut.BeforeCall(_operationName, inputs);

                _manager.VerifyAll();

                Assert.IsNull(actual);
                Assert.AreEqual(token, inputs[0]);
            }
        }
Ejemplo n.º 4
0
        public void BeforeCallBeginOperation()
        {
            var operationId = Guid.NewGuid().ToString();
            var token       = new CancellationTokenProxy(CancellationToken.None).NewOperationId(operationId);

            using (var source = new CancellationTokenSource())
            {
                _manager
                .Setup(m => m.BeginOperation(operationId))
                .Returns(source.Token);

                var operation = _sut.BeforeCall("x", token);

                _manager.VerifyAll();

                Assert.IsNotNull(operation);
                Assert.AreEqual(operationId, operation.Token.OperationId);
                Assert.AreEqual(source.Token, operation.Token.Token);
            }
        }
Ejemplo n.º 5
0
        public void BeforeCallChangeToken()
        {
            using (var source = new CancellationTokenSource())
            {
                var token    = new CancellationTokenProxy(source.Token);
                var inputs   = new object[1];
                var expected = new OperationInfo {
                    Token = token
                };

                _manager
                .Setup(m => m.BeforeCall(_operation.FullName, null))
                .Returns(expected);

                var actual = _sut.BeforeCall(_operationName, inputs);

                _manager.VerifyAll();

                Assert.AreEqual(expected, actual);
                Assert.AreEqual(token, inputs[0]);
            }
        }
Ejemplo n.º 6
0
        public void BeforeCallPassTokenIntoChannel()
        {
            using (var sourceInput = new CancellationTokenSource())
                using (var sourceOutput = new CancellationTokenSource())
                {
                    var inputToken  = new CancellationTokenProxy(sourceInput.Token);
                    var outputToken = new CancellationTokenProxy(sourceOutput.Token);

                    var inputs  = new object[] { inputToken };
                    var outputs = new OperationInfo {
                        Token = outputToken
                    };

                    _operationManager
                    .Setup(m => m.BeforeCall(_operation.FullName, inputToken))
                    .Returns(outputs);

                    var actual = (OperationInfo)_sut.BeforeCall(_operationName, inputs);

                    _operationManager.VerifyAll();
                    Assert.AreEqual(outputs, actual);
                    Assert.AreEqual(outputToken, inputs[0]);
                }
        }