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 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_IfObjectParamType_ReturnsNull()
        {
            // Arrange && Act
            IBindingDataProvider provider = BindingDataProvider.FromType(typeof(object));

            // Assert
            Assert.Null(provider);
        }
Beispiel #4
0
 public RedisTriggerBinding(RedisConfiguration configuration, ParameterInfo parameter, IRedisAttribute attribute)
 {
     _configuration = configuration;
     _parameter = parameter;
     _attribute = attribute;
     //_bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.ChannelOrKey); // ?? {Id} ??
     _bindingDataProvider = BindingDataProvider.FromType(parameter.ParameterType);
 }
Beispiel #5
0
 public FileTriggerBinding(FilesConfiguration config, ParameterInfo parameter, TraceWriter trace)
 {
     _config              = config;
     _parameter           = parameter;
     _trace               = trace;
     _attribute           = parameter.GetCustomAttribute <FileTriggerAttribute>(inherit: false);
     _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path);
     _bindingContract     = CreateBindingContract();
 }
        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 void FromType_DuplicatePropertiesDetected_Throws()
        {
            var ex = Assert.Throws <InvalidOperationException>(() =>
            {
                BindingDataProvider.FromType(typeof(DerivedWithNew));
            });

            Assert.Equal("Multiple properties named 'A' found in type 'DerivedWithNew'.", ex.Message);
        }
 public SimpleMessageBusFileTriggerBinding(IOptions <FileSystemOptions> options, ParameterInfo parameter, ILogger logger, ISimpleMessageBusFileProcessorFactory fileProcessorFactory)
 {
     _options              = options;
     _parameter            = parameter;
     _logger               = logger;
     _fileProcessorFactory = fileProcessorFactory;
     _attribute            = parameter.GetCustomAttribute <SimpleMessageBusFileTriggerAttribute>(inherit: false);
     _bindingDataProvider  = BindingDataProvider.FromTemplate(_attribute.Path);
     _bindingContract      = CreateBindingContract();
 }
Beispiel #9
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 GenericTriggerbinding(
                ParameterInfo parameter,
                TAttribute attribute,
                TraceWriter trace,
                GenericFileTriggerBindingProvider <TAttribute, TFile> parent)
            {
                this._parameter = parameter;
                this._attribute = attribute;
                this._parent    = parent;
                this._trace     = trace;

                _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path);
                _bindingContract     = CreateBindingContract();
            }
            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 FromTemplate_CreatesCaseSensitiveProvider()
        {
            var provider = BindingDataProvider.FromTemplate(@"A/b/{c}");

            var data = provider.GetBindingData("A/b/Test");

            Assert.Equal(1, data.Count);
            Assert.Equal("Test", data["c"]);

            // Don't expect a match here, since templates are case sensitive
            // by default
            data = provider.GetBindingData("a/b/Test");
            Assert.Null(data);
        }
        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 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 void FromTemplate_IgnoreCase_CreatesCaseInsensitiveProvider()
        {
            var provider = BindingDataProvider.FromTemplate(@"A/b/{c}", ignoreCase: true);

            var data = provider.GetBindingData("A/b/Test");

            Assert.Equal(1, data.Count);
            Assert.Equal("Test", data["c"]);

            data = provider.GetBindingData("a/b/Test");
            Assert.Equal(1, data.Count);
            Assert.Equal("Test", data["c"]);

            data = provider.GetBindingData("A/B/Test");
            Assert.Equal(1, data.Count);
            Assert.Equal("Test", data["c"]);
        }
        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 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;
                }
            }
        }
Beispiel #18
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 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"]);
        }
Beispiel #21
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);
        }
Beispiel #22
0
            public GenericTriggerbinding(
                JobHostConfiguration config,
                ParameterInfo parameter,
                TAttribute attribute,
                TraceWriter trace,
                GenericFileTriggerBindingProvider <TAttribute, TFile> parent)
            {
                this._config    = config;
                this._parameter = parameter;
                this._attribute = attribute;
                this._parent    = parent;
                this._trace     = trace;

                MethodInfo methodInfo = (MethodInfo)parameter.Member;

                _functionName = methodInfo.Name;

                _bindingDataProvider = BindingDataProvider.FromTemplate(_attribute.Path.TrimStart('/'), ignoreCase: true);
                _bindingContract     = CreateBindingContract();
            }
        public void SetBindingData(Type contractType, object value)
        {
            var provider = BindingDataProvider.FromType(contractType);

            _bindingData = provider.GetBindingData(value);
        }
 public UserTypeArgumentBinding(Type valueType, ILoggerFactory loggerFactory)
 {
     _valueType           = valueType;
     _bindingDataProvider = BindingDataProvider.FromType(_valueType);
     _loggerFactory       = loggerFactory;
 }
 public UserTypeArgumentBinding(Type valueType)
 {
     _valueType           = valueType;
     _bindingDataProvider = BindingDataProvider.FromType(_valueType);
 }
Beispiel #26
0
 public UserTypeArgumentBinding()
 {
     _bindingDataProvider = BindingDataProvider.FromType(typeof(TInput));
 }