Esempio n. 1
0
        public void Test_SetId_SetsIfRequest()
        {
            var request = new UntypedRequest()
            {
                RawId = JValue.CreateString("test")
            };
            var value = new JObject();

            new JsonServerResponseWrapper(value, request, null);

            value.Should().ContainKey(JsonRpcConstants.IdProperty);
            Assert.AreEqual(request.RawId, value[JsonRpcConstants.IdProperty]);
        }
        public async Task Test_HandleBatch_ThrowsOnUnknown()
        {
            var request = new UntypedRequest();
            var batch   = new BatchRequestWrapper
            {
                Batch = new List <IUntypedCall>()
                {
                    request
                }
            };
            var         handlingContext = new HandlingContext(Mock.Of <HttpContext>(), Mock.Of <Encoding>(), Mock.Of <RequestDelegate>());
            Func <Task> action          = async() => await requestHandlerMock.Object.HandleBatch(batch, (BatchHandling)(-1), handlingContext);

            await action.Should().ThrowAsync <ArgumentOutOfRangeException>();

            requestHandlerMock.Verify(x => x.HandleBatch(It.IsAny <BatchRequestWrapper>(), It.IsAny <BatchHandling>(), It.IsAny <HandlingContext>()));
        }
        public async Task Test_HandleBatch_CallsSequential()
        {
            var request = new UntypedRequest();
            var value   = new JArray();
            var batch   = new BatchRequestWrapper
            {
                Batch = new List <IUntypedCall>()
                {
                    request
                }
            };

            var handlingContext = new HandlingContext(Mock.Of <HttpContext>(), Mock.Of <Encoding>(), Mock.Of <RequestDelegate>());

            requestHandlerMock.Setup(x => x.HandleBatchSequential(It.IsAny <BatchRequestWrapper>(), It.IsAny <HandlingContext>()))
            .ReturnsAsync(value);

            var result = await requestHandlerMock.Object.HandleBatch(batch, BatchHandling.Sequential, handlingContext);

            result.Should().BeOfType <JsonServerResponseWrapper>();
            Assert.AreEqual(value, (result as JsonServerResponseWrapper).Value);
            requestHandlerMock.Verify(x => x.HandleBatch(It.IsAny <BatchRequestWrapper>(), BatchHandling.Sequential, It.IsAny <HandlingContext>()));
            requestHandlerMock.Verify(x => x.HandleBatchSequential(It.IsAny <BatchRequestWrapper>(), It.IsAny <HandlingContext>()));
        }
Esempio n. 4
0
        public void Test_UntypedRequest_HasDefaultVersion()
        {
            var value = new UntypedRequest();

            value.Jsonrpc.Should().Be(JsonRpcConstants.Version);
        }