Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new BindingTarget when the method binding has failued due to
 /// one or more parameters which could not be converted.
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, CallFailure[] failures)
 {
     _name         = name;
     _result       = BindingResult.CallFailure;
     _callFailures = failures;
     _actualArgs   = actualArgumentCount;
 }
Ejemplo n.º 2
0
            public BindingContext(MethodInfo method)
            {
                Method = method;

                Parameters = method.GetParameters().Select(p => new BindingParameter(p)).ToList();
                Result     = new BindingResult(method.ReturnParameter);
            }
 void given_operation_property(Func <IOperationAsync, bool> predicate, string propertyName, string propertyValue)
 {
     Operations.First(predicate).Inputs.First().Binder.SetProperty(
         propertyName,
         new object[] { propertyValue },
         (v, t) => BindingResult.Success(v));
 }
Ejemplo n.º 4
0
        private ImmutableArray <Diagnostic> GetDiagnostics(BindingResult bindingResult)
        {
            var syntaxDiagnostics   = SyntaxTree.GetDiagnostics();
            var semanticDiagnostics = bindingResult.Diagnostics;

            return(syntaxDiagnostics.Concat(semanticDiagnostics).ToImmutableArray());
        }
        protected override void When()
        {
            var binder = BinderCollection.FindBinderFor("json", typeof(Json), this.Request, new RouteValues(), null);

            this.bindingResult = binder.Bind("json", typeof(Json), this.Request, new RouteValues(), false, null);
            this.target        = (Json)bindingResult.Object;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Creates a new BindingTarget when the method binding has failed due to an incorrect argument count
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, int[] expectedArgCount)
 {
     _name = name;
     _result = BindingResult.IncorrectArgumentCount;
     _expectedArgs = expectedArgCount;
     _actualArgs = actualArgumentCount;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Creates a new BindingTarget when the match was ambiguous
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, MethodTarget[] ambiguousMatches)
 {
     _name             = name;
     _result           = BindingResult.AmbiguousMatch;
     _ambiguousMatches = ambiguousMatches;
     _actualArgs       = actualArgumentCount;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new BindingTarget when the method binding has failed due to an incorrect argument count
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, int[] expectedArgCount)
 {
     _name         = name;
     _result       = BindingResult.IncorrectArgumentCount;
     _expectedArgs = expectedArgCount;
     _actualArgs   = actualArgumentCount;
 }
Ejemplo n.º 9
0
        public void Produces_correct_result_for_nullable_right_operand(Tuple <int, int?> graph)
        {
            var expected = BindingResult.Some(graph.Item1 != graph.Item2);

            var actual = Binding.Create((Tuple <int, int?> x) => x.Item1 != x.Item2);

            AssertEx.Bind(graph, expected, actual);
        }
Ejemplo n.º 10
0
        public void Produces_correct_result_for_non_nullable_operand(Tuple <bool> graph)
        {
            var expected = BindingResult.Some(!graph.Item1);

            var actual = Binding.Create((Tuple <bool> x) => !x.Item1);

            AssertEx.Bind(graph, expected, actual);
        }
        public void Produces_correct_result_for_nullable_operands(Tuple <bool?, bool?> graph)
        {
            var expected = BindingResult.Some(graph.Item1 ^ graph.Item2);

            var actual = Binding.Create((Tuple <bool?, bool?> x) => x.Item1 ^ x.Item2);

            AssertEx.Bind(graph, expected, actual);
        }
        public void Produces_none_when_object_of_member_of_nullable_object_in_the_expression_is_null()
        {
            var graph    = new Person();
            var expected = BindingResult.None <int>();

            var actual = Binding.Create((Person x) => x.Age.Value);

            AssertEx.Bind(graph, expected, actual);
        }
Ejemplo n.º 13
0
        public void the_object_is_created_with_the_correct_properties()
        {
            var binder = new KeyedValuesBinder(TypeOf <Customer>(), "customer");

            binder.SetProperty("username", new[] { "johndoe" }, (str, type) => BindingResult.Success(str));
            var customer = (Customer)binder.BuildObject().Instance;

            customer.Username.ShouldBe("johndoe");
        }
Ejemplo n.º 14
0
        public void the_same_object_is_returned_when_building_twice_without_changes()
        {
            var binder = new KeyedValuesBinder(TypeOf <Customer>(), "customer");

            binder.SetProperty("username", new[] { "johndoe" }, (str, type) => BindingResult.Success(str));
            var customer  = (Customer)binder.BuildObject().Instance;
            var customer2 = (Customer)binder.BuildObject().Instance;

            customer.ShouldBeSameAs(customer2);
        }
Ejemplo n.º 15
0
 public static object CreateInstanceFrom(this Type type, string[] propertyValues)
 {
     return(CreateInstanceFrom(type,
                               propertyValues,
                               (str, destinationType) =>
     {
         var destination = CreateInstanceFrom(destinationType, str);
         return BindingResult.Success(destination);
     }));
 }
Ejemplo n.º 16
0
        public void the_property_is_assigned_even_when_the_prefix_has_the_same_name()
        {
            var binder = new KeyedValuesBinder(TypeOf <Customer>(), "firstname");
            ValueConverter <string> valueConverter = (str, type) => BindingResult.Success(type.CreateInstanceFrom(str));

            binder.SetProperty("firstName", new[] { "Smeagol" }, valueConverter).ShouldBeTrue();

            binder.BuildObject().Instance.ShouldBeAssignableTo <Customer>()
            .FirstName.ShouldBe("Smeagol");
        }
Ejemplo n.º 17
0
        public static void Bind <TGraph, TResult>(TGraph graph, BindingResult <TResult> expected, IRootBinding <TGraph, TResult> actual)
        {
            None(actual);

            actual.Bind(graph);
            Some(expected, actual);

            actual.Unbind();
            None(actual);
        }
Ejemplo n.º 18
0
 protected static BindingResult ConvertValuesByString(string strings, Type entityType)
 {
     try
     {
         return(BindingResult.Success(entityType.CreateInstanceFrom(strings)));
     }
     catch (NotSupportedException)
     {
         return(BindingResult.Failure());
     }
 }
Ejemplo n.º 19
0
        public void Produces_correct_result_for_operand_whose_result_maybe_none(Tuple <bool?> single)
        {
            var graph = Tuple.Create(
                single.Item1 != null ? Tuple.Create(single.Item1.Value) : null);

            var expected = BindingResult.FromNullable(!graph.Item1?.Item1);

            var actual = Binding.Create((Tuple <Tuple <bool> > x) => !x.Item1.Item1);

            AssertEx.Bind(graph, expected, actual);
        }
Ejemplo n.º 20
0
        public void Produces_correct_result_for_left_operand_whose_result_maybe_none(Tuple <int?, int> pair)
        {
            var graph = Tuple.Create(
                pair.Item1 != null ? Tuple.Create(pair.Item1.Value) : null,
                pair.Item2);

            var expected = BindingResult.Some(graph.Item1?.Item1 > graph.Item2);

            var actual = Binding.Create((Tuple <Tuple <int>, int> x) => x.Item1.Item1 > x.Item2);

            AssertEx.Bind(graph, expected, actual);
        }
Ejemplo n.º 21
0
 private void executeBinding(ref Binding binding)
 {
     if (bindingCore != null && !string.IsNullOrEmpty(binding.path))
     {
         BindingResult result = bindingCore.executeBinding(ref binding);
         if (result.error != BindingError.Success)
         {
             Debug.LogError("[DialogueController] An error was encountered while trying to resolve a binding!" +
                            "\nError type: " + result.error.ToString() + "\t - Binding: " + binding.ToString());
         }
     }
 }
Ejemplo n.º 22
0
        public void Produces_correct_result_for_right_operand_whose_result_maybe_none(Tuple <int, int?> pair)
        {
            var graph = Tuple.Create(
                pair.Item1,
                pair.Item2 != null ? Tuple.Create(pair.Item2.Value) : null);

            var expected = BindingResult.Some(graph.Item1 != graph.Item2?.Item1);

            var actual = Binding.Create((Tuple <int, Tuple <int> > x) => x.Item1 != x.Item2.Item1);

            AssertEx.Bind(graph, expected, actual);
        }
        public void Produces_correct_result_for_operands_whose_results_maybe_none(Tuple <bool?, bool?> pair)
        {
            var graph = Tuple.Create(
                pair.Item1 != null ? Tuple.Create(pair.Item1.Value) : null,
                pair.Item2 != null ? Tuple.Create(pair.Item2.Value) : null);

            var expected = BindingResult.FromNullable(graph.Item1?.Item1 ^ graph.Item2?.Item1);

            var actual = Binding.Create((Tuple <Tuple <bool>, Tuple <bool> > x) => x.Item1.Item1 ^ x.Item2.Item1);

            AssertEx.Bind(graph, expected, actual);
        }
Ejemplo n.º 24
0
        public void a_change_after_a_creation_results_in_a_new_oject_with_the_same_properties()
        {
            var binder = new KeyedValuesBinder(TypeOf <Customer>(), "customer");

            binder.SetProperty("username", new[] { "johndoe" }, (str, type) => BindingResult.Success(str));
            binder.BuildObject();

            binder.SetProperty("firstname", new[] { "john" }, (str, type) => BindingResult.Success(str));
            var customer = (Customer)binder.BuildObject().Instance;

            customer.Username.ShouldBe("johndoe");
            customer.FirstName.ShouldBe("john");
        }
Ejemplo n.º 25
0
        public void multiple_values_with_the_same_name_for_an_icollection_appends_to_the_collection()
        {
            var binder = new KeyedValuesBinder(TypeOf <Customer>(), "firstname");
            ValueConverter <string> valueConverter = (str, type) => BindingResult.Success(type.CreateInstanceFrom(str));

            binder.SetProperty("Attributes", new[] { "blue eyes" }, valueConverter).ShouldBeTrue();
            binder.SetProperty("Attributes", new[] { "green eyes" }, valueConverter).ShouldBeTrue();

            var customer = binder.BuildObject().Instance as Customer;

            customer.Attributes.Count().ShouldBe(2);
            customer.Attributes.First().ShouldBe("blue eyes");
            customer.Attributes.Skip(1).First().ShouldBe("green eyes");
        }
Ejemplo n.º 26
0
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                // Evaluate the binding path
                var result = page.EvaluatePath(Path);

                // Invalid result
                if (result.Property == null)
                {
                    result.IsValid = false;
                }

                // # syntax
                else if (Extension == "#")
                {
                    string format = null;
                    Parameters.TryGetValue("format", out format);

                    string value;
                    result.IsValid = Adapter.TryGetDisplayValue(result.Property, format, result.Value, out value);
                    result.Value   = value;
                }

                // @ syntax
                else if (Extension == "@")
                {
                    if (string.IsNullOrEmpty(Path))
                    {
                        if (!(page.Context.DataItem is Adapter))
                        {
                            throw new ApplicationException("No path was specified for the \"@\" markup extension, and the source is not an adapter.");
                        }
                        result.Value = page.Context.DataItem;
                    }
                    else
                    {
                        ExoWeb.OnBeforeCreateAdapter(this, result.Source, result.Property);

                        result = new BindingResult()
                        {
                            Value    = new Adapter(result, Parameters),
                            IsValid  = result.IsValid,
                            Property = result.Property,
                            Source   = result.Source
                        };
                    }
                }

                return(new AttributeBinding(Attribute, result));
            }
 static BindingResult ConvertFromString(string strings, Type entityType)
 {
     try
     {
         return(BindingResult.Success(entityType.CreateInstanceFrom(strings)));
     }
     catch (Exception e)
     {
         if (e.InnerException is FormatException)
         {
             return(BindingResult.Failure());
         }
         throw;
     }
 }
Ejemplo n.º 28
0
        public void enumerables_can_be_built_without_headers()
        {
            var binder = new KeyedValuesBinder(TypeOf <IEnumerable <Customer> >(), "customer");
            ValueConverter <string> valueConverter = (str, type) => BindingResult.Success(type.CreateInstanceFrom(str));

            binder.SetProperty(":0.FirstName", new[] { "Frodo" }, valueConverter).ShouldBeTrue();


            binder.SetProperty(":1.FirstName", new[] { "Sam" }, valueConverter).ShouldBeTrue();

            var customers = (IEnumerable <Customer>)binder.BuildObject().Instance;

            customers.Count().ShouldBe(2);
            customers.First().FirstName.ShouldBe("Frodo");
            customers.Skip(1).First().FirstName.ShouldBe("Sam");
        }
        public void Produces_none_when_object_of_member_in_the_expression_is_null()
        {
            var graph = new Person();
            var none  = BindingResult.None <string>();

            var actual = Binding.Create((Person x) => x.Spouse.Name.First);

            AssertEx.Bind(null, none, actual);

            AssertEx.Bind(graph, none, actual);

            graph.Spouse = new Person();
            AssertEx.Bind(graph, none, actual);

            graph.Spouse.Name = new Name("Baz");
            AssertEx.Bind(graph, "Baz", actual);
        }
Ejemplo n.º 30
0
//        [TestMethod]
        public void TestMethod1()
        {
            SourceClass   source     = new SourceClass(  );
            TargetClass   target     = new TargetClass(  );
            BindingBase   binding    = new BindingBase(target, "TargetStr", source, "SourceInt");
            BindingResult lastResult = null;

            binding.OnBinding += result => {
                lastResult = result;
            };
            binding.Bind(  );
            target.TargetStr = "5";
            Assert.IsTrue(source.SourceInt == 5);
            target.TargetStr = "invalid int";
            Assert.IsTrue(source.SourceInt == 0);
            Assert.IsTrue(lastResult.hasConversionError);
        }
        public BindingResult ConvertValues(IMultipartHttpEntity entity, Type targetType)
        {
            object destination;
            var    sourceMediaType = entity.ContentType ?? MediaType.TextPlain;

            var type = _typeSystem.FromClr(targetType);
            var mediaTypeReaderReg = _codecs.FindMediaTypeReader(sourceMediaType, new[] { type }, null);

            if (mediaTypeReaderReg != null)
            {
                var mediaTypeReader =
                    (ICodec)_container.Resolve(mediaTypeReaderReg.CodecRegistration.CodecType);
                if (mediaTypeReader is IMediaTypeReader)
                {
                    return(BindingResult.Success(((IMediaTypeReader)mediaTypeReader).ReadFrom(entity, type, targetType.Name)));
                }
                var binder = BinderLocator.GetBinder(type);
                if (mediaTypeReader.TryAssignKeyValues(entity, binder))
                {
                    return(binder.BuildObject());
                }
            }

            // if no media type reader was found, try to parse to a string and convert from that.
            var stringType = _typeSystem.FromClr <string>();

            mediaTypeReaderReg = _codecs.FindMediaTypeReader(sourceMediaType, new[] { stringType }, null);

            if (entity.ContentType == null)
            {
                entity.ContentType = MediaType.TextPlain;
            }

            // defaults the entity to UTF-8 if none is specified, to account for browsers favouring using the charset of the origin page rather than the standard. Cause RFCs are too difficult to follow uh...
            if (entity.ContentType.CharSet == null)
            {
                entity.ContentType.CharSet = "UTF-8";
            }
            var plainTextReader = (IMediaTypeReader)_container.Resolve(mediaTypeReaderReg.CodecRegistration.CodecType);
            var targetString    = plainTextReader.ReadFrom(entity, stringType, targetType.Name);

            destination = targetType.CreateInstanceFrom(targetString);

            return(BindingResult.Success(destination));
        }
Ejemplo n.º 32
0
 /// <summary>
 /// Creates a new BindingTarget when the method binding has failued due to 
 /// one or more parameters which could not be converted.
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, CallFailure[] failures)
 {
     _name = name;
     _result = BindingResult.CallFailure;
     _callFailures = failures;
     _actualArgs = actualArgumentCount;
 }
Ejemplo n.º 33
0
 internal AttributeBinding(Attribute attribute, BindingResult binding)
 {
     this.attribute = attribute;
     this.binding = binding;
 }
Ejemplo n.º 34
0
 /// <summary>
 /// Other failure.
 /// </summary>
 internal BindingTarget(string name, BindingResult result)
 {
     _name = name;
     _result = result;
 }
Ejemplo n.º 35
0
 /// <summary>
 /// Creates a new BindingTarget when the match was ambiguous
 /// </summary>
 internal BindingTarget(string name, int actualArgumentCount, MethodCandidate[] ambiguousMatches)
 {
     _name = name;
     _result = BindingResult.AmbiguousMatch;
     _ambiguousMatches = ambiguousMatches;
     _actualArgs = actualArgumentCount;
 }
Ejemplo n.º 36
0
            internal override AttributeBinding Evaluate(AjaxPage page)
            {
                // Evaluate the binding path
                var result = page.EvaluatePath(Path);

                // Invalid result
                if (result.Property == null)
                    result.IsValid = false;

                // # syntax
                else if (Extension == "#")
                {
                    string format = null;
                    Parameters.TryGetValue("format", out format);

                    string value;
                    result.IsValid = Adapter.TryGetDisplayValue(result.Property, format, result.Value, out value);
                    result.Value = value;
                }

                // @ syntax
                else if (Extension == "@")
                {
                    if (string.IsNullOrEmpty(Path))
                    {
                        if (!(page.Context.DataItem is Adapter))
                            throw new ApplicationException("No path was specified for the \"@\" markup extension, and the source is not an adapter.");
                        result.Value = page.Context.DataItem;
                    }
                    else
                    {
                        var args = ExoWeb.OnBeforeCreateAdapter(this, result.Source, result.Property);

                        result = new BindingResult()
                        {
                            Value = new Adapter(result, args != null ? args.ModifiedParameters ?? Parameters : Parameters),
                            IsValid = result.IsValid,
                            Property = result.Property,
                            Source = result.Source
                        };
                    }
                }

                return new AttributeBinding(Attribute, result);
            }