public void TriemEndTest()
 {
     StringBuilder sb;
     sb = new StringBuilder("asdfgef");
     Assert.Equal(sb.TrimEnd('a').ToString(), "asdfgef");
     Assert.Equal(sb.TrimEnd('f').ToString(), "asdfge");
     sb.Append("   ");
     Assert.Equal(sb.TrimEnd().ToString(), "asdfge");
     Assert.Equal(sb.TrimEnd(new[] { 'g', 'e' }).ToString(), "asdf");
     Assert.Equal(sb.TrimEnd("asdf").ToString(), string.Empty);
 }
 public void can_trim_end_of_stringbuffer()
 {
     var sb1 = new StringBuilder("foo1234   \r\n");
     var sb2 = new StringBuilder("foo1234");
     Assert.AreEqual("foo1234", sb1.TrimEnd().ToString());
     Assert.AreEqual("foo1234", sb2.TrimEnd().ToString());
 }
 public void can_trim_character_end_of_stringbuffer()
 {
     var sb1 = new StringBuilder("foo1234");
     var sb2 = new StringBuilder("foo1233");
     Assert.AreEqual("foo123", sb1.TrimEnd('4').ToString());
     Assert.AreEqual("foo1233", sb2.TrimEnd('4').ToString());
 }
        public string ViewSql(Process process) {

            const string fieldSpacer = ",\r\n    ";
            var builder = new StringBuilder();
            var master = process.MasterEntity;
            var l = process.OutputConnection.L;
            var r = process.OutputConnection.R;

            builder.AppendLine("SELECT");
            builder.Append("    ");
            builder.Append(new FieldSqlWriter(master.OutputFields()).Alias(l, r).Prepend("m.").Write(fieldSpacer));

            foreach (var rel in process.Relationships) {
                var joinFields = rel.Fields();
                foreach (var field in rel.RightEntity.OutputFields()) {
                    if (!joinFields.HaveField(field.Alias)) {
                        builder.Append(fieldSpacer);
                        builder.Append(new FieldSqlWriter(new Fields(field)).Alias(l, r).Prepend("r" + rel.RightEntity.Index + ".").Write(fieldSpacer));
                    }
                }
            }

            builder.AppendLine();
            builder.Append("FROM ");
            builder.Append(l);
            builder.Append(master.OutputName());
            builder.Append(r);
            builder.Append(" m");

            foreach (var rel in process.Relationships) {
                builder.AppendLine();
                builder.Append("LEFT OUTER JOIN ");
                if (rel.RightEntity.IsMaster()) {
                    builder.Append("m");
                } else {
                    builder.Append(l);
                    builder.Append(rel.RightEntity.OutputName());
                    builder.Append(r);
                }
                builder.Append(" ");
                builder.Append("r");
                builder.Append(rel.RightEntity.Index);
                builder.Append(" ON (");
                foreach (var j in rel.Join) {
                    if (rel.LeftEntity.IsMaster()) {
                        builder.Append("m");
                    } else {
                        builder.Append("r");
                        builder.Append(rel.LeftEntity.Index);
                    }
                    builder.Append(".");
                    builder.Append(l);
                    builder.Append(j.LeftField.Alias);
                    builder.Append(r);
                    builder.Append(" = ");
                    builder.Append("r");
                    builder.Append(rel.RightEntity.Index);
                    builder.Append(".");
                    builder.Append(l);
                    builder.Append(j.RightField.Alias);
                    builder.Append(r);
                    builder.Append(" AND ");
                }
                builder.TrimEnd(" AND ");
                builder.Append(")");
            }

            builder.Append(";");
            return builder.ToString();

        }
        public string CreateSql(Process process) {
            var builder = new StringBuilder();
            builder.AppendFormat("CREATE VIEW {0} AS\r\n", process.OutputConnection.Enclose(process.Star));
            builder.AppendFormat("SELECT\r\n    d.TflKey,\r\n    d.TflBatchId,\r\n    b.TflUpdate,\r\n");

            var l = process.OutputConnection.L;
            var r = process.OutputConnection.R;

            var typedFields = new StarFields(process).TypedFields();
            builder.AppendLine(string.Concat(new FieldSqlWriter(typedFields[StarFieldType.Master]).Alias(l, r).PrependEntityOutput(process.OutputConnection, "d").Prepend("    ").Write(",\r\n"), ","));

            if (typedFields[StarFieldType.Foreign].Any())
                builder.AppendLine(string.Concat(new FieldSqlWriter(typedFields[StarFieldType.Foreign]).Alias(l, r).PrependEntityOutput(process.OutputConnection, "d").IsNull().ToAlias(l, r).Prepend("    ").Write(",\r\n"), ","));

            if (typedFields[StarFieldType.Other].Any())
                builder.AppendLine(string.Concat(new FieldSqlWriter(typedFields[StarFieldType.Other]).Alias(l, r).PrependEntityOutput(process.OutputConnection).IsNull().ToAlias(l, r).Prepend("    ").Write(",\r\n"), ","));

            builder.TrimEnd("\r\n,");
            builder.AppendLine();
            builder.AppendFormat("FROM {0} d\r\n", process.OutputConnection.Enclose(process.MasterEntity.OutputName()));
            builder.AppendFormat("INNER JOIN TflBatch b ON (d.TflBatchId = b.TflBatchId AND b.ProcessName = '{0}')\r\n", process.Name);

            foreach (var entity in process.Entities.Where(e => !e.IsMaster())) {
                builder.AppendFormat("LEFT OUTER JOIN {0} ON (", entity.OutputName());

                foreach (var join in entity.RelationshipToMaster.First().Join.ToArray()) {
                    builder.AppendFormat(
                        "d.{0} = {1}.{2} AND ",
                        process.OutputConnection.Enclose(join.LeftField.Alias),
                        entity.OutputName(),
                        process.OutputConnection.Enclose(join.RightField.Alias));
                }

                builder.TrimEnd(" AND ");
                builder.AppendLine(")");
            }

            builder.Append(";");
            return builder.ToString();
        }