public void GetBindingData_IfComplexDataType_ReturnsBindingDataWithAllTypes()
        {
            // Arrange
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(ComplexDataType));

            // When JSON is a structured object, we can extract the fields as route parameters.
            string json  = @"{
""a"":1,
""b"":[1,2,3],
""c"":{}
}";
            object value = JsonConvert.DeserializeObject(json, typeof(ComplexDataType));

            // Act
            var bindingData = provider.GetBindingData(value);

            // Assert
            Assert.NotNull(bindingData);

            // Only take simple types
            Assert.Equal(3, bindingData.Count);
            Assert.Equal(1, bindingData["a"]);
            Assert.Equal(new int[] { 1, 2, 3 }, bindingData["b"]);
            Assert.Equal(new Dictionary <string, object>(), bindingData["c"]);
        }
        public void FromType_IfObjectParamType_ReturnsNull()
        {
            // Arrange && Act
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(object));

            // Assert
            Assert.Null(provider);
        }
 public CosmosDBTriggerBinding(ParameterInfo parameter, DocumentCollectionInfo documentCollectionLocation, DocumentCollectionInfo leaseCollectionLocation, ChangeFeedHostOptions leaseHostOptions)
 {
     _bindingDataProvider        = BindingDataProvider.FromType(parameter.ParameterType);
     _documentCollectionLocation = documentCollectionLocation;
     _leaseCollectionLocation    = leaseCollectionLocation;
     _leaseHostOptions           = leaseHostOptions;
     _parameter = parameter;
 }
        public void FromType_IfIntParamType_ReturnsNull()
        {
            // Simple type, not structured, doesn't produce any route parameters.
            // Arrange && Act
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(int));

            // Assert
            Assert.Null(provider);
        }
 public RedisTriggerBinding(ParameterInfo parameter, RedisAccount account, string channelOrKey, Mode mode, RedisConfiguration config, TraceWriter trace)
 {
     _parameter = parameter;
     _account = account;
     _channelOrKey = channelOrKey;
     _mode = mode;
     _config = config;
     _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
     _trace = trace;
 }
Example #6
0
 public RedisTriggerBinding(ParameterInfo parameter, RedisAccount account, string channelOrKey, Mode mode, RedisConfiguration config, TraceWriter trace)
 {
     _parameter           = parameter;
     _account             = account;
     _channelOrKey        = channelOrKey;
     _mode                = mode;
     _config              = config;
     _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
     _trace               = trace;
 }
            public ManualTriggerBinding(ParameterInfo parameter, bool isUserTypeBinding)
            {
                _parameter         = parameter;
                _isUserTypeBinding = isUserTypeBinding;

                if (_isUserTypeBinding)
                {
                    // Create the BindingDataProvider from the user Type. The BindingDataProvider
                    // is used to define the binding parameters that the binding exposes to other
                    // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                    // It is also used to extract the binding data from an instance of the Type.
                    _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
                }
            }
            public ManualTriggerBinding(ParameterInfo parameter, bool isUserTypeBinding)
            {
                _parameter = parameter;
                _isUserTypeBinding = isUserTypeBinding;

                if (_isUserTypeBinding)
                {
                    // Create the BindingDataProvider from the user Type. The BindingDataProvider
                    // is used to define the binding parameters that the binding exposes to other
                    // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                    // It is also used to extract the binding data from an instance of the Type.
                    _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
                }
            }
        public void FromType_IfStructuredDataType_ReturnsValidContract()
        {
            // Arrange && Act
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(NestedDataType));

            // Assert
            Assert.NotNull(provider);
            Assert.NotNull(provider.Contract);

            var names = provider.Contract.Keys.ToArray();

            Array.Sort(names);
            var expected = new string[] { "IntProp", "Nested", "StringProp" };

            Assert.Equal(expected, names);
        }
        public void GetBindingData_IfSimpleDataType_ReturnsValidBindingData()
        {
            // Arrange
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(SimpleDataType));

            // When JSON is a structured object, we can extract the fields as route parameters.
            string json  = @"{ ""Name"" : 12, ""other"" : 13 }";
            object value = JsonConvert.DeserializeObject(json, typeof(SimpleDataType));

            // Act
            var bindingData = provider.GetBindingData(value);

            // Assert
            Assert.NotNull(bindingData);
            Assert.Equal(1, bindingData.Count);
            Assert.Equal(12, bindingData["Name"]);
        }
            public HttpTriggerBinding(HttpTriggerAttribute attribute, ParameterInfo parameter, bool isUserTypeBinding, Action <HttpRequest, object> responseHook = null)
            {
                _responseHook      = responseHook;
                _parameter         = parameter;
                _isUserTypeBinding = isUserTypeBinding;

                if (_isUserTypeBinding)
                {
                    // Create the BindingDataProvider from the user Type. The BindingDataProvider
                    // is used to define the binding parameters that the binding exposes to other
                    // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                    // It is also used to extract the binding data from an instance of the Type.
                    _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
                }

                _bindingDataContract = GetBindingDataContract(attribute, parameter);
            }
        public PocoTriggerArgumentBinding(ITriggerBindingStrategy <TMessage, TTriggerValue> bindingStrategy, IConverterManager converterManager, Type elementType) :
            base(bindingStrategy, converterManager)
        {
            this.ElementType = elementType;

            // Add properties ot binding data. Null if type doesn't expose it.
            _provider = BindingDataProvider.FromType(elementType);
            if (_provider != null)
            {
                // Binding data from Poco properties takes precedence over builtins
                foreach (var kv in _provider.Contract)
                {
                    string name = kv.Key;
                    Type   type = kv.Value;
                    Contract[name] = type;
                }
            }
        }
Example #13
0
            public HttpTriggerBinding(HttpTriggerAttribute attribute, ParameterInfo parameter, bool isUserTypeBinding)
            {
                _parameter         = parameter;
                _isUserTypeBinding = isUserTypeBinding;

                Dictionary <string, Type> aggregateDataContract = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase);

                if (_isUserTypeBinding)
                {
                    // Create the BindingDataProvider from the user Type. The BindingDataProvider
                    // is used to define the binding parameters that the binding exposes to other
                    // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                    // It is also used to extract the binding data from an instance of the Type.
                    _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
                    if (_bindingDataProvider.Contract != null)
                    {
                        aggregateDataContract.AddRange(_bindingDataProvider.Contract);
                    }
                }

                // add any route parameters to the contract
                if (!string.IsNullOrEmpty(attribute.RouteTemplate))
                {
                    var routeParameters = _httpRouteFactory.GetRouteParameters(attribute.RouteTemplate);
                    var parameters      = ((MethodInfo)parameter.Member).GetParameters().ToDictionary(p => p.Name, p => p.ParameterType, StringComparer.OrdinalIgnoreCase);
                    foreach (string parameterName in routeParameters)
                    {
                        // don't override if the contract already includes a name
                        if (!aggregateDataContract.ContainsKey(parameterName))
                        {
                            // if there is a method parameter mapped to this parameter
                            // derive the Type from that
                            Type type;
                            if (!parameters.TryGetValue(parameterName, out type))
                            {
                                type = typeof(string);
                            }
                            aggregateDataContract[parameterName] = type;
                        }
                    }
                }

                _bindingDataContract = aggregateDataContract;
            }
        public WebHookTriggerBinding(WebHookDispatcher dispatcher, ParameterInfo parameter, bool isUserTypeBinding, WebHookTriggerAttribute attribute)
        {
            _dispatcher = dispatcher;
            _parameter = parameter;
            _isUserTypeBinding = isUserTypeBinding;
            _attribute = attribute;

            if (_isUserTypeBinding)
            {
                // Create the BindingDataProvider from the user Type. The BindingDataProvider
                // is used to define the binding parameters that the binding exposes to other
                // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                // It is also used to extract the binding data from an instance of the Type.
                _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
            }

            Uri baseAddress = new Uri(string.Format("http://localhost:{0}", dispatcher.Port));
            _route = FormatWebHookUri(baseAddress, attribute, parameter);
        }
            public HttpTriggerBinding(HttpTriggerAttribute attribute, ParameterInfo parameter, bool isUserTypeBinding)
            {
                _parameter = parameter;
                _isUserTypeBinding = isUserTypeBinding;

                Dictionary<string, Type> aggregateDataContract = new Dictionary<string, Type>(StringComparer.OrdinalIgnoreCase);
                if (_isUserTypeBinding)
                {
                    // Create the BindingDataProvider from the user Type. The BindingDataProvider
                    // is used to define the binding parameters that the binding exposes to other
                    // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                    // It is also used to extract the binding data from an instance of the Type.
                    _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
                    if (_bindingDataProvider.Contract != null)
                    {
                        aggregateDataContract.AddRange(_bindingDataProvider.Contract);
                    }
                }

                // add any route parameters to the contract
                if (!string.IsNullOrEmpty(attribute.RouteTemplate))
                {
                    var routeParameters = _httpRouteFactory.GetRouteParameters(attribute.RouteTemplate);
                    var parameters = ((MethodInfo)parameter.Member).GetParameters().ToDictionary(p => p.Name, p => p.ParameterType, StringComparer.OrdinalIgnoreCase);
                    foreach (string parameterName in routeParameters)
                    {
                        // don't override if the contract already includes a name
                        if (!aggregateDataContract.ContainsKey(parameterName))
                        {
                            // if there is a method parameter mapped to this parameter
                            // derive the Type from that
                            Type type;
                            if (!parameters.TryGetValue(parameterName, out type))
                            {
                                type = typeof(string);
                            }
                            aggregateDataContract[parameterName] = type;
                        }
                    }
                }

                _bindingDataContract = aggregateDataContract;
            }
        public void GetBindingData_WithDerivedValue_ReturnsValidBindingData()
        {
            // Arrange
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(Base));

            Derived value = new Derived {
                A = 1, B = 2
            };

            // Act
            var bindingData = provider.GetBindingData(value);

            // Assert
            Assert.NotNull(bindingData);

            // Get binding data for the type used when creating the provider
            Assert.Equal(1, bindingData.Count);
            Assert.Equal(1, bindingData["a"]);
        }
        public void GetBindingData_IfDateProperty_ReturnsValidBindingData()
        {
            // Arrange
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(DataTypeWithDateProperty));

            // Dates with JSON can be tricky. Test Date serialization.
            DateTime date = new DateTime(1950, 6, 1, 2, 3, 30);

            var    json  = JsonConvert.SerializeObject(new { date = date });
            object value = JsonConvert.DeserializeObject(json, typeof(DataTypeWithDateProperty));

            // Act
            var bindingData = provider.GetBindingData(value);

            // Assert
            Assert.NotNull(bindingData);
            Assert.Equal(1, bindingData.Count);
            Assert.Equal(date, bindingData["date"]);
        }
Example #18
0
        public WebHookTriggerBinding(WebHookDispatcher dispatcher, ParameterInfo parameter, bool isUserTypeBinding, WebHookTriggerAttribute attribute)
        {
            _dispatcher        = dispatcher;
            _parameter         = parameter;
            _isUserTypeBinding = isUserTypeBinding;
            _attribute         = attribute;

            if (_isUserTypeBinding)
            {
                // Create the BindingDataProvider from the user Type. The BindingDataProvider
                // is used to define the binding parameters that the binding exposes to other
                // bindings (i.e. the properties of the POCO can be bound to by other bindings).
                // It is also used to extract the binding data from an instance of the Type.
                _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
            }

            Uri baseAddress = new Uri(string.Format("http://localhost:{0}", dispatcher.Port));

            _route = FormatWebHookUri(baseAddress, attribute, parameter);
        }
 public UserTypeArgumentBinding(Type valueType)
 {
     _valueType           = valueType;
     _bindingDataProvider = BindingDataProvider.FromType(_valueType);
 }
 public UserTypeArgumentBinding(Type valueType, ILoggerFactory loggerFactory)
 {
     _valueType           = valueType;
     _bindingDataProvider = BindingDataProvider.FromType(_valueType);
     _loggerFactory       = loggerFactory;
 }
Example #21
0
 public UserTypeArgumentBinding()
 {
     _bindingDataProvider = BindingDataProvider.FromType(typeof(TInput));
 }