public async Task TemplateEngineShouldUseSameNamingConventionForBinding() { var cacheProvider = new MemoryCacheProvider(); var handlerFactory = new Mock <IHelperHandlerFactory>(); handlerFactory.Setup(f => f.Create()).Returns(Enumerable.Empty <IHelperHandler>()); var namingRule = new NamingRule(); var schemaProvider = new HandlebarsViewSchemaProvider(null, new MemberLocatorFromNamingRule(namingRule)); var codeGenerator = new JsonSchemaCodeGenerator(namingRule); const string input = "<p>{{name}}</p><p>{{first_name}}</p>"; var templateInfo = new StringTemplateInfo("views/test", input); var schema = await schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false); var modelType = codeGenerator.Compile(schema); var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory.Object, namingRule); var view = await viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false); var model = Activator.CreateInstance(modelType); modelType.GetProperty("Name").SetValue(model, "{{name}}"); modelType.GetProperty("FirstName").SetValue(model, "{{first_name}}"); var writer = new StringWriter(); view.Render(model, new RenderingContext(writer)); var stringResult = writer.ToString(); Assert.AreEqual(input, stringResult); }
public bool TableExists(IDataContext db, string tableName) { if (db == null) { throw new ArgumentNullException("session"); } if (tableName == null) { throw new ArgumentNullException("tableName"); } if (!NamingRule.IsValidSqlName(tableName)) { throw new ArgumentOutOfRangeException("tableName"); } //检查连接 var sql = new SqlString( "select coalesce(count(table_name), 0) ", "from information_schema.tables ", "where table_type='BASE TABLE' and table_schema='dbo' and table_name=", Parameter.Placeholder); var n = Convert.ToInt32(db.QueryValue(sql, tableName)); return(n > 0); }
public void CreateTable(IDataContext db, string tableName, string label) { if (db == null) { throw new ArgumentNullException("session"); } if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("tableName"); } if (!NamingRule.IsValidSqlName(tableName)) { throw new ArgumentOutOfRangeException("tableName"); } LoggerProvider.EnvironmentLogger.Debug(String.Format("Creating Table [{0}]...", tableName)); tableName = tableName.SqlEscape(); var sb = new SqlStringBuilder(); sb.Add("create table ["); sb.Add(tableName); sb.Add("] ("); sb.Add("[_id] bigint not null identity(1,1), "); sb.Add("primary key([_id]))"); var sql = sb.ToSqlString(); db.Execute(sql); //TODO // SetTableComment(db, tableName, label); }
public void AddFK(IDataContext db, string columnName, string refTable, OnDeleteAction act) { if (db == null) { throw new ArgumentNullException("session"); } if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } if (string.IsNullOrEmpty(refTable)) { throw new ArgumentNullException("refTable"); } var onDelete = OnDeleteMapping[act]; var fkName = this.GenerateFkName(columnName); var sql = string.Format(CultureInfo.InvariantCulture, "alter table [{0}] add constraint [{1}] foreign key ([{2}]) references [{3}] on delete {4}", this.Name, fkName, columnName, refTable, onDelete); db.Execute(SqlString.Parse(sql)); }
private void LoadColumns(IDataContext db, string tableName) { if (db == null) { throw new ArgumentNullException("session"); } if (string.IsNullOrEmpty(tableName)) { throw new ArgumentNullException("tableName"); } if (!NamingRule.IsValidSqlName(tableName)) { throw new ArgumentOutOfRangeException("tableName"); } var sql = new SqlString( "select column_name, data_type, is_nullable, character_maximum_length ", "from information_schema.columns ", "where table_name=", Parameter.Placeholder, " ", "order by ordinal_position"); var records = db.QueryAsDictionary(sql, tableName); this.columns.Clear(); foreach (var r in records) { var column = new MssqlColumnMetadata(r); this.columns.Add(column.Name, column); } }
public void AlterColumnNullable(IDataContext db, string columnName, bool nullable) { if (db == null) { throw new ArgumentNullException("session"); } if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } //TODO //DO nothing /* * var sql = string.Format(CultureInfo.InvariantCulture, * "alter table [{0}] alter column [{1}] {2}", * this.Name, columnName, sqlType); * db.Execute(SqlString.Parse(sql)); */ }
private State(TService service, SemanticDocument document, NamingRule fieldNamingRule, NamingRule propertyNamingRule, NamingRule parameterNamingRule) { _service = service; _document = document; _fieldNamingRule = fieldNamingRule; _propertyNamingRule = propertyNamingRule; _parameterNamingRule = parameterNamingRule; }
public void TestCase70925() { var rule = new NamingRule(AffectedEntity.Field); rule.NamingStyle = NamingStyle.PascalCase; System.Collections.Generic.IList <string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext(null, TextLocation.Empty, null), "_taskStatus", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("TaskStatus")); }
public void TestSuggestionForPascalCase() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.PascalCase; System.Collections.Generic.IList <string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext(null, TextLocation.Empty, null), "pascalCase_12_____12323", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("PascalCase_12_12323")); }
public void TestSuggestionForPascalCaseWithLowerStart() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.PascalCaseWithLowerLetterUnderscore; System.Collections.Generic.IList <string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext(null, TextLocation.Empty, null), "PascalCase_UnderscoreTolerant", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("PascalCase_underscoreTolerant")); }
public void TestCamelCase() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.CamelCase; Assert.IsFalse(rule.IsValid("PascalCase")); Assert.IsFalse(rule.IsValid("camel_Case")); Assert.IsTrue(rule.IsValid("camelCase")); Assert.IsTrue(rule.IsValid("camelCase_10_11")); }
public void TestFirstUpper() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.FirstUpper; Assert.IsFalse(rule.IsValid("PascalCase")); Assert.IsFalse(rule.IsValid("camelCase")); Assert.IsTrue(rule.IsValid("First_upper")); Assert.IsTrue(rule.IsValid("Firstupper")); }
public void UnderscoreTolerantCamelCaseWithUpperStart() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.CamelCaseWithUpperLetterUnderscore; Assert.IsFalse(rule.IsValid("PascalCase")); Assert.IsFalse(rule.IsValid("camelCase_underscoreTolerant")); Assert.IsFalse(rule.IsValid("camelCase__UnderscoreTolerant")); Assert.IsTrue(rule.IsValid("camelCase_UnderscoreTolerant")); }
public void TestAllLower() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.AllLower; Assert.IsFalse(rule.IsValid("PascalCase")); Assert.IsFalse(rule.IsValid("camelCase")); Assert.IsTrue(rule.IsValid("all_lower")); Assert.IsTrue(rule.IsValid("alllower")); }
public void TestAllUpper() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.AllUpper; Assert.IsFalse(rule.IsValid("PascalCase")); Assert.IsFalse(rule.IsValid("camelCase")); Assert.IsTrue(rule.IsValid("ALL_UPPER")); Assert.IsTrue(rule.IsValid("ALLUPPER")); }
private State(TService service, SemanticDocument document, NamingRule fieldNamingRule, NamingRule propertyNamingRule, NamingRule parameterNamingRule) { _service = service; _document = document; _fieldNamingRule = fieldNamingRule; _propertyNamingRule = propertyNamingRule; _parameterNamingRule = parameterNamingRule; ParameterToNewFieldMap = ImmutableDictionary <string, string> .Empty; ParameterToNewPropertyMap = ImmutableDictionary <string, string> .Empty; }
private State(TService service, SemanticDocument document, NamingRule fieldNamingRule, NamingRule propertyNamingRule, NamingRule parameterNamingRule, CodeAndImportGenerationOptionsProvider fallbackOptions) { _service = service; _document = document; _fieldNamingRule = fieldNamingRule; _propertyNamingRule = propertyNamingRule; _parameterNamingRule = parameterNamingRule; ParameterToNewFieldMap = ImmutableDictionary <string, string> .Empty; ParameterToNewPropertyMap = ImmutableDictionary <string, string> .Empty; _fallbackOptions = fallbackOptions; }
public NamingStyleSetting( NamingRule namingRule, NamingStyle[] allStyles, NamingStyleSettingsUpdater settingsUpdater, string?fileName = null) { Style = namingRule.NamingStyle; _allStyles = allStyles; Type = namingRule.SymbolSpecification; Severity = namingRule.EnforcementLevel; _settingsUpdater = settingsUpdater; Location = new SettingLocation(fileName is null ? LocationKind.VisualStudio : LocationKind.EditorConfig, fileName); }
private string GetEventHandlerName( IEventSymbol eventSymbol, SyntaxToken plusEqualsToken, SemanticModel semanticModel, ISyntaxFactsService syntaxFactsService, NamingRule namingRule) { AssertIsBackground(); var objectPart = GetNameObjectPart(eventSymbol, plusEqualsToken, semanticModel, syntaxFactsService); var basename = namingRule.NamingStyle.CreateName(ImmutableArray.Create( string.Format("{0}_{1}", objectPart, eventSymbol.Name))); var reservedNames = semanticModel.LookupSymbols(plusEqualsToken.SpanStart).Select(m => m.Name); return NameGenerator.EnsureUniqueness(basename, reservedNames); }
private string GenerateFkName(string columnName) { if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } return(string.Format(CultureInfo.InvariantCulture, "{0}_{1}_fkey", this.Name, columnName)); }
public IColumnMetadata GetColumn(string columnName) { if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } return(this.columns[columnName]); }
public bool ColumnExists(string columnName) { if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } return(this.columns.ContainsKey(columnName)); }
public ParameterName(string nameBasedOnArgument, bool isFixed, NamingRule parameterNamingRule) { NameBasedOnArgument = nameBasedOnArgument; if (isFixed) { // If the parameter name is fixed, we have to accept it as is. BestNameForParameter = NameBasedOnArgument; } else { // Otherwise, massage it a bit to be a more suitable match for // how people actually writing parameters. BestNameForParameter = parameterNamingRule.NamingStyle.MakeCompliant(nameBasedOnArgument).First(); } }
public ParameterName(string nameBasedOnArgument, bool isFixed, NamingRule parameterNamingRule) { NameBasedOnArgument = nameBasedOnArgument; if (isFixed) { // If the parameter name is fixed, we have to accept it as is. BestNameForParameter = NameBasedOnArgument; } else { // Otherwise, massage it a bit to be a more suitable match for // how people actually writing parameters. var trimmed = nameBasedOnArgument.TrimStart('_'); BestNameForParameter = trimmed.Length > 0 ? trimmed.ToCamelCase() : nameBasedOnArgument; BestNameForParameter = parameterNamingRule.NamingStyle.MakeCompliant(BestNameForParameter).First(); } }
public static ImmutableArray <ParameterName> GenerateParameterNames( this SemanticModel semanticModel, IEnumerable <ArgumentSyntax> arguments, IList <string> reservedNames, NamingRule parameterNamingRule, CancellationToken cancellationToken) { reservedNames ??= SpecializedCollections.EmptyList <string>(); // We can't change the names of named parameters. Any other names we're flexible on. var isFixed = reservedNames.Select(s => true).Concat( arguments.Select(a => a.NameColon != null)).ToImmutableArray(); var parameterNames = reservedNames.Concat( arguments.Select(a => semanticModel.GenerateNameForArgument(a, cancellationToken))).ToImmutableArray(); return(GenerateNames(reservedNames, isFixed, parameterNames, parameterNamingRule)); }
private async Task <string> ExecuteServerSide(string testName, string templateFile, string dataFile) { var cacheProvider = new NullCacheProvider(); var namingRule = new NamingRule(); var handlerFactory = new NullRenderingHelperHandlerFactory(); var config = ConfigurationLoader.LoadNitroConfiguration(Path.Combine(TestContext.DeploymentDirectory, "Basic")); var templateInfo = new FileTemplateInfo(testName, TemplateType.View, PathInfo.Create(templateFile), new FileSystem(config)); var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory, namingRule); IView view = await viewEngine.CreateViewAsync(templateInfo).ConfigureAwait(false); if (view == null) { Assert.Fail("Could not create view from file'{0}'.", templateFile); } object model; using (var reader = new StreamReader(dataFile)) { model = new JsonSerializer().Deserialize(reader, typeof(Dictionary <string, object>)); } if (TestContext.Properties.Contains("$LoadTestUserContext")) { this.TestContext.BeginTimer("Server"); } var builder = new StringBuilder(); using (var writer = new StringWriterDelayed(builder)) { view.Render(model, new RenderingContext(writer)); } var resultString = builder.ToString(); if (TestContext.Properties.Contains("$LoadTestUserContext")) { this.TestContext.EndTimer("Server"); } return(resultString); }
private ImmutableArray <ParameterName> GenerateParameterNames( SemanticDocument document, IEnumerable <Argument> arguments, IList <string> reservedNames, NamingRule parameterNamingRule, CancellationToken cancellationToken ) { reservedNames ??= SpecializedCollections.EmptyList <string>(); // We can't change the names of named parameters. Any other names we're flexible on. var isFixed = reservedNames .Select(s => true) .Concat(arguments.Select(a => a.IsNamed)) .ToImmutableArray(); var parameterNames = reservedNames .Concat( arguments.Select( a => this.GenerateNameForArgument( document.SemanticModel, a, cancellationToken ) ) ) .ToImmutableArray(); var syntaxFacts = document.Document.GetRequiredLanguageService <ISyntaxFactsService>(); var comparer = syntaxFacts.StringComparer; return(NameGenerator .EnsureUniqueness( parameterNames, isFixed, canUse: s => !reservedNames.Any(n => comparer.Equals(s, n)) ) .Select( (name, index) => new ParameterName(name, isFixed[index], parameterNamingRule) ) .Skip(reservedNames.Count) .ToImmutableArray()); }
public void TestClassNameNormalization() { var inputs = new List <Tuple <string, string> > { new Tuple <string, string>(null, null), new Tuple <string, string>("class", "Class"), new Tuple <string, string>("person info", "PersonInfo"), new Tuple <string, string>("person", "Person"), new Tuple <string, string>("Person", "Person"), new Tuple <string, string>("person_info", "PersonInfo"), new Tuple <string, string>("SimpleClass", "SimpleClass"), }; foreach (var input in inputs) { var result = new NamingRule().GetPropertyName(input.Item1); Assert.AreEqual(input.Item2, result); } }
private async Task <string> ExecuteServerSideStrongModel(string testName, string templateFile, string dataFile) { var cacheProvider = new NullCacheProvider(); var namingRule = new NamingRule(); var handlerFactory = new NullRenderingHelperHandlerFactory(); var templateInfo = new FileTemplateInfo(testName, PathInfo.Create(templateFile), new FileSystem()); var schemaProvider = new HandlebarsViewSchemaProvider(handlerFactory, new MemberLocatorFromNamingRule(namingRule)); var generator = new JsonSchemaCodeGenerator(namingRule); var schema = await schemaProvider.GetSchemaFromTemplateAsync(templateInfo).ConfigureAwait(false); schema.Title = "Model"; var modelType = generator.Compile(schema); var viewEngine = new VeilViewEngine(cacheProvider, handlerFactory, namingRule); var view = await viewEngine.CreateViewAsync(templateInfo, modelType).ConfigureAwait(false); if (view == null) { Assert.Fail("Could not create view from file '{0}'.", templateFile); } object model; using (var reader = new JsonTextReader(new StreamReader(dataFile))) { model = JsonSerializer.Create().Deserialize(reader, modelType); } this.TestContext.BeginTimer("ServerStrong"); var builder = new StringBuilder(); using (var writer = new StringWriterDelayed(builder)) { view.Render(model, new RenderingContext(writer)); } var resultString = builder.ToString(); this.TestContext.EndTimer("ServerStrong"); return(resultString); }
public void DeleteFK(IDataContext db, string columnName) { if (db == null) { throw new ArgumentNullException("session"); } if (string.IsNullOrEmpty(columnName)) { throw new ArgumentNullException("columnName"); } if (!NamingRule.IsValidSqlName(columnName)) { throw new ArgumentOutOfRangeException("columnName"); } var fkName = this.GenerateFkName(columnName); this.DeleteConstraint(db, fkName); }
internal NameConventionRule (NamingRule wrappedRule) { this.wrappedRule = wrappedRule; }
public void TestCase70925() { var rule = new NamingRule(AffectedEntity.Field); rule.NamingStyle = NamingStyle.PascalCase; System.Collections.Generic.IList<string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext (null, TextLocation.Empty, null), "_taskStatus", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("TaskStatus")); }
public void TestSuggestionForPascalCase() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.PascalCase; System.Collections.Generic.IList<string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext (null, TextLocation.Empty, null), "pascalCase_12_____12323", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("PascalCase_12_12323")); }
public void TestSuggestionForPascalCaseWithLowerStart() { var rule = new NamingRule(AffectedEntity.Class); rule.NamingStyle = NamingStyle.PascalCaseWithLowerLetterUnderscore; System.Collections.Generic.IList<string> suggestedNames; rule.GetErrorMessage(new TestRefactoringContext (null, TextLocation.Empty, null), "PascalCase_UnderscoreTolerant", out suggestedNames); Assert.IsTrue(suggestedNames.Contains("PascalCase_underscoreTolerant")); }