Esempio n. 1
0
        public void SomethingStatus_Should_Be_Left_Alone()
        {
            var word      = "SomethingStatus";
            var inflected = Inflector.MakeSingular(word);

            Assert.Equal(word, inflected);
        }
Esempio n. 2
0
 /// <summary>
 /// Make plural when count is not one
 /// </summary>
 /// <param name="number">The number of things</param>
 /// <param name="sourceString">The source string.</param>
 /// <returns></returns>
 public static string Pluralize(int number, string sourceString)
 {
     if (number == 1)
     {
         return(String.Concat(number, " ", Inflector.MakeSingular(sourceString)));
     }
     return(String.Concat(number, " ", Inflector.MakePlural(sourceString)));
 }
Esempio n. 3
0
        public void MakeSingular(string word, string expected)
        {
            // Act
            var result = Inflector.MakeSingular(word);

            // Assert
            Assert.AreEqual(expected, result);
        }
Esempio n. 4
0
    // SchemaReader.ReadSchema
    public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
    {
        var result = new Tables();


        var cmd = factory.CreateCommand();

        cmd.Connection  = connection;
        cmd.CommandText = TABLE_SQL;

        //pull the tables in a reader
        using (cmd)
        {
            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    Table tbl = new Table();
                    tbl.Name      = rdr["TABLE_NAME"].ToString();
                    tbl.Schema    = rdr["TABLE_SCHEMA"].ToString();
                    tbl.IsView    = string.Compare(rdr["TABLE_TYPE"].ToString(), "View", true) == 0;
                    tbl.CleanName = CleanUp(tbl.Name);
                    tbl.ClassName = Inflector.MakeSingular(tbl.CleanName);
                    result.Add(tbl);
                }
            }
        }


        //this will return everything for the DB
        var schema = connection.GetSchema("COLUMNS");

        //loop again - but this time pull by table name
        foreach (var item in result)
        {
            item.Columns = new List <Column>();

            //pull the columns from the schema
            var columns = schema.Select("TABLE_NAME='" + item.Name + "'");
            foreach (var row in columns)
            {
                Column col = new Column();
                col.Name            = row["COLUMN_NAME"].ToString();
                col.PropertyName    = CleanUp(col.Name);
                col.PropertyType    = GetPropertyType(row);
                col.IsNullable      = row["IS_NULLABLE"].ToString() == "YES";
                col.IsPK            = row["COLUMN_KEY"].ToString() == "PRI";
                col.IsAutoIncrement = row["extra"].ToString().ToLower().IndexOf("auto_increment") >= 0;

                item.Columns.Add(col);
            }
        }

        return(result);
    }
Esempio n. 5
0
        private string GetCandidateKey()
        {
            string candidateKey = Inflector.MakeSingular(this._ObjectName);

            if (!string.IsNullOrWhiteSpace(candidateKey))
            {
                candidateKey += "_id";
            }

            return(candidateKey ?? "");
        }
Esempio n. 6
0
        private string GetNameColumnByConvention()
        {
            string nameKey = Inflector.MakeSingular(this.GetTableByConvention());

            if (!string.IsNullOrWhiteSpace(nameKey))
            {
                nameKey += "_name";
            }

            return(nameKey?.Replace("_name_name", "_name") ?? "");
        }
Esempio n. 7
0
        private string GetCandidateKeyByConvention()
        {
            string candidateKey = Inflector.MakeSingular(this.GetTableByConvention());

            if (!string.IsNullOrWhiteSpace(candidateKey))
            {
                candidateKey += "_id";
            }

            return(candidateKey ?? "");
        }
Esempio n. 8
0
        private string GetNameColumn()
        {
            string nameKey = Inflector.MakeSingular(this._ObjectName);

            if (!string.IsNullOrWhiteSpace(nameKey))
            {
                nameKey += "_name";
            }

            return(nameKey ?? "");
        }
    public string PkTableHumanCase(string suffix)
    {
        var singular         = Inflector.MakeSingular(PkTableNameFiltered);
        var pkTableHumanCase = (Settings.UsePascalCase ? Inflector.ToTitleCase(singular) : singular).Replace(" ", "").Replace("$", "");

        if (string.Compare(PkSchema, "dbo", StringComparison.OrdinalIgnoreCase) != 0 && Settings.PrependSchemaName)
        {
            pkTableHumanCase = PkSchema + "_" + pkTableHumanCase;
        }
        pkTableHumanCase += suffix;
        return(pkTableHumanCase);
    }
Esempio n. 10
0
        private string GetLookupFieldByConvention()
        {
            string candidateKey = Inflector.MakeSingular(this.GetTableByConvention());

            if (!string.IsNullOrWhiteSpace(candidateKey))
            {
                candidateKey += "_code";
            }

            candidateKey = candidateKey?.Replace("_code_code", "_code") ?? "";

            return(Sanitizer.SanitizeIdentifierName(candidateKey));
        }
Esempio n. 11
0
        private string GetCandidateKeyByConvention()
        {
            string candidateKey = Inflector.MakeSingular(this.GetTableByConvention());

            if (!string.IsNullOrWhiteSpace(candidateKey))
            {
                candidateKey += "_id";
            }

            candidateKey = candidateKey ?? "";

            return(Sanitizer.SanitizeIdentifierName(candidateKey));
        }
Esempio n. 12
0
        private string GetLookupField()
        {
            string candidateKey = Inflector.MakeSingular(this._ObjectName);

            if (!string.IsNullOrWhiteSpace(candidateKey))
            {
                candidateKey += "_code";
            }

            candidateKey = candidateKey ?? "";

            return(Sanitizer.SanitizeIdentifierName(candidateKey));
        }
Esempio n. 13
0
        // SchemaReader.ReadSchema
        public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
        {
            var result = new Tables();

            _connection = connection;
            _factory    = factory;

            var cmd = _factory.CreateCommand();

            cmd.Connection  = connection;
            cmd.CommandText = TABLE_SQL;
            cmd.GetType().GetProperty("BindByName").SetValue(cmd, true, null);
            cmd.GetType().GetProperty("InitialLONGFetchSize").SetValue(cmd, -1, null);

            //pull the tables in a reader
            using (cmd)
            {
                using (var rdr = cmd.ExecuteReader())
                {
                    while (rdr.Read())
                    {
                        Table tbl = new Table();
                        tbl.Name      = rdr["TABLE_NAME"].ToString();
                        tbl.Schema    = rdr["TABLE_SCHEMA"].ToString();
                        tbl.IsView    = string.Compare(rdr["TABLE_TYPE"].ToString(), "View", true) == 0;
                        tbl.CleanName = CleanUp(tbl.Name);
                        tbl.ClassName = Inflector.MakeSingular(tbl.CleanName);
                        result.Add(tbl);
                    }
                }
            }

            foreach (var tbl in result)
            {
                tbl.Columns = LoadColumns(tbl);

                // Mark the primary key
                string PrimaryKey = GetPK(tbl.Name);
                var    pkColumn   = tbl.Columns.SingleOrDefault(x => x.Name.ToLower().Trim() == PrimaryKey.ToLower().Trim());
                if (pkColumn != null)
                {
                    pkColumn.IsPK = true;
                }
            }


            return(result);
        }
Esempio n. 14
0
    // SchemaReader.ReadSchema
    public override Tables ReadSchema(DbConnection connection, DbProviderFactory factory)
    {
        var result = new Tables();

        _connection = connection;
        _factory    = factory;

        var cmd = _factory.CreateCommand();

        cmd.Connection  = connection;
        cmd.CommandText = TABLE_SQL;

        //pull the tables in a reader
        using (cmd)
        {
            using (var rdr = cmd.ExecuteReader())
            {
                while (rdr.Read())
                {
                    Table tbl = new Table();
                    tbl.Name      = rdr["TABLE_NAME"].ToString();
                    tbl.CleanName = CleanUp(tbl.Name);
                    tbl.ClassName = Inflector.MakeSingular(tbl.CleanName);
                    tbl.Schema    = null;
                    tbl.IsView    = false;
                    result.Add(tbl);
                }
            }
        }

        foreach (var tbl in result)
        {
            tbl.Columns = LoadColumns(tbl);

            // Mark the primary key
            string PrimaryKey = GetPK(tbl.Name);
            var    pkColumn   = tbl.Columns.SingleOrDefault(x => x.Name.ToLower().Trim() == PrimaryKey.ToLower().Trim());
            if (pkColumn != null)
            {
                pkColumn.IsPK = true;
            }
        }


        return(result);
    }
Esempio n. 15
0
        private HttpClient GetHttpClient()
        {
            var contentType = BuildJsonMimeType(Inflector.MakeSingular(Resource.Name));

            var client = new HttpClient
            {
                Timeout = new TimeSpan(0, 0, 5, 0), BaseAddress = new Uri(Configuration.Url)
            };

            client.DefaultRequestHeaders.Accept.Clear();

            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Bearer", TokenHandler.GetBearerToken());

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));

            return(client);
        }
Esempio n. 16
0
 /// <summary>
 /// Plurals to singular.
 /// </summary>
 /// <param name="sourceString">The source string.</param>
 /// <returns></returns>
 public static string PluralToSingular(string sourceString)
 {
     return(Inflector.MakeSingular(sourceString));
 }
Esempio n. 17
0
 public static string PluralToSingular(string sIn)
 {
     return(Inflector.MakeSingular(sIn));
 }