public async Task StopConcurrentMethodRunnerQueueWhenMethodRunning()
        {
            var boundObject = new AsyncBoundObject();

            var objectRepository = new JavascriptObjectRepository();

            objectRepository.NameConverter = null;
#if NETCOREAPP
            objectRepository.Register("testObject", boundObject, BindingOptions.DefaultBinder);
#else
            objectRepository.Register("testObject", boundObject, true, BindingOptions.DefaultBinder);
#endif
            var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);
            methodInvocation.Parameters.Add("Echo Me!");
            var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);

            methodRunnerQueue.Enqueue(methodInvocation);

            //Wait a litle for the queue to start processing our Method call
            await Task.Delay(500);

            var ex = Record.Exception(() => methodRunnerQueue.Dispose());

            Assert.Null(ex);
        }
        public void ValidateAsyncTaskMethodOutput()
        {
            const string expectedResult = "Echo Me!";
            var          boundObject    = new AsyncBoundObject();

            var objectRepository = new JavascriptObjectRepository();

            objectRepository.Register("testObject", boundObject, true, new BindingOptions {
                CamelCaseJavascriptNames = false
            });
            var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);

            methodInvocation.Parameters.Add(expectedResult);
            var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);
            var manualResetEvent  = new ManualResetEvent(false);

            var actualResult = "";

            methodRunnerQueue.MethodInvocationComplete += (sender, args) =>
            {
                methodRunnerQueue.Stop();

                actualResult = args.Result.Result.ToString();

                manualResetEvent.Set();
            };

            methodRunnerQueue.Start();
            methodRunnerQueue.Enqueue(methodInvocation);

            manualResetEvent.WaitOne(3000);

            Assert.Equal(expectedResult, actualResult);
        }
Exemplo n.º 3
0
        public void DisposeConcurrentMethodRunnerQueueThenEnqueueInvocation()
        {
            var methodInvocation = new MethodInvocation(1, 1, 1, "Testing", 1);

            methodInvocation.Parameters.Add("Echo Me!");

            var objectRepository = new JavascriptObjectRepository
            {
                NameConverter = null
            };

            var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);

            //Dispose
            methodRunnerQueue.Dispose();

            //Enqueue
            var ex = Record.Exception(() => methodRunnerQueue.Enqueue(methodInvocation));

            //Ensure no exception thrown
            Assert.Null(ex);
        }
        public async Task ValidateAsyncTaskMethodOutput()
        {
            const string expectedResult = "Echo Me!";
            var          boundObject    = new AsyncBoundObject();

            var objectRepository = new JavascriptObjectRepository();

            objectRepository.NameConverter = null;
#if NETCOREAPP
            objectRepository.Register("testObject", boundObject, BindingOptions.DefaultBinder);
#else
            objectRepository.Register("testObject", boundObject, true, BindingOptions.DefaultBinder);
#endif
            var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);
            methodInvocation.Parameters.Add(expectedResult);
            var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);
            var manualResetEvent  = new AsyncManualResetEvent();
            var cancellationToken = new CancellationTokenSource();

            cancellationToken.CancelAfter(5000);

            var actualResult = "";

            methodRunnerQueue.MethodInvocationComplete += (sender, args) =>
            {
                actualResult = args.Result.Result.ToString();

                manualResetEvent.Set();
            };

            methodRunnerQueue.Enqueue(methodInvocation);

            await manualResetEvent.WaitAsync(cancellationToken.Token);

            Assert.Equal(expectedResult, actualResult);

            methodRunnerQueue.Dispose();
        }
        public async Task StopConcurrentMethodRunnerQueueWhenMethodRunning()
        {
            var boundObject = new AsyncBoundObject();

            var objectRepository = new JavascriptObjectRepository();

            objectRepository.Register("testObject", boundObject, true, new BindingOptions {
                CamelCaseJavascriptNames = false
            });
            var methodInvocation = new MethodInvocation(1, 1, 1, nameof(boundObject.AsyncWaitTwoSeconds), 1);

            methodInvocation.Parameters.Add("Echo Me!");
            var methodRunnerQueue = new ConcurrentMethodRunnerQueue(objectRepository);

            methodRunnerQueue.Start();
            methodRunnerQueue.Enqueue(methodInvocation);

            //Wait a litle for the queue to start processing our Method call
            await Task.Delay(500);

            var ex = Record.Exception(() => methodRunnerQueue.Stop());

            Assert.Null(ex);
        }