Ejemplo n.º 1
0
        public void Test_BindModelAsync_UsesParserAndBinder()
        {
            var jsonRpcMethodOptions = new JsonRpcMethodOptions();
            var methodMetadata       = new MethodMetadata(jsonRpcMethodOptions, new JsonName("test", "test"), new JsonName("test", "test"));
            var parameterMetadata    = new ParameterMetadata(new JsonName("test", "test"), typeof(object), 0, BindingStyle.Default, false);

            methodMetadata.Add(parameterMetadata);
            var name = "test";
            var bindingContextMock = MockContext(methodMetadata: methodMetadata, name: name);
            var binder             = testEnvironment.ServiceProvider.GetRequiredService <JsonRpcModelBinder>();

            binder.BindModelAsync(bindingContextMock.Object).GetAwaiter().GetResult();

            Mock.Get(testEnvironment.ServiceProvider.GetService <IParamsParser>())
            .Verify(x => x.ParseParams(It.IsAny <JToken>(), parameterMetadata), Times.Once);
            Mock.Get(testEnvironment.ServiceProvider.GetService <IParameterBinder>())
            .Verify(x => x.SetResult(bindingContextMock.Object, It.IsAny <IParseResult>(), name, It.IsAny <JsonRpcBindingContext>()), Times.Once);
        }
Ejemplo n.º 2
0
        public void Test_GetRpcBindingContext_ThrowsOnNoSerializer()
        {
            var jsonRpcMethodOptions = new JsonRpcMethodOptions()
            {
                RequestSerializer = typeof(CamelCaseJsonRpcSerializer)
            };
            var methodMetadata = new MethodMetadata(jsonRpcMethodOptions, new JsonName("test", "test"), new JsonName("test", "test"));

            methodMetadata.Add(new ParameterMetadata(new JsonName("test", "test"), typeof(object), 0, BindingStyle.Default, false));
            var bindingContextMock = MockContext(methodMetadata: methodMetadata);
            var binder             = testEnvironment.ServiceProvider.GetRequiredService <JsonRpcModelBinder>();

            Action action = () => binder.GetRpcBindingContext(bindingContextMock.Object, "test");

            action.Should().Throw <InvalidOperationException>();
            bindingContextMock.VerifyGet(x => x.HttpContext);
            bindingContextMock.VerifyGet(x => x.ActionContext);
            bindingContextMock.VerifyGet(x => x.HttpContext.RequestServices);
        }
Ejemplo n.º 3
0
        public void Test_GetRpcBindingContext_ReturnsValue()
        {
            var jsonRpcMethodOptions = new JsonRpcMethodOptions();
            var methodMetadata       = new MethodMetadata(jsonRpcMethodOptions, new JsonName("test", "test"), new JsonName("test", "test"));
            var parameterMetadata    = new ParameterMetadata(new JsonName("test", "test"), typeof(object), 0, BindingStyle.Default, false);

            methodMetadata.Add(parameterMetadata);
            var bindingContextMock = MockContext(methodMetadata: methodMetadata);
            var binder             = testEnvironment.ServiceProvider.GetRequiredService <JsonRpcModelBinder>();

            var result = binder.GetRpcBindingContext(bindingContextMock.Object, "test");

            bindingContextMock.VerifyGet(x => x.HttpContext);
            bindingContextMock.VerifyGet(x => x.ActionContext);
            bindingContextMock.VerifyGet(x => x.HttpContext.RequestServices);
            result.Should().NotBeNull();
            result.Call.Should().Be(Mock.Get(result.Call).Object);
            result.ParameterMetadata.Should().Be(parameterMetadata);
            result.Serializer.Should().BeOfType(jsonRpcMethodOptions.RequestSerializer);
        }