示例#1
0
 public void It_should_handle_harder_strings()
 {
     SnakeCase.Convert("TestTesting").ShouldEqual("test_testing");
     SnakeCase.Convert("TestingTest").ShouldEqual("testing_test");
     SnakeCase.Convert("ApppppAppppppp").ShouldEqual("appppp_appppppp");
     SnakeCase.Convert("ApppppppAppppp").ShouldEqual("appppppp_appppp");
 }
示例#2
0
        private IDictionary <string, object> WithCommonConventions(object target, IDictionary <string, object> results = null)
        {
            if (target == null)
            {
                return(null);
            }
            if (results == null)
            {
                results = new Dictionary <string, object>();
            }
#if NETSTANDARD1_6
            foreach (var property in target.GetType().GetRuntimeProperties())
#else
            foreach (var property in target.GetType().GetProperties())
#endif
            {
                var name = SnakeCase.Convert(property.Name);
                if (results.ContainsKey(name))
                {
                    continue;
                }

                results[name] = GetTheValue(property.PropertyType, property.GetValue(target));
            }
            return(RemoveNulls(results));
        }
示例#3
0
 public void Configure(EntityTypeBuilder <ErrorOccurrence> builder)
 {
     builder.ToTable(SnakeCase.Convert(nameof(ErrorOccurrence)));
     builder.HasKey(x => x.Id)
     .HasName("error_occurrence_id");
     builder.Property(x => x.Id)
     .HasColumnName("id")
     .IsRequired();
     builder.Property(x => x.Level)
     .HasColumnName("level")
     .IsRequired();
     builder.Property(x => x.Environment)
     .HasColumnName("environment")
     .IsRequired();
     builder.Property(x => x.Title)
     .HasColumnName("title")
     .IsRequired();
     builder.Property(x => x.Description)
     .HasColumnName("description")
     .IsRequired();
     builder.Property(x => x.ArchiviedRecord)
     .HasColumnName("archivied_record")
     .IsRequired();
     builder.Property(x => x.Origin)
     .HasColumnName("origin")
     .IsRequired();
     builder.Property(x => x.CreatedAt)
     .HasColumnName("created_at")
     .IsRequired();
 }
示例#4
0
 public void It_should_convert_things_to_snake_case()
 {
     SnakeCase.Convert("T").ShouldEqual("t");
     SnakeCase.Convert("Test").ShouldEqual("test");
     SnakeCase.Convert("TEST").ShouldEqual("t_e_s_t");
     SnakeCase.Convert("JohnGalt").ShouldEqual("john_galt");
 }
示例#5
0
 public void It_should_handle_harder_strings()
 {
     Assert.Equal("test_testing", SnakeCase.Convert("TestTesting"));
     Assert.Equal("testing_test", SnakeCase.Convert("TestingTest"));
     Assert.Equal("appppp_appppppp", SnakeCase.Convert("ApppppAppppppp"));
     Assert.Equal("appppppp_appppp", SnakeCase.Convert("ApppppppAppppp"));
 }
示例#6
0
 public void It_should_convert_things_to_snake_case()
 {
     Assert.Equal("t", SnakeCase.Convert("T"));
     Assert.Equal("test", SnakeCase.Convert("Test"));
     Assert.Equal("t_e_s_t", SnakeCase.Convert("TEST"));
     Assert.Equal("john_galt", SnakeCase.Convert("JohnGalt"));
 }
示例#7
0
        void SetValues()
        {
            var properties = typeof(JobData).GetProperties();

            foreach (var property in properties)
            {
                string key   = SnakeCase.Convert(property.Name);
                string value = NamedObjectDictionary.KeyValue("job_data", key);
                property.SetValue(this, value);
            }
        }
        public object Map(Type propertyType, object value)
        {
            var original   = (IDictionary <string, object>)value;
            var dictionary = new Dictionary <string, object>();

            foreach (var item in original.Where(i => i.Value != null))
            {
                var itemKey   = SnakeCase.Convert(item.Key);
                var itemValue = item.Value;
                dictionary[itemKey] = dataMapper.GetTheValue(itemValue.GetType(), itemValue);
            }
            return(dictionary.Count > 0 ? dictionary : null);
        }
示例#9
0
        private string ConvertToQueryString(object data)
        {
            if (data == null) return null;
            var original = dataMapper.CatchAll(data);

            var dictionary = new Dictionary<string, string>();
            foreach(var thing in original.Where(x=>string.IsNullOrEmpty(x.Value.ToString()) == false))
                dictionary[thing.Key] = thing.Value.ToString();

            var values = dictionary
                .Select(x => UrlUtility.UrlEncode(SnakeCase.Convert(x.Key)) + "=" + UrlUtility.UrlEncode(x.Value));

            return string.Join("&", values);
        }
示例#10
0
 public void Configure(EntityTypeBuilder <User> builder)
 {
     builder.ToTable(SnakeCase.Convert(nameof(User)));
     builder.HasKey(x => x.Id)
     .HasName("user_id");
     builder.Property(x => x.Id)
     .HasColumnName("id")
     .IsRequired();
     builder.Property(x => x.Name)
     .HasColumnName("name")
     .HasMaxLength(100)
     .IsRequired();
     builder.Property(x => x.Email)
     .HasColumnName("email")
     .IsRequired();
     builder.Property(x => x.Password)
     .HasColumnName("hash_password")
     .IsRequired();
 }
示例#11
0
        void GetValues()
        {
            //var form = new JobDataForm();
            //form.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
            //form.ShowDialog();

            var properties = typeof(JobData).GetProperties();

            foreach (var property in properties)
            {
                if (property.Name == nameof(HasJobDataDictionary))
                {
                    continue;
                }

                string key   = SnakeCase.Convert(property.Name);
                string value = NamedObjectDictionary.KeyValue("job_data", key);
                property.SetValue(this, value);
            }
        }
示例#12
0
        private string ConvertToQueryString(object data)
        {
            if (data == null)
            {
                return(null);
            }
            var original = dataMapper.CatchAll(data);

            var dictionary = new Dictionary <string, string>();

            foreach (var thing in original.Where(x => string.IsNullOrEmpty(x.Value.ToString()) == false))
            {
                dictionary[thing.Key] = thing.Value.ToString();
            }
#if NETSTANDARD1_6
            var values = dictionary
                         .Select(x => System.Net.WebUtility.UrlEncode(SnakeCase.Convert(x.Key)) + "=" + System.Net.WebUtility.UrlEncode(x.Value));
#else
            var values = dictionary
                         .Select(x => HttpUtility.UrlEncode(SnakeCase.Convert(x.Key)) + "=" + HttpUtility.UrlEncode(x.Value));
#endif

            return(string.Join("&", values));
        }
示例#13
0
 public void It_should_convert_null_to_null()
 {
     SnakeCase.Convert(null).ShouldBeNull();
 }
示例#14
0
 public void It_should_convert_null_to_null()
 {
     Assert.Null(SnakeCase.Convert(null));
 }
示例#15
0
 public void Normal()
 {
     Assert.Equal(
         "this_is_pascal",
         SnakeCase.Convert("ThisIsPascal"));
 }