示例#1
0
        public void TestStopImmediatelyAfterStart()
        {
            Mock <ILoggerProvider> logger = new Mock <ILoggerProvider>();
            TestJsonRpcSubscriptionBackgroundService service = new TestJsonRpcSubscriptionBackgroundService("nats://localhost:4222", "test", logger.Object
                                                                                                            , wrapper => { });

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            service.StartAsync(cancellationToken).GetAwaiter().GetResult();

            CancellationToken ct2 = new CancellationToken();

            service.StopAsync(ct2).GetAwaiter().GetResult();

            //Assert.IsNull(service.NatsConnection);

            Assert.IsFalse(ct2.IsCancellationRequested);
        }
示例#2
0
        public void TestStopThreeSecondsAfterStart()
        {
            Mock <ILoggerProvider> logger = new Mock <ILoggerProvider>();
            TestJsonRpcSubscriptionBackgroundService service = new TestJsonRpcSubscriptionBackgroundService("nats://localhost:4222", "test", logger.Object
                                                                                                            , wrapper => { });

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();
            CancellationToken       cancellationToken       = cancellationTokenSource.Token;

            service.StartAsync(cancellationToken).GetAwaiter().GetResult();

            Thread.Sleep(3000);

            CancellationToken ct2 = new CancellationToken();

            service.StopAsync(ct2).GetAwaiter().GetResult();

            //Assert.IsNotNull(service.NatsConnection);

            //Assert.IsTrue(service.NatsConnection.State.Equals(NATS.Client.ConnState.CLOSED));
            Assert.IsFalse(ct2.IsCancellationRequested);
        }