public async Task ShouldCallTheRestartService( bool resume, [Frozen, Substitute] IGatewayRestartService restartService, [Target] DefaultGatewayService gateway ) { var cancellationToken = new CancellationToken(false); await gateway.Restart(resume, cancellationToken); await restartService.Received().Restart(Is(gateway), Is(resume), Is(cancellationToken)); }
public async Task StartShouldSetupGatewayToRestartOnUnexpectedStops( [Frozen, Substitute] IGatewayRestartService restartService, [Frozen, Substitute] ITimer worker, [Target] DefaultGatewayService gateway ) { var cancellationToken = new CancellationToken(false); await gateway.StartAsync(); worker.Received().StopOnException = Is(true); worker.Received().OnUnexpectedStop = Any <OnUnexpectedTimerStop>(); var arg = (from call in worker.ReceivedCalls() where call.GetMethodInfo().Name.Contains(nameof(worker.OnUnexpectedStop)) select(OnUnexpectedTimerStop) call.GetArguments()[0]).First(); await arg(); await restartService.Received().Restart(Is(gateway), Is(true), Any <CancellationToken>()); }
/// <summary> /// Initializes a new instance of the <see cref="DefaultGatewayService" /> class. /// </summary> /// <param name="rxWorker">The worker to use for receiving message chunks and parsing messages.</param> /// <param name="txWorker">The worker to use for sending messages to the gateway.</param> /// <param name="timerFactory">Factory to create timers with.</param> /// <param name="restartService">Service used to restart the gateway.</param> /// <param name="gatewayUtilsFactory">Factory to create various utils with.</param> /// <param name="options">Options to use for interacting with the gateway.</param> /// <param name="logger">Logger used to log information to some destination(s).</param> public DefaultGatewayService( IGatewayRxWorker rxWorker, IGatewayTxWorker txWorker, ITimerFactory timerFactory, IGatewayRestartService restartService, IGatewayUtilsFactory gatewayUtilsFactory, IOptions <GatewayOptions> options, ILogger <DefaultGatewayService> logger ) { this.rxWorker = rxWorker; this.txWorker = txWorker; this.timerFactory = timerFactory; this.restartService = restartService; this.gatewayUtilsFactory = gatewayUtilsFactory; this.options = options.Value; this.logger = logger; buffer = new byte[this.options.BufferSize]; memoryBuffer = new Memory <byte>(buffer); }