Esempio n. 1
0
        public void TestSubscriptionPublishing()
        {
            Mock <ILoggerProvider> logger = new Mock <ILoggerProvider>();

            ///this background service is subscribe only
            TestJsonRpcSubscriptionBackgroundService service = new TestJsonRpcSubscriptionBackgroundService("nats://localhost:4222", "test", logger.Object
                                                                                                            , wrapper => {
                var proxy = new TestProxy();
                wrapper.RegisterMethod("testsubject", p => proxy.TestMethod(p));
            });

            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            CancellationToken cancellationToken = cancellationTokenSource.Token;

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

            Thread.Sleep(3000);

            DummyObject obj = new DummyObject()
            {
                Message = "Hello world!"
            };

            //service.NatsConnection.Publish("testsubject", Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(obj)));
        }
Esempio n. 2
0
        public void TestStart()
        {
            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();

            System.Threading.Thread.Sleep(1000);

            //Assert.IsTrue(service.NatsConnection.State.Equals(NATS.Client.ConnState.CONNECTED));

            Assert.IsFalse(cancellationToken.IsCancellationRequested);
        }
Esempio n. 3
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);
        }