Esempio n. 1
0
        public void It_generates_the_correct_property_for_a_non_required_boolean()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Boolean Attrbute",
                Description =
                    "A boolean attribute",
                Required           = false,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Boolean",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BoolAttributeNotRequired, result.Item1);
            ExAssert.AreEqual(TestData.BoolAttributeNotRequiredTests, result.Item2);
        }
Esempio n. 2
0
        public void It_handles_Multivalued_Reference_attributes()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "My Display Name",
                Description        = "My Description",
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = true,
                    DataType    = "Reference",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null, new List <string> {
                "foo"
            },
                                          @"[ { ""AttrName"": ""ActionWorkflowInstance"", ""ObjType"": ""WorkflowInstance"" }, { ""AttrName"": ""Property-Name"", ""ObjType"": ""Model-Type"" } ]");


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.MultiValuedReference, result.Item1);
            ExAssert.AreEqual(TestData.MultiValuedReferenceTests, result.Item2);
        }
Esempio n. 3
0
        public void It_handles_Multivalued_Binary_attributes()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "My Display Name",
                Description        = "My Description",
                Required           = false,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = true,
                    DataType    = "Binary",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null);


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.MultiValuedBinary, result.Item1);
            ExAssert.AreEqual(TestData.MultivaluedBinaryTests, result.Item2);
        }
Esempio n. 4
0
        public void It_can_handle_non_required_multi_valued_strings()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "My Display Name",
                Description        = "My Description",
                Required           = false,
                StringRegex        = "[0-9]",
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = true,
                    DataType    = "String",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null);


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.MultiValuedStringNonRequired, result.Item1);
            ExAssert.AreEqual(TestData.MultiValuedStringTestsNonRequired, result.Item2);
        }
Esempio n. 5
0
        public void It_can_handle_non_required_multiValued_Integer_with_MaxAndMin()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "My Display Name",
                Description        = "My Description",
                Required           = false,
                IntegerMinimum     = 2,
                IntegerMaximum     = 5,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = true,
                    DataType    = "Integer",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.MultiValuedIntegerAttributeWithMinMax, result.Item1);
            ExAssert.AreEqual(TestData.MultiValuedIntegerAttributeWithMinMaxTests, result.Item2);
        }
Esempio n. 6
0
        public void It_handles_dashes_in_reference_AttrName()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "Reference Attrbute",
                Description        = "A standard reference attribute",
                Required           = true, // should be ignored - reference attributes can't be required
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Reference",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null, new List <string> {
                "Property-Name"
            });

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.ReferenceAttrWithDashInName, result.Item1);
            ExAssert.AreEqual(TestData.ReferenceAttrWithDashInNameTests, result.Item2);
        }
Esempio n. 7
0
        public void It_can_handle_binary_attributes_with_dashes_in_the_name()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Reference Attrbute",
                Description =
                    "A standard reference attribute",
                Required           = true,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Binary",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null);


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BinaryAttributeWithDash, result.Item1);
            ExAssert.AreEqual(TestData.BinaryAttributeWithDashTests, result.Item2);
        }
Esempio n. 8
0
        public void It_handles_booleans_with_dashes()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Boolean Attrbute",
                Description =
                    "A boolean attribute",
                Required           = true,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Boolean",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "Property-Name"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BoolAttributeWithDash, result.Item1);
            ExAssert.AreEqual(TestData.BoolAttributeWithDashTests, result.Item2);
        }
Esempio n. 9
0
        public void It_generates_the_correct_property_for_a_binding_with_different_Description()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "First Choice for Summary Part I",
                Description        = "Binding Description",
                Required           = true,
                StringRegex        = "abc",
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "String",
                    DisplayName = "Second Choice for Summary Part I",
                    Description = "Second Choice for Summary Part II",
                    Name        = "PropertyName"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BindingWithDifferentDescription, result.Item1);
            ExAssert.AreEqual(TestData.BindingWithDifferentDescriptionTests, result.Item2);
        }
Esempio n. 10
0
        public void It_generates_the_correct_property_and_tests_for_a_required_binary_attr()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Reference Attrbute",
                Description =
                    "A standard reference attribute",
                Required           = true,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Binary",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName"
                },
            };

            var it = new IdmCodeGenerator(null);


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.BinaryAttributeRequired, result.Item1);
            ExAssert.AreEqual(TestData.BinaryAttributeTestsRequired, result.Item2);
        }
Esempio n. 11
0
        public void It_can_handle_attributes_with_dashes_in_the_name()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "First Choice for Summary Part I",
                Description =
                    "First Choice for Summary Part II",
                Required           = true,
                StringRegex        = "abc",
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "String",
                    DisplayName = "Second Choice for Summary Part I",
                    Description = "Second Choice for Summary Part II",
                    Name        = "Property-Name",
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.StringAttributeWithDashInName, result.Item1);
            ExAssert.AreEqual(TestData.StringAttributeWithDashInNameTests, result.Item2);
        }
Esempio n. 12
0
        public void It_generates_the_correct_property_for_a_reference_attribute_doesnt_match_any_object_type()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Reference Attrbute",
                Description =
                    "A standard reference attribute",
                Required           = true, // should be ignored - reference attributes can't be required
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Reference",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName2"
                },
            };

            var it = new IdmCodeGenerator(null);


            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.ReferenceAttributeWhereTypeNotFound, result.Item1);
            ExAssert.AreEqual(TestData.ReferenceAttributeWhereTypeNotFoundTests, result.Item2);
        }
Esempio n. 13
0
        public void It_generates_the_correct_property_for_a_standard_reference_attribute_that_matches_an_item_in_the_json_environment_variable()
        {
            // Where's the environment variable
            // Arrange
            var it = new IdmCodeGenerator(null);
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "Reference Attrbute",
                Description        = "A standard reference attribute",
                Required           = true, // should be ignored - reference attributes can't be required
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Reference",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName"
                },
            };

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.StandardReferenceAttributeWhereTypeFoundInJsonFile, result.Item1);
            ExAssert.AreEqual(TestData.StandardReferenceAttributeWhereTypeFoundInJsonFileTests, result.Item2);
        }
Esempio n. 14
0
        public void It_generates_the_correct_property_for_a_standard_reference_attribute_that_matches_an_object_type_name()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "Reference Attrbute",
                Description =
                    "A standard reference attribute",
                Required           = true, // should be ignored - reference attributes can't be required
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Reference",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName"
                },
                // The generator needs the smarts of the generator or,
                // "How do I know that a "DisplayedOwner" is a "Person" object?
            };

            var it = new IdmCodeGenerator(null, null, @"[ { ""AttrName"": ""PropertyName"", ""ObjType"": ""Person"" } ]");

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.StandardReferenceAttributeWhereTypeMatchesName, result.Item1);
            ExAssert.AreEqual(TestData.StandardReferenceAttributeWhereTypeMatchesNameTests, result.Item2);
        }
Esempio n. 15
0
        public static void AddBinding(this IBindingContextOwner view, object target,
                                      BindingDescription bindingDescription, object clearKey = null)
        {
            var descriptions = new[] { bindingDescription };

            view.AddBindings(target, descriptions, clearKey);
        }
Esempio n. 16
0
        public void It_generates_the_correct_property_for_an_integer_thats_required()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName        = "My Display Name",
                Description        = "My Description",
                Required           = true,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "Integer",
                    DisplayName = "Doesn't matter",
                    Description = "Doesn't matter",
                    Name        = "PropertyName"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.IntegerAttribute, result.Item1);
            ExAssert.AreEqual(TestData.IntegerAttributeTests, result.Item2);
        }
Esempio n. 17
0
        public void It_generates_the_correct_property_for_a_string_attribute_without_a_regular_expression()
        {
            // Arrange
            var bindingDescription = new BindingDescription
            {
                DisplayName =
                    "First Choice for Summary Part I",
                Description =
                    "First Choice for Summary Part II",
                Required           = true,
                BoundAttributeType = new AttributeTypeDescription
                {
                    Multivalued = false,
                    DataType    = "String",
                    DisplayName = "Second Choice for Summary Part I",
                    Description = "Second Choice for Summary Part II",
                    Name        = "PropertyName"
                },
            };

            var it = new IdmCodeGenerator(null);

            // Act
            Tuple <string, string> result = it.GenerateAPropertyAndItsTests(bindingDescription);

            // Assert
            ExAssert.AreEqual(TestData.StringAttributeWithoutRegEx, result.Item1);
            ExAssert.AreEqual(TestData.StringAttributeWithoutRegExTests, result.Item2);
        }
Esempio n. 18
0
        public static T Bind <T>(this T element,
                                 InlineBindingTarget target,
                                 string targetPath,
                                 string sourcePath,
                                 IValueConverter converter = null,
                                 object converterParameter = null,
                                 object fallbackValue      = null,
                                 BindingMode mode          = BindingMode.Default)
        {
            if (string.IsNullOrEmpty(targetPath))
            {
                targetPath = BindingSingletonCache.Instance.DefaultBindingNameLookup.DefaultFor(typeof(T));
            }

            var bindingDescription = new BindingDescription(
                targetPath,
                sourcePath,
                converter,
                converterParameter,
                fallbackValue,
                mode);

            target.BindingContextOwner.AddBinding(element, bindingDescription);

            return(element);
        }
        protected virtual bool TryCreateProxy(object target, BindingDescription description, out ITargetProxy proxy)
        {
            proxy = null;
            foreach (PriorityFactoryPair pair in this.factories)
            {
                try
                {
                    var factory = pair.factory;
                    if (factory == null)
                    {
                        continue;
                    }

                    proxy = factory.CreateProxy(target, description);
                    if (proxy != null)
                    {
                        return(true);
                    }
                }
                catch (Exception e)
                {
                    if (log.IsWarnEnabled)
                    {
                        log.WarnFormat("Unable to bind:{0};exception:{1}", description.ToString(), e);
                    }
                }
            }

            return(false);
        }
Esempio n. 20
0
        private static string GenerateSingleValuedStringTests(BindingDescription bindingDescription)
        {
            var nonMatchTest = "";
            var val          = "A string";

            if (!string.IsNullOrEmpty(bindingDescription.StringRegex))
            {
                var xeger = new Xeger(bindingDescription.StringRegex);
                val = xeger.Generate();

                var nonMatch = @"flkj3332@!!!$

fd333
";
                nonMatchTest = string.Format(Templates.NonMatchTest,
                                             GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name),
                                             nonMatch);
            }

            string tests = string.Format(Templates.SingleValuedStringFormatTests,
                                         GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name),
                                         val,
                                         nonMatchTest);

            return(tests);
        }
Esempio n. 21
0
        private static string GetRegEx(BindingDescription bindingDescription)
        {
            var regEx = "";

            if (!string.IsNullOrEmpty(bindingDescription.StringRegex))
            {
                if (bindingDescription.BoundAttributeType.Multivalued)
                {
                    var regExFormat = @"var regEx = new RegEx(""{0}"");
                if (value.Any(x => !regEx.IsMatch(x))
                    throw new ArgumentException(""One or more invalid values for {1}.  Each value must match regular expression '{0}'"");
                ";
                    regEx = string.Format(regExFormat, bindingDescription.StringRegex, bindingDescription.BoundAttributeType.Name);
                }
                else
                {
                    var regExFormat = @"var regEx = new RegEx(""{0}"");
                if (!regEx.IsMatch(value))
                    throw new ArgumentException(""Invalid value for {1}.  Must match regular expression '{0}'"");
                ";
                    regEx = string.Format(regExFormat, bindingDescription.StringRegex, bindingDescription.BoundAttributeType.Name);
                }
            }
            return(regEx);
        }
Esempio n. 22
0
        private static string GenerateSingleValuedValue(BindingDescription bindingDescription)
        {
            string conversionMethodString;
            string typeString = bindingDescription.BoundAttributeType.DataType == "Boolean" ? "bool" : "int";

            if (bindingDescription.Required == false)
            {
                typeString            += '?';
                conversionMethodString = bindingDescription.BoundAttributeType.DataType == "Boolean"
                    ? "AttrToNullableBool"
                    : "AttrToNullableInteger";
            }
            else
            {
                conversionMethodString = bindingDescription.BoundAttributeType.DataType == "Boolean"
                    ? "AttrToBool"
                    : "AttrToInteger";
            }

            var minMax = GetMinMax(bindingDescription);
            var validCSharpIdentifier = GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name);
            var propertyCode          = string.Format(Templates.SingleValuedValueFormat,
                                                      GetDisplayName(bindingDescription),
                                                      GetDescription(bindingDescription),
                                                      GetRequired(bindingDescription),
                                                      bindingDescription.BoundAttributeType.Name,
                                                      typeString,
                                                      validCSharpIdentifier,
                                                      conversionMethodString,
                                                      minMax);

            return(propertyCode);
        }
 public void SetDescription(BindingDescription bindingDescription)
 {
     this.description.Mode          = bindingDescription.Mode;
     this.description.TargetName    = bindingDescription.TargetName;
     this.description.UpdateTrigger = bindingDescription.UpdateTrigger;
     this.description.Converter     = bindingDescription.Converter;
     this.description.Source        = bindingDescription.Source;
 }
Esempio n. 24
0
        public Tuple <string, string> GenerateAPropertyAndItsTests(BindingDescription bindingDescription)
        {
            var propertyAndTests = bindingDescription.BoundAttributeType.Multivalued
                ? GenerateMultiValuedPropertyAndTests(bindingDescription)
                : GenerateSingleValuedPropertyAndTests(bindingDescription);

            return(propertyAndTests);
        }
Esempio n. 25
0
        private static string GetNullTestMultivaluedDateTime(BindingDescription bindingDescription, string validCSharpIdentifier)
        {
            string nullTest = bindingDescription.Required == true
                ? ""
                : string.Format(Templates.MultiValuedDateTimeNullTestFormat, validCSharpIdentifier);

            return(nullTest);
        }
Esempio n. 26
0
        private string GenerateSingleValuedReferenceTests(BindingDescription bindingDescription)
        {
            var tests = string.Format(Templates.SingleValuedReferenceFormatTests,
                                      GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name),
                                      GetObjTypeName(bindingDescription));

            return(tests);
        }
Esempio n. 27
0
        public FluentBindingDescription <TChildTarget, TSource> Bind <TChildTarget>(TChildTarget childTarget,
                                                                                    BindingDescription bindingDescription)
            where TChildTarget : class
        {
            var toReturn = Bind(childTarget);

            toReturn.FullyDescribed(bindingDescription);
            return(toReturn);
        }
Esempio n. 28
0
 private string GenerateMultiValuedDateTime(BindingDescription bindingDescription)
 {
     return(string.Format(Templates.MultiValuedDateTimeFormat,
                          GetDisplayName(bindingDescription),
                          GetDescription(bindingDescription),
                          GetRequired(bindingDescription),
                          bindingDescription.BoundAttributeType.Name,
                          GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name)));
 }
Esempio n. 29
0
        private string GenerateMultiValuedDateTimeTests(BindingDescription bindingDescription)
        {
            var validCSharpIdentifier = GetValidCSharpIdentifier(bindingDescription.BoundAttributeType.Name);
            var nullTest = GetNullTestMultivaluedDateTime(bindingDescription, validCSharpIdentifier);

            return(string.Format(Templates.MultiValuedDateTimeFormatTests,
                                 validCSharpIdentifier,
                                 nullTest));
        }
Esempio n. 30
0
        private static string GetRequired(BindingDescription bindingDescription)
        {
            var required = "";

            if (bindingDescription.Required == true)
            {
                required = $"[Required]{Environment.NewLine}        ";
            }
            return(required);
        }