Exemple #1
0
        public async Task When_NotConnected_ExecuteAsync_ReturnsTransportFailureException()
        {
            var mockConnection = new Mock <IConnection>();

            mockConnection.Setup(x => x.IsConnected).Returns(false);

            var mockConnectionPool = new Mock <IConnectionPool>();

            mockConnectionPool.Setup(x => x.Acquire()).Returns(mockConnection.Object);
            mockConnectionPool.SetupGet(x => x.Configuration).Returns(new PoolConfiguration {
                UseEnhancedDurability = false
            });

            var service = new MultiplexingIOService(mockConnectionPool.Object);
            await service.ExecuteAsync(new FakeOperationWithRequiredKey("key", null, new DefaultTranscoder(), 0)
            {
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
                Completed = async s =>
                {
                    Assert.AreEqual(s.Status, ResponseStatus.TransportFailure);
                    Assert.IsInstanceOf <TransportFailureException>(s.Exception);
                }
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
            });
        }
        public async Task When_TransportFailure_Occurs_CheckConfigUpdate_Is_Called_For_ExecuteAsync_T()
        {
            var mockConnection = new Mock <IConnection>();

            mockConnection.Setup(x => x.IsConnected).Returns(false);

            var mockConnectionPool = new Mock <IConnectionPool>();

            mockConnectionPool.Setup(x => x.Acquire()).Returns(mockConnection.Object);
            mockConnectionPool.SetupGet(x => x.Configuration).Returns(new PoolConfiguration {
                UseEnhancedDurability = false
            });

            var service = new MultiplexingIOService(mockConnectionPool.Object);

            var mockOperation = new Mock <IOperation <string> >();

            mockOperation.Setup(x => x.Opaque).Returns(1);
            mockOperation.Setup(x => x.Exception).Returns(new TransportFailureException());

            var opqueue = new ConcurrentDictionary <uint, IOperation>();

            opqueue.TryAdd(mockOperation.Object.Opaque, mockOperation.Object);

            var mockController = new Mock <IClusterController>();

            mockController.Setup(x => x.CheckConfigUpdate(It.IsAny <string>(), It.IsAny <IPEndPoint>())).Verifiable();

            TaskCompletionSource <IOperationResult <string> > tcs = new TaskCompletionSource <IOperationResult <string> >();

            mockOperation.Setup(x => x.Completed)
            .Returns(CallbackFactory.CompletedFuncWithRetryForCouchbase <string>(null, opqueue, mockController.Object, tcs,
                                                                                 new CancellationToken()));

            await service.ExecuteAsync(mockOperation.Object);

            mockController.VerifyAll();
        }