public void StringToUnderscoreTest() { var actual = NamingConventions.Underscore("HelloWorld"); var expected = "hello_world"; Assert.AreEqual(expected, actual); }
public void VariantStringToDashedTest() { var actual = NamingConventions.Dashed("abcID"); var expected = "abc-id"; Assert.AreEqual(expected, actual); }
public void UpperStringToDashedTest() { var actual = NamingConventions.Dashed("TEST"); var expected = "test"; Assert.AreEqual(expected, actual); }
public void StringWithNumbersToDashedTest() { var actual = NamingConventions.Dashed("1Test123F5"); var expected = "1-test123-f5"; Assert.AreEqual(expected, actual); }
public void StringToCamelCaseTest() { var actual = NamingConventions.CamelCase("HelloWorld"); var expected = "helloWorld"; Assert.AreEqual(expected, actual); }
public async Task Should_Be_Able_To_Subscibe_To_Pure_Json_Message() { var conventions = new NamingConventions(); using (var client = TestClientFactory.CreateNormal(ioc => ioc.AddSingleton <INamingConventions>(c => conventions))) { /* Setup */ var tcs = new TaskCompletionSource <BasicMessage>(); var subscription = client.SubscribeAsync <BasicMessage>((message, context) => { tcs.TrySetResult(message); return(Task.FromResult(true)); }); var uniqueValue = Guid.NewGuid().ToString(); var jsonMsg = JsonConvert.SerializeObject(new BasicMessage { Prop = uniqueValue }); /* Test */ TestChannel.BasicPublish( conventions.ExchangeNamingConvention(typeof(BasicMessage)), conventions.QueueNamingConvention(typeof(BasicMessage)), true, null, Encoding.UTF8.GetBytes(jsonMsg)); await tcs.Task; /* Assert */ Assert.Equal(uniqueValue, tcs.Task.Result.Prop); } }
public void CapsStringToCamelCaseTest() { var actual = NamingConventions.CamelCase("ID"); var expected = "id"; Assert.AreEqual(expected, actual); }
public async Task Should_Be_Able_To_Get_BasicGetResult_Message() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); var queueName = conventions.QueueNamingConvention(message.GetType()); TestChannel.QueueDeclare(queueName, true, false, false, null); TestChannel.ExchangeDeclare(exchangeName, ExchangeType.Topic); TestChannel.QueueBind(queueName, exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetAsync(cfg => cfg.FromQueue(queueName)); /* Assert */ Assert.NotNull(ackable); Assert.NotEmpty(ackable.Content.Body); TestChannel.QueueDelete(queueName); TestChannel.ExchangeDelete(exchangeName); } }
public async Task Should_Be_Able_To_Get_Message_When_Batch_Size_Is_Smaller_Than_Queue_Length() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null); TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic); TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), conventions.ExchangeNamingConvention(message.GetType()), conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetManyAsync <BasicMessage>(2); TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType())); TestChannel.ExchangeDelete(exchangeName); /* Assert */ Assert.NotNull(ackable); Assert.Equal(ackable.Content.Count, 2); } }
public JsonExtensionMemberInfo(string memberName, Type memberType, NamingConventions namingConvention, bool excludeNulls) { MemberName = memberName; MemberType = memberType; NamingConvention = namingConvention; ExcludeNulls = excludeNulls; }
public void StringToDashedTest() { var actual = NamingConventions.Dashed("HelloWorld"); var expected = "hello-world"; Assert.AreEqual(expected, actual); }
public async Task Should_Be_Able_To_Ack_Messages_And_Then_Full_List() { using (var client = ZyRabbitFactory.CreateTestClient()) { /* Setup */ var message = new BasicMessage { Prop = "Get me, get it?" }; var conventions = new NamingConventions(); var exchangeName = conventions.ExchangeNamingConvention(message.GetType()); TestChannel.QueueDeclare(conventions.QueueNamingConvention(message.GetType()), true, false, false, null); TestChannel.ExchangeDeclare(conventions.ExchangeNamingConvention(message.GetType()), ExchangeType.Topic); TestChannel.QueueBind(conventions.QueueNamingConvention(message.GetType()), exchangeName, conventions.RoutingKeyConvention(message.GetType()) + ".#"); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); await client.PublishAsync(message, ctx => ctx.UsePublishConfiguration(cfg => cfg.OnExchange(exchangeName))); /* Test */ var ackable = await client.GetManyAsync <BasicMessage>(3); ackable.Content[1].Ack(); ackable.Ack(); TestChannel.QueueDelete(conventions.QueueNamingConvention(message.GetType())); TestChannel.ExchangeDelete(exchangeName); /* Assert */ Assert.True(true); } }
public static void Map(ClientModel model, IMapperContext context) { var entities = new List <EntityIdDescriptor>(); foreach (var entity in model.Entities) { var fields = new List <ScalarEntityIdDescriptor>(); foreach (var field in entity.Fields) { if (field.Type.NamedType() is ILeafType leafType) { fields.Add( new ScalarEntityIdDescriptor( field.Name, leafType.Name, model.Schema.GetOrCreateTypeInfo(leafType.GetSerializationType()))); } } entities.Add( new EntityIdDescriptor(entity.Name, entity.Name, fields)); } context.Register( new EntityIdFactoryDescriptor( context.ClientName + "EntityIdFactory", entities, NamingConventions.CreateStateNamespace(context.Namespace))); }
protected override CSharpSyntaxGeneratorResult Generate( InputObjectTypeDescriptor descriptor, CSharpSyntaxGeneratorSettings settings) { string name = NamingConventions.CreateInputValueInfo(descriptor.Name); InterfaceDeclarationSyntax interfaceDeclaration = SyntaxFactory.InterfaceDeclaration(name) .AddModifiers(SyntaxFactory.Token(SyntaxKind.InternalKeyword)) .AddGeneratedAttribute(); foreach (var prop in descriptor.Properties) { interfaceDeclaration = interfaceDeclaration.AddMembers( SyntaxFactory.PropertyDeclaration( SyntaxFactory.ParseTypeName(TypeNames.Boolean), NamingConventions.CreateIsSetProperty(prop.Name)) .WithGetter()); } return(new( name, State, $"{descriptor.RuntimeType.NamespaceWithoutGlobal}.{State}", interfaceDeclaration)); }
public ComputedPropertyInfo(NamingConventions conventions, TypeInfo owner, string name, string type, bool cached, IEnumerable <string> dependsOn, string formula) : base(conventions, owner, name, type, false, false) { Cached = cached; DependsOn.AddRange(dependsOn); Formula = (formula == "" ? null : formula); Getter = new MethodInfo(GetGetterName(), TypeName); Setter = null; LazyInitializer = null; validator = null; if (Cached) { FieldName = FieldName + "Cache"; ValidFieldName = FieldName + "Valid"; Cacher = new MethodInfo(GetCacherName(), TypeName); Invalidate = new MethodInfo(GetInvalidateName()); } else { FieldName = null; ValidFieldName = null; Cacher = Getter; Invalidate = null; } }
public ComputedPropertyInfo(NamingConventions conventions, TypeInfo owner, string name, string type, bool cached, IEnumerable<string> dependsOn, string formula) : base(conventions, owner, name, type, false, false) { Cached = cached; DependsOn.AddRange(dependsOn); Formula = (formula == "" ? null : formula); Getter = new MethodInfo(GetGetterName(), TypeName); Setter = null; LazyInitializer = null; validator = null; if (Cached) { FieldName = FieldName + "Cache"; ValidFieldName = FieldName + "Valid"; Cacher = new MethodInfo(GetCacherName(), TypeName); Invalidate = new MethodInfo(GetInvalidateName()); } else { FieldName = null; ValidFieldName = null; Cacher = Getter; Invalidate = null; } }
public Task <IActionResult> Validate([FromBody] SubmitValidatorBody body) { if (body.ValidatorDefinition == null) { return(Task.FromResult <IActionResult>(BadRequest("Validator definition is null"))); } if (!NamingConventions.IsValidDataType(body.ValidatorDefinition.DataType)) { return(Task.FromResult <IActionResult>(BadRequest($"Data type '{body.ValidatorDefinition.DataType}' is not a valid name for a collection"))); } if (body.ValidatorDefinition.ValidatorType != ValidatorType.TextRules) { return(Task.FromResult <IActionResult>(StatusCode((int)HttpStatusCode.Forbidden, "Currently only text rule validators are supported"))); } if (body.ValidatorDefinition.ValidatorType == ValidatorType.Exe) { return(Task.FromResult <IActionResult>(StatusCode((int)HttpStatusCode.Forbidden, "Exe-validators are currently rejected because of security concerns."))); } var rulesetValidationResult = validatorManager.ValidateValidatorDefinition(body.ValidatorDefinition); return(Task.FromResult <IActionResult>(new ContentResult { ContentType = Conventions.JsonContentType, Content = JsonConvert.SerializeObject(rulesetValidationResult), StatusCode = (int)HttpStatusCode.OK })); }
protected virtual string GetMethodName(bool isRemote) { var sb = new StringBuilder(); bool isFirst = true; if (IsType(SearchCriteriaType.ForeignKey)) { foreach (AssociationProperty associationProperty in ForeignProperties) { if (isFirst) { isFirst = false; sb.AppendFormat(Configuration.Instance.SearchCriteriaProperty.Prefix, NamingConventions.CleanEscapeSystemType(Association.ForeignEntity.Name)); } else { sb.Append(Configuration.Instance.SearchCriteriaProperty.Delimeter); } if (isRemote) { sb.Append(NamingConventions.CleanEscapeSystemType(associationProperty.ForeignProperty.Name)); } else { sb.Append(NamingConventions.CleanEscapeSystemType(associationProperty.Property.Name)); } } sb.Append(Configuration.Instance.SearchCriteriaProperty.Suffix); } else if (IsType(SearchCriteriaType.PrimaryKey) && !String.IsNullOrEmpty(Configuration.Instance.SearchCriteriaProperty.MethodKeySuffix)) { sb.Append(Configuration.Instance.SearchCriteriaProperty.Prefix); sb.Append(Configuration.Instance.SearchCriteriaProperty.MethodKeySuffix); } else // Handle anything not a ForeignKey. { foreach (IProperty member in Properties) { if (isFirst) { isFirst = false; sb.AppendFormat(Configuration.Instance.SearchCriteriaProperty.Prefix, NamingConventions.CleanEscapeSystemType(member.Entity.Name)); } else { sb.Append(Configuration.Instance.SearchCriteriaProperty.Delimeter); } sb.Append(member.Name); } sb.Append(Configuration.Instance.SearchCriteriaProperty.Suffix); } return(sb.ToString()); }
/// <summary> /// Do any Post constructor initialization here. /// By default, this does nothing. /// </summary> public override void Initialize() { AssociationKeyName = AssociationSource.Name; if (String.IsNullOrEmpty(Namespace)) { Namespace = NamingConventions.PropertyName(AssociationSource.Database.Name); } }
public ComponentInfo(NamingConventions conventions, TypeInfo owner, string name, string type, bool lazy) : base(conventions, owner, name, type, !lazy, lazy) { Setter = null; WithSetter = null; ReadOnly = false; // !lazy; <= Needed for serialization DefaultValue = "new " + type + "()"; }
private string GetPrefix(NamingConventions namingConvention) { if ((namingConvention & NamingConventions.Underscore) == NamingConventions.Underscore) { return "_"; } return null; }
public static void Map( ClientModel model, IMapperContext context) { context.Register( new StoreAccessorDescriptor( NamingConventions.CreateStoreAccessor(context.ClientName), NamingConventions.CreateStateNamespace(context.Namespace))); }
protected virtual string ResolveAssociationName(bool preserveSuffix = false) { string name; List <string> properties; // Resolve the association name from the association's relationship. if (AssociationType == AssociationType.ManyToMany && IntermediaryAssociation != null) { bool result = !IntermediaryAssociation.ForeignEntity.Name.Equals(ForeignEntity.Name, StringComparison.OrdinalIgnoreCase); name = result ? IntermediaryAssociation.ForeignEntity.Name : IntermediaryAssociation.Entity.Name; properties = result ? IntermediaryAssociation.Properties.Select(p => NamingConventions.RemoveId(p.ForeignProperty.Name)).ToList() : IntermediaryAssociation.Properties.Select(p => NamingConventions.RemoveId(p.Property.Name)).ToList(); } else { name = ForeignEntity.Name; properties = IsToMany ? Properties.Select(p => NamingConventions.RemoveId(p.ForeignProperty.Name)).ToList() : Properties.Select(p => NamingConventions.RemoveId(p.Property.Name)).ToList(); } if (_makeUnique) { name = String.Concat(String.Join(String.Empty, properties), name); } if (preserveSuffix) { return(name); } // update the suffixes. if (IsToMany) { switch (Configuration.Instance.NamingProperty.AssociationNaming) { case AssociationNaming.List: name += Configuration.Instance.ListSuffix; break; case AssociationNaming.SingularList: name = String.Format("{0}{1}", StringUtil.ToPascalCase(StringUtil.ToSingular(name)), Configuration.Instance.ListSuffix); break; case AssociationNaming.Plural: name = StringUtil.ToPascalCase(StringUtil.ToPlural(name)); break; case AssociationNaming.Singular: name = StringUtil.ToPascalCase(StringUtil.ToSingular(name)); break; } } else { name = StringUtil.ToPascalCase(StringUtil.ToSingular(name)); } return(name); }
public PropertyMember(IMember parent, PropertyInfo property) { this.Parent = parent; this.Symbol = Symbol.Undefined; this.aProperty = property; this.aConventions = null; }
/// <summary> /// Return naming convention. /// </summary> /// <param name="conventionId"> /// The convention id. /// </param> /// <returns> /// The <see cref="INamingConvention"/>. /// </returns> public static INamingConvention ReturnNamingConvention(Guid conventionId) { if (NamingConventions == null || !NamingConventions.Any()) { return(null); } return(NamingConventions.FirstOrDefault( d => d.Metadata["ValueMetaData"].ToString().ToLower() == conventionId.ToString().ToLower()).Value); }
public PropertyMember(IMember parent, Symbol symbol, PropertyInfo property, NamingConventions conventions) { this.Parent = parent; this.Symbol = symbol; this.aProperty = property; this.aConventions = conventions; }
public FieldMember(IMember parent, FieldInfo field) { this.Parent = parent; this.Symbol = Symbol.Undefined; this.aField = field; this.aConventions = null; }
public FieldMember(IMember parent, Symbol symbol, FieldInfo field, NamingConventions conventions) { this.Parent = parent; this.Symbol = symbol; this.aField = field; this.aConventions = conventions; }
public void Should_Be_Able_To_Get_Application_Name_From_Console_App_Or_Service() { /* Setup */ var consoleAppUrl = @"\""Services\\Micro.Services.MagicMaker\\bin\\Micro.Services.MagicMaker.exe\"" "; /* Test */ var consoleAppRes = NamingConventions.GetApplicationName(consoleAppUrl); /* Assert */ Assert.Equal(expected: "micro_services_magicmaker", actual: consoleAppRes); }
public void Should_Be_Able_To_Get_Application_Name_From_IIS_Hosted_App_With_Host_Flag() { /* Setup */ var iisHostedApp = @"""c:\\windows\\system32\\inetsrv\\w3wp.exe -ap \""Application.Name\"" -v \""v4.0\"" -l \""webengine4.dll\"" -a \\\\.\\pipe\\iisipm6866bb0f-a36a-49b2-9ea8-d83ca69e873d -h \""C:\\inetpub\\temp\\apppools\\voyager_dk\\voyager_dk.config\"" -w \""\"" -m 0 -t 20 -ta 0"""; /* Test */ var iisHostedAppRes = NamingConventions.GetApplicationName(iisHostedApp); /* Assert */ Assert.Equal(expected: "application_name", actual: iisHostedAppRes); }
public string ApplyConventions(NamingConventions namingConvention) { var sb = new StringBuilder(GetPrefix(namingConvention)); if ((namingConvention & NamingConventions.CamelCase) == NamingConventions.CamelCase) { sb.Append(GetCamelCase()); } return sb.ToString(); }
public MethodMember(IMember parent, Symbol symbol, MethodInfo getMethod, MethodInfo setMethod, NamingConventions conventions) { this.Parent = parent; this.Symbol = symbol; this.aSetMethod = setMethod; this.aGetMethod = getMethod; this.aConventions = conventions; }
public MethodMember(IMember parent, MethodInfo getMethod, MethodInfo setMethod) { this.Parent = parent; this.Symbol = Symbol.Undefined; this.aSetMethod = setMethod; this.aGetMethod = getMethod; this.aConventions = null; }
public static void SetObjectNamingConvention(int type) { if (type > 2 || type < 1) { throw new Exception("Value cannot be more than 2 and less than 1 as of now."); } switch (type) { case 1: ObjectNamingConvention = NamingConventions.UnderScoreCase; break; case 2: ObjectNamingConvention = NamingConventions.PascalCase; break; } }
public CollectionInfo(NamingConventions conventions, TypeInfo owner, string name, string contents, bool lazy, bool readOnly) : base(conventions, owner, name, "ObservableList<" + contents + ">", false, lazy) { Contract.Requires(!string.IsNullOrEmpty(contents)); ContentsType = new BaseFieldInfo(conventions, "Items", contents); Contents = contents; ReadOnly = false; // !lazy; <= Needed for serializationa ExposeAsReadOnly = readOnly; Setter = null; WithSetter = null; validator = null; Getter.TypeName = ExposedTypeName; }
public BaseFieldInfo(NamingConventions conventions, string name, string type) { Contract.Requires(StringUtils.IsValidVariableName(name)); Contract.Requires(StringUtils.IsValidTypeName(type)); Contract.Ensures(StringUtils.IsValidVariableName(Name)); Contract.Ensures(StringUtils.IsValidVariableName(PrivateName)); Contract.Ensures(StringUtils.IsValidVariableName(VarName)); Contract.Ensures(StringUtils.IsValidTypeName(TypeName)); Contract.Ensures(StringUtils.IsValidVariableName(DefineName)); Name = name; FieldName = PrivateName = conventions.ToFieldName(name); VarName = conventions.ToVarName(name); TypeName = type; DefineName = conventions.ToDefineName(name); ReadOnly = false; }
public PropertyInfo(NamingConventions conventions, TypeInfo owner, string name, string type, bool required, bool lazy) : base(conventions, name, type) { Owner = owner; Required = required; Lazy = lazy; string getter = GetGetterName(); if (getter != null) Getter = new MethodInfo(getter, TypeName); string setter = GetSetterName(); if (setter != null) Setter = new MethodInfo(setter, "bool", TypeName); string withSetter = GetWithSetterName(); if (withSetter != null) WithSetter = new MethodInfo(withSetter, owner.Name, TypeName); string lazyIntializer = GetLazyInitializerName(); if (lazyIntializer != null) LazyInitializer = new MethodInfo(lazyIntializer); string validatorName = GetValidatorName(); if (validatorName != null) validator = new MethodInfo(validatorName, "void", TypeName); }
public NamingConvensionAttribute(NamingConventions convention) { _convention = convention; }