Example #1
0
 public AggregateExpectationTypeResolver(INamingConvention namingConvention)
 {
     targetKey  = namingConvention.Apply(TargetKey);
     typeLookup = new Dictionary <string, Type>()
     {
         { namingConvention.Apply(nameof(NoEvents)), typeof(NoEvents) },
         { namingConvention.Apply(nameof(EventCount)), typeof(EventCount) },
     };
 }
Example #2
0
 public string GetStr(INamingConvention naming)
 {
     if (!string.IsNullOrEmpty(Alias))
         return Alias;
     else if (IsNonConsecutiveList)
         return naming.Apply(Name).Singularize(Plurality.CouldBeEither);
     else
         return naming.Apply(Name);
 }
Example #3
0
        public ExpectationTypeResolver(INamingConvention namingConvention)
        {
            typeLookup = new Dictionary <string, Type>()
            {
                { namingConvention.Apply(nameof(BoundedExpectation.Bounds)), typeof(BoundedExpectation) },
                { namingConvention.Apply(nameof(CentroidExpectation.Centroid)), typeof(CentroidExpectation) },
                { namingConvention.Apply(nameof(TemporalExpectation.Time)), typeof(TemporalExpectation) },
            };

            // Only match label only expectation as a last resort. We want more specific matchers to match first.
            fallback = new KeyValuePair <string, Type>(namingConvention.Apply(nameof(LabelOnlyExpectation.Label)), typeof(LabelOnlyExpectation));
        }
Example #4
0
 public string GetStr(INamingConvention naming)
 {
     if (!string.IsNullOrEmpty(Alias))
     {
         return(Alias);
     }
     else if (IsNonConsecutiveList)
     {
         return(naming.Apply(Name).Singularize(Plurality.CouldBeEither));
     }
     else
     {
         return(naming.Apply(Name));
     }
 }
        public void TestNamingConventionApply(string testName, INamingConvention namingConvention, string originalOldName, string expectedNewName)
        {
            this.Output.WriteLine("Test Name: {0}", testName);
            this.Output.WriteLine(String.Empty);

            // Arrange
            this.Output.WriteLine("Original Old Name");
            this.Output.WriteLine(originalOldName ?? String.Empty);

            this.Output.WriteLine(String.Empty);

            this.Output.WriteLine("Expected New Name");
            this.Output.WriteLine(expectedNewName ?? String.Empty);

            // Act
            var actualNewName = namingConvention.Apply(originalOldName);

            this.Output.WriteLine(String.Empty);

            this.Output.WriteLine("Actual New Name");
            this.Output.WriteLine(actualNewName ?? String.Empty);

            // Assert
            Assert.Equal(expectedNewName, actualNewName);
        }
        public static void TraverseGenericDictionaryHelper <TKey, TValue, TContext>(
            FullObjectGraphTraversalStrategy self,
            IDictionary <TKey, TValue> dictionary,
            IObjectGraphVisitor visitor,
            int currentDepth,
            INamingConvention namingConvention,
            IObjectGraphVisitorContext context)
        {
            var v         = (IObjectGraphVisitor <TContext>)visitor;
            var c         = (TContext)context;
            var isDynamic = dictionary.GetType().FullName.Equals("System.Dynamic.ExpandoObject");

            foreach (var entry in dictionary)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key.ToString();
                var key       = self.GetObjectDescriptor(keyString, typeof(TKey));
                var value     = self.GetObjectDescriptor(entry.Value, typeof(TValue));

                if (v.EnterMapping(key, value, c))
                {
                    self.Traverse(key, v, currentDepth, c);
                    self.Traverse(value, v, currentDepth, c);
                }
            }
        }
 public override IEnumerable <IPropertyDescriptor> GetProperties(Type type, object container)
 {
     return(innerTypeDescriptor.GetProperties(type, container)
            .Select(p => (IPropertyDescriptor) new PropertyDescriptor(p)
     {
         Name = namingConvention.Apply(p.Name)
     }));
 }
        public string Apply(string value)
        {
            var(key, renamedValue) = _rename.FirstOrDefault(
                p =>
                string.Equals(value, p.Key, StringComparison.InvariantCultureIgnoreCase));

            return(key != default
                ? renamedValue
                : _yamlNaming.Apply(value));
        }
Example #9
0
 private static void UpdateComponentData(Component component, YamlNode componentYamlNode, INamingConvention nameConvertor)
 {
     foreach (PropertyInfo info in component.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         string key = nameConvertor.Apply(info.Name);
         if (componentYamlNode.HasValue(key) && info.CanWrite)
         {
             info.SetValue(component, componentYamlNode.GetValue(key), null);
         }
     }
 }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateExpectationTypeResolver{T}"/> class.
 /// </summary>
 /// <param name="namingConvention">The <see cref="INamingConvention"/> instance.</param>
 public AggregateExpectationTypeResolver(INamingConvention namingConvention)
 {
     targetKey  = namingConvention.Apply(TargetKey);
     typeLookup = new Dictionary <string, Type>();
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         foreach (var t in assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(T))))
         {
             typeLookup.Add(t.Name, t);
         }
     }
 }
Example #11
0
 public override IEnumerable <IPropertyDescriptor> GetProperties(Type type, object container)
 {
     return(innerTypeDescriptor.GetProperties(type, container).Select(delegate(IPropertyDescriptor p)
     {
         YamlMemberAttribute customAttribute = p.GetCustomAttribute <YamlMemberAttribute>();
         if (customAttribute != null && !customAttribute.ApplyNamingConventions)
         {
             return p;
         }
         return new PropertyDescriptor(p)
         {
             Name = namingConvention.Apply(p.Name)
         };
     }));
 }
Example #12
0
 public static void SetPropertiesFromYamlNode(object target, YamlNode componentYamlNode, INamingConvention nameConvertor)
 {
     foreach (PropertyInfo info in target.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance))
     {
         string key = nameConvertor.Apply(info.Name);
         if (componentYamlNode.HasValue(key) && info.CanWrite)
         {
             try
             {
                 info.SetValue(target, componentYamlNode.GetValue(key), null);
             }
             catch (ArgumentException)
             {
                 object[] args = new object[] { info.PropertyType, componentYamlNode.GetValue(key).GetType() };
                 UnityEngine.Debug.LogFormat("Can't convert to {0} from {1}", args);
             }
         }
     }
 }
Example #13
0
        private void TraverseGenericDictionaryHelper <TKey, TValue>(
            IDictionary <TKey, TValue> dictionary,
            IObjectGraphVisitor visitor, int currentDepth, INamingConvention namingConvention)
        {
            var isDynamic = dictionary.GetType().FullName.Equals("System.Dynamic.ExpandoObject");

            foreach (var entry in dictionary)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key.ToString();
                var key       = GetObjectDescriptor(keyString, typeof(TKey));
                var value     = GetObjectDescriptor(entry.Value, typeof(TValue));

                if (visitor.EnterMapping(key, value))
                {
                    Traverse(key, visitor, currentDepth);
                    Traverse(value, visitor, currentDepth);
                }
            }
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AggregateExpectationTypeResolver{T}"/> class.
 /// </summary>
 /// <param name="namingConvention">The <see cref="INamingConvention"/> instance.</param>
 public AggregateExpectationTypeResolver(INamingConvention namingConvention)
 {
     targetKey  = namingConvention.Apply(TargetKey);
     typeLookup = new Dictionary <string, Type>();
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         try
         {
             foreach (Type t in assembly.GetTypes().Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(T))))
             {
                 typeLookup.Add(t.Name, t);
             }
         }
         catch (Exception e)
         {
             Log.Error($"Error loading types for {assembly.FullName}\n{e}");
         }
     }
 }
Example #15
0
        protected virtual void TraverseDictionary<TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor<TContext> visitor, int currentDepth, Type keyType, Type valueType, TContext context)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);

            var isDynamic = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var keyString = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key;
                var key = GetObjectDescriptor(keyString, keyType);
                var value = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value, context))
                {
                    Traverse(key, visitor, currentDepth, context);
                    Traverse(value, visitor, currentDepth, context);
                }
            }

            visitor.VisitMappingEnd(dictionary, context);
        }
Example #16
0
        protected virtual void TraverseDictionary <TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor <TContext> visitor, Type keyType, Type valueType, TContext context, Stack <ObjectPathSegment> path)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);

            var isDynamic = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");

            foreach (DictionaryEntry entry in (IDictionary)dictionary.Value)
            {
                var keyValue = isDynamic ? namingConvention.Apply(entry.Key.ToString()) : entry.Key;
                var key      = GetObjectDescriptor(keyValue, keyType);
                var value    = GetObjectDescriptor(entry.Value, valueType);

                if (visitor.EnterMapping(key, value, context))
                {
                    var keyAsString = TypeConverter.ChangeType <string>(key);
                    Traverse(keyValue, key, visitor, context, path);
                    Traverse(keyValue, value, visitor, context, path);
                }
            }

            visitor.VisitMappingEnd(dictionary, context);
        }
 private void ShouldApplyConventionGiven(string input, string expectedName, INamingConvention convention)
 {
     convention.Apply(input).Should().Be(expectedName);
 }
 private void ShouldApplyConventionGiven(string input, string expectedName, INamingConvention convention)
 {
     convention.Apply(input).Should().Be(expectedName);
 }
 public override IEnumerable <IPropertyDescriptor> GetProperties(Type type, object container) =>
 from p in innerTypeDescriptor.GetProperties(type, container)
 select(IPropertyDescriptor) new PropertyDescriptor(p)
 {
     Name = namingConvention.Apply(p.Name)
 };
 public override IEnumerable <IPropertyDescriptor> GetProperties(Type type)
 {
     return(innerTypeDescriptor.GetProperties(type)
            .Select(p => (IPropertyDescriptor) new PropertyDescriptor(p.Property, namingConvention.Apply(p.Name))));
 }
Example #21
0
        protected virtual void TraverseDictionary <TContext>(IObjectDescriptor dictionary, IObjectGraphVisitor <TContext> visitor, int currentDepth, Type keyType, Type valueType, TContext context)
        {
            visitor.VisitMappingStart(dictionary, keyType, valueType, context);
            bool flag = dictionary.Type.FullName.Equals("System.Dynamic.ExpandoObject");
            IDictionaryEnumerator enumerator = ((IDictionary)dictionary.Value).GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    DictionaryEntry   dictionaryEntry   = (DictionaryEntry)enumerator.Current;
                    object            value             = (!flag) ? dictionaryEntry.Key : namingConvention.Apply(dictionaryEntry.Key.ToString());
                    IObjectDescriptor objectDescriptor  = GetObjectDescriptor(value, keyType);
                    IObjectDescriptor objectDescriptor2 = GetObjectDescriptor(dictionaryEntry.Value, valueType);
                    if (visitor.EnterMapping(objectDescriptor, objectDescriptor2, context))
                    {
                        Traverse(objectDescriptor, visitor, currentDepth, context);
                        Traverse(objectDescriptor2, visitor, currentDepth, context);
                    }
                }
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = (enumerator as IDisposable)) != null)
                {
                    disposable.Dispose();
                }
            }
            visitor.VisitMappingEnd(dictionary, context);
        }
Example #22
0
 public SharedImporter(ILogger <SharedImporter> logger, INamingConvention configNaming)
 {
     this.logger    = logger;
     SharedTestsKey = configNaming.Apply(nameof(Config.CommonTests));
 }