Пример #1
0
        public void TestConstructorDoesNotSetRequestIdIfResponseCallbackIsNull()
        {
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                null,
                                                null, //No callback specified
                                                1000.0);

            Assert.AreEqual(0, jetMethod.GetRequestId());
        }
Пример #2
0
        public void TestConstructorInitializesResponseTimeout()
        {
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                null,
                                                A.Dummy <Action <bool, JToken> >(),
                                                1337.42);

            Assert.AreEqual(1337.42, jetMethod.GetTimeoutMs());
        }
Пример #3
0
        public void TestConstructorInitializesTimer()
        {
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                null,
                                                A.Dummy <Action <bool, JToken> >(),
                                                1000.0);

            Assert.IsNotNull(jetMethod.RequestTimer as TimerAdapter, "ctor did not initialize a TimerAdapter.");
        }
Пример #4
0
        public void TestCallResponseCallbackInvokesActions()
        {
            Action <bool, JToken> responseCallback = A.Fake <Action <bool, JToken> >();
            JetMethod             jetMethod        = new JetMethod(JetMethod.Info, new JObject(), responseCallback, 1000.0);

            JToken token = JToken.FromObject(15);

            jetMethod.CallResponseCallback(true, token);
            jetMethod.CallResponseCallback(false, token);
            A.CallTo(() => responseCallback.Invoke(true, token)).MustHaveHappened(Repeated.Exactly.Once);
            A.CallTo(() => responseCallback.Invoke(false, token)).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #5
0
        public void TestConstructorIncreasesRequestIdIfResponseCallbackIsNotNull()
        {
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                null,
                                                A.Dummy <Action <bool, JToken> >(),
                                                1000.0);

            JetMethod nextJetMethod = new JetMethod(JetMethod.Info,
                                                    null,
                                                    A.Dummy <Action <bool, JToken> >(),
                                                    1000.0);

            Assert.AreEqual(1, nextJetMethod.GetRequestId() - jetMethod.GetRequestId());
        }
Пример #6
0
        public void TestHasResponseCallback()
        {
            JetMethod jetMethod1 = new JetMethod(JetMethod.Info,
                                                 new JObject(),
                                                 A.Dummy <Action <bool, JToken> >(),
                                                 1000.0);

            JetMethod jetMethod2 = new JetMethod(JetMethod.Info,
                                                 new JObject(),
                                                 null,
                                                 1000.0);

            Assert.IsTrue(jetMethod1.HasResponseCallback(), $"Expected {nameof(jetMethod1)} to have a response callback but received false.");
            Assert.IsFalse(jetMethod2.HasResponseCallback(), $"Expected {nameof(jetMethod2)} to not have a response callback but received true.");
        }
Пример #7
0
        public void TestDispose()
        {
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                new JObject(),
                                                A.Dummy <Action <bool, JToken> >(),
                                                1000.0);

            ITimer timer = A.Fake <ITimer>();

            jetMethod.RequestTimer = timer;
            jetMethod.Dispose();

            //Second call does nothing.
            jetMethod.Dispose();

            A.CallTo(() => timer.Dispose()).MustHaveHappened(Repeated.Exactly.Once);
        }
Пример #8
0
        public void TestConstructorInitializesJson()
        {
            JObject parameter = new JObject();

            parameter.Add("p1", JToken.FromObject(15));
            parameter.Add("p2", JToken.FromObject("hello world"));
            JetMethod jetMethod = new JetMethod(JetMethod.Info,
                                                parameter,
                                                A.Dummy <Action <bool, JToken> >(),
                                                1000.0);

            JObject json = jetMethod.GetJson();

            Assert.AreEqual((string)json["jsonrpc"], "2.0");
            Assert.AreEqual((string)json["method"], JetMethod.Info);
            Assert.AreEqual((int)json["params"]["p1"], 15);
            Assert.AreEqual((string)json["params"]["p2"], "hello world");
        }