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); }
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)); }
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); } }
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); }