コード例 #1
0
        public void StartObserver_Update_DoesNotUpdateBotCommandStrategy(string observerTestBotCommand)
        {
            // Arrange
            IBotStrategy expectedBotCommandStrategy = null;

            // Initialize test CommandStrategy for NowObserver
            var startCommand = new ObserverTestCommand
            {
                CommandType = CommandType.Start
            };

            IEnumerable <ICommand> commands = new List <ICommand>()
            {
                startCommand
            };
            var commandStrategy = new BotStrategy(commands);

            // Initialize the test bot
            var startObserver = new StartObserver(commandStrategy);
            var testBot       = new ObserverTestBot(observerTestBotCommand, startObserver);

            // Act
            testBot.Run();
            var actualBotCommandStrategy = testBot.Strategy;

            //Assert
            Assert.AreEqual(actualBotCommandStrategy, expectedBotCommandStrategy);
        }
コード例 #2
0
        public ReceiveEndpoint(IReceiveTransport transport, ReceiveEndpointContext context)
        {
            _context   = context;
            _transport = transport;

            _started = Util.TaskUtil.GetTask <ReceiveEndpointReady>();

            _startObserver = new StartObserver();

            ConnectReceiveEndpointObserver(_startObserver);

            transport.ConnectReceiveTransportObserver(new Observer(this, context.EndpointObservers));
        }
コード例 #3
0
        public void StartObserver_Update_UpdatesBotCommandStrategy()
        {
            // Arrange
            var expectedCommandStrategyIsNull = false;
            var expectedCommandType           = CommandType.Start;

            // Initialize test CommandStrategy for NowObserver
            var testStartCommand = new ObserverTestCommand
            {
                CommandType = CommandType.Start
            };

            IEnumerable <ICommand> commands = new List <ICommand>()
            {
                testStartCommand
            };
            var commandStrategy = new BotStrategy(commands);

            // Initialize the test bot
            var startObserver = new StartObserver(commandStrategy);
            var testBot       = new ObserverTestBot("/START", startObserver);

            // Act
            testBot.Run();
            var actualCommandStrategyIsNull = testBot.Strategy == null;

            CommandType?actualCommandType = null;

            if (actualCommandStrategyIsNull == false)
            {
                actualCommandType = testBot.Strategy.CommandType;
            }

            //Assert
            Assert.AreEqual(actualCommandStrategyIsNull, expectedCommandStrategyIsNull);

            if (actualCommandStrategyIsNull == false)
            {
                Assert.AreEqual(actualCommandType, expectedCommandType);
            }
        }
コード例 #4
0
            public EndpointHandle(ReceiveEndpoint endpoint, IReceiveTransport transport, StartObserver startObserver, CancellationToken cancellationToken)
            {
                _endpoint  = endpoint;
                _transport = transport;

                _cancellationToken = cancellationToken;
                _ready             = Util.TaskUtil.GetTask <ReceiveEndpointReady>();

                if (cancellationToken.CanBeCanceled)
                {
                    _registration = cancellationToken.Register(() =>
                    {
                        if (_faulted != null)
                        {
                            _handle?.Disconnect();
                            _ready.TrySetException(_faulted.Exception);
                        }

                        _registration.Dispose();
                    });
                }

                _handle = startObserver.ConnectEndpointHandle(this);
            }