/// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string queueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, INameFormatter nameFormatter, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _nameFormatter = nameFormatter;

            if (queueName != null)
            {
                // this never happens
                if (queueName.StartsWith(MagicSubscriptionPrefix))
                {
                    throw new ArgumentException($"Sorry, but the queue name '{queueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{MagicSubscriptionPrefix}'. ");
                }

                Address           = _nameFormatter.FormatQueueName(queueName);
                _subscriptionName = _nameFormatter.FormatSubscriptionName(queueName);
            }

            _connectionString  = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            _asyncTaskFactory  = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
            _cancellationToken = cancellationToken;
            _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>();
            _managementClient = new ManagementClient(connectionString);
        }
Ejemplo n.º 2
0
        protected virtual EnumMemberDeclarationSyntax?CreateEnumMember(
            ILocatedOpenApiElement <OpenApiSchema> schemaElement,
            IOpenApiAny value,
            INameFormatter nameFormatter,
            NamingContext namingContext)
        {
            if (value.AnyType != AnyType.Primitive)
            {
                return(null);
            }

            var primitive = (IOpenApiPrimitive)value;

            if (primitive.PrimitiveType != PrimitiveType.String)
            {
                return(null);
            }

            var stringPrimitive = (OpenApiPrimitive <string>)primitive;

            string memberName = namingContext.RegisterName(nameFormatter.Format(stringPrimitive.Value));

            return(SyntaxFactory.EnumMemberDeclaration(memberName)
                   .AddAttributeLists(SyntaxFactory.AttributeList().AddAttributes(
                                          CreateEnumMemberAttribute(stringPrimitive.Value))));
        }
Ejemplo n.º 3
0
        private string GetClassName()
        {
            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);

            if (Element.IsRoot())
            {
                // We're in the components section

                return(formatter.Format(Response.Reference.Id + "Response"));
            }
            else
            {
                // We're in an operation

                OpenApiOperation operation = Element.Parents()
                                             .OfType <LocatedOpenApiElement <OpenApiOperation> >()
                                             .First()
                                             .Element;

                string responseCode = Enum.TryParse <HttpStatusCode>(Element.Key, out var statusCode)
                    ? HttpResponseCodeNameProvider.GetName(statusCode)
                    : Element.Key;

                return(formatter.Format($"{operation.OperationId}{responseCode}Response"));
            }
        }
Ejemplo n.º 4
0
        protected override YardarmTypeInfo GetTypeInfo()
        {
            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);
            NameSyntax     ns        = Context.NamespaceProvider.GetNamespace(Element);

            return(new YardarmTypeInfo(QualifiedName(ns,
                                                     IdentifierName(formatter.Format(Operation.OperationId + "Request")))));
        }
 public void AddFormatter(String tableName, INameFormatter <T> formatter)
 {
     if (!_tableColumnFormatters.ContainsKey(tableName))
     {
         _tableColumnFormatters[tableName] = new List <INameFormatter <T> >();
     }
     _tableColumnFormatters[tableName].Add(formatter);
 }
 public NameMapper(string packageName, ITemplateFormatter packageNamingConvention,
                   INameFormatter fieldNameFormatter = null, INameFormatter constantNameFormatter = null)
 {
     _packageName             = packageName ?? throw new ArgumentNullException(nameof(packageName));
     _packageNamingConvention = packageNamingConvention ?? throw new ArgumentNullException(nameof(packageNamingConvention));
     _fieldNameFormatter      = fieldNameFormatter ?? new AsIsFormatter();
     _constantNameFormatter   = constantNameFormatter ?? new AsIsFormatter();
 }
Ejemplo n.º 7
0
        public FileManager(INameFormatter nameFormatter)
        {
            if (nameFormatter == null)
            {
                throw new ArgumentNullException(nameof(nameFormatter));
            }

            _nameFormatter = nameFormatter;
        }
Ejemplo n.º 8
0
        private string GetClassName()
        {
            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);

            OpenApiOperation operation =
                Element.Parents().OfType <LocatedOpenApiElement <OpenApiOperation> >().First().Element;

            return(formatter.Format($"{operation.OperationId}UnknownResponse"));
        }
 /// <summary>
 /// Updates <see cref="Formatter"/> with new value.
 /// </summary>
 /// <param name="formatter">New formatter to set.</param>
 /// <returns>Self.</returns>
 /// <exception cref="ArgumentNullException">Throws when <paramref name="formatter"/> is null.</exception>
 public NameFormatterConfiguration UpdateFormatter(INameFormatter formatter)
 {
     ThrowIfSealed();
     if (formatter == null)
     {
         throw new ArgumentNullException(nameof(formatter));
     }
     Formatter = formatter;
     return(this);
 }
Ejemplo n.º 10
0
        protected override YardarmTypeInfo GetTypeInfo()
        {
            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);
            NameSyntax     ns        = Context.NamespaceProvider.GetNamespace(RequestTypeGenerator.Element);

            TypeSyntax name = QualifiedName(ns,
                                            IdentifierName(formatter.Format($"{RequestTypeGenerator.Element.Element.OperationId}-HttpContent-Request")));

            return(new YardarmTypeInfo(name));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Constructor.
        /// </summary>
        protected CoreMetadataProvider(LightBddConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            ValueFormattingService = new ValueFormattingService(configuration);
            NameFormatter          = configuration.NameFormatterConfiguration().GetFormatter();
            _nameParser            = new NameParser(NameFormatter);
            _stepTypeProcessor     = new StepTypeProcessor(NameFormatter, configuration.StepTypeConfiguration());
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="nameFormatter"><see cref="INameFormatter"/> object used to format names.</param>
        /// <param name="stepTypeConfiguration"><see cref="StepTypeConfiguration"/> object used in providing step metadata.</param>
        /// <param name="cultureInfoProvider"><see cref="ICultureInfoProvider"/> object used in providing step parameter formatters.</param>
        /// <param name="valueFormattingConfiguration"><see cref="IValueFormattingService"/> object used to format parameters.</param>
        protected CoreMetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration, ICultureInfoProvider cultureInfoProvider, ValueFormattingConfiguration valueFormattingConfiguration)
        {
            if (stepTypeConfiguration == null)
            {
                throw new ArgumentNullException(nameof(stepTypeConfiguration));
            }
            _valueFormattingService = new ValueFormattingService(valueFormattingConfiguration, cultureInfoProvider);

            NameFormatter       = nameFormatter ?? throw new ArgumentNullException(nameof(nameFormatter));
            CultureInfoProvider = cultureInfoProvider ?? throw new ArgumentNullException(nameof(cultureInfoProvider));
            _nameParser         = new NameParser(nameFormatter);
            _stepTypeProcessor  = new StepTypeProcessor(nameFormatter, stepTypeConfiguration);
        }
Ejemplo n.º 13
0
 internal static void AppendContentRow(
     this StringBuilder sb,
     ProjectInfo projectInfo,
     UnitUnderTest unitUnderTest,
     OperationUnderTest operationUnderTest,
     TestScenario testScenario,
     string separator,
     INameFormatter nameFormatter)
 {
     sb?.Append($"{nameFormatter.SpecialCasedWordToSentence(projectInfo.Name)}{separator}");
     sb?.Append($"{nameFormatter.SpecialCasedWordToSentence(unitUnderTest.Namespace)}{separator}");
     sb?.Append($"{nameFormatter.SpecialCasedWordToSentence(operationUnderTest.ClassName)}{separator}");
     sb?.AppendLine($"\"{nameFormatter.CreateTestScenarioDescription(testScenario.Name, operationUnderTest.ClassName)}\"");
 }
Ejemplo n.º 14
0
        public override IEnumerable <MemberDeclarationSyntax> Generate()
        {
            var fullName = (QualifiedNameSyntax)GetTypeName();

            string enumName = fullName.Right.Identifier.Text;

            INameFormatter memberNameFormatter = Context.NameFormatterSelector.GetFormatter(NameKind.EnumMember);

            yield return(SyntaxFactory.EnumDeclaration(enumName)
                         .AddElementAnnotation(Element, Context.ElementRegistry)
                         .AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
                         .AddMembers(Schema.Enum
                                     .Select(p => CreateEnumMember(Element, p, memberNameFormatter) !)
                                     .Where(p => p != null)
                                     .ToArray()));
        }
Ejemplo n.º 15
0
        public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind)
        {
            QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind);

            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind);

            if (name == null)
            {
                // At the components root, use the responses namespace
                return(QualifiedName(
                           GetNamespace(),
                           IdentifierName(formatter.Format(Element.Key))));
            }

            return(name);
        }
Ejemplo n.º 16
0
        public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind)
        {
            QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind);

            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind);

            if (name == null)
            {
                // At the components root, use the parameters namespace. In this case, use the key on the components
                // dictionary and not the parameter name, since multiple component parameters may have the same name.
                return(QualifiedName(
                           GetNamespace(),
                           IdentifierName(formatter.Format(Element.Key))));
            }

            return(name);
        }
Ejemplo n.º 17
0
        protected override YardarmTypeInfo GetTypeInfo()
        {
            SerializerDescriptor?serializerDescriptor = SerializerSelector.Select(Element)?.Descriptor;

            if (serializerDescriptor == null)
            {
                throw new InvalidOperationException($"No serializer configured for {Element}.");
            }

            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);
            NameSyntax     ns        = Context.NamespaceProvider.GetNamespace(RequestTypeGenerator.Element);

            TypeSyntax name = QualifiedName(ns,
                                            IdentifierName(formatter.Format($"{RequestTypeGenerator.Element.Element.OperationId}-{serializerDescriptor.NameSegment}-Request")));

            return(new YardarmTypeInfo(name));
        }
Ejemplo n.º 18
0
        public override QualifiedNameSyntax GetChildName <TChild>(ILocatedOpenApiElement <TChild> child, NameKind nameKind)
        {
            QualifiedNameSyntax?name = Parent?.GetChildName(Element, nameKind);

            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(nameKind);

            if (name == null)
            {
                // At the components root, use the schema namespace
                return(QualifiedName(
                           Context.NamespaceProvider.GetNamespace(Element),
                           IdentifierName(formatter.Format(Element.Key + "-Item"))));
            }

            return(name.WithRight(IdentifierName(
                                      formatter.Format(name.Right.Identifier.ValueText + "-Item"))));
        }
        /// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string queueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, INameFormatter nameFormatter, CancellationToken cancellationToken = default(CancellationToken), ITokenProvider tokenProvider = null)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }

            _nameFormatter = nameFormatter;

            if (queueName != null)
            {
                // this never happens
                if (queueName.StartsWith(MagicSubscriptionPrefix))
                {
                    throw new ArgumentException($"Sorry, but the queue name '{queueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{MagicSubscriptionPrefix}'. ");
                }

                Address           = _nameFormatter.FormatQueueName(queueName);
                _subscriptionName = _nameFormatter.FormatSubscriptionName(queueName);
            }

            _connectionString  = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            _cancellationToken = cancellationToken;
            _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>();

            if (tokenProvider != null)
            {
                var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                _managementClient = new ManagementClient(connectionStringBuilder, tokenProvider);
                _endpoint         = connectionStringBuilder.Endpoint;
                _transportType    = connectionStringBuilder.TransportType;
            }
            else
            {
                _managementClient = new ManagementClient(connectionString);
            }

            _tokenProvider = tokenProvider;

            _messageLockRenewalTask = asyncTaskFactory.Create("Peek Lock Renewal", RenewPeekLocks, prettyInsignificant: true, intervalSeconds: 10);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="nameFormatter"><see cref="INameFormatter"/> object used to format names.</param>
        /// <param name="stepTypeConfiguration"><see cref="StepTypeConfiguration"/> object used in providing step metadata.</param>
        /// <param name="cultureInfoProvider"><see cref="ICultureInfoProvider"/> object used in providing step parameter formatters.</param>
        protected CoreMetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration, ICultureInfoProvider cultureInfoProvider)
        {
            if (nameFormatter == null)
            {
                throw new ArgumentNullException(nameof(nameFormatter));
            }
            if (cultureInfoProvider == null)
            {
                throw new ArgumentNullException(nameof(cultureInfoProvider));
            }
            if (stepTypeConfiguration == null)
            {
                throw new ArgumentNullException(nameof(stepTypeConfiguration));
            }

            NameFormatter       = nameFormatter;
            CultureInfoProvider = cultureInfoProvider;
            _nameParser         = new NameParser(nameFormatter);
            _stepTypeProcessor  = new StepTypeProcessor(nameFormatter, stepTypeConfiguration);
        }
Ejemplo n.º 21
0
        public static StringBuilder ToCsv(
            this TestReport testReport,
            INameFormatter nameFormatter,
            string separator = ";")
        {
            if (nameFormatter == null)
            {
                throw new ArgumentNullException(nameof(nameFormatter));
            }

            var sb = new StringBuilder();

            if (testReport != null)
            {
                sb.AppendHeaderRow(separator);
                foreach (var projectInfo in testReport.Projects)
                {
                    foreach (var unitUnderTest in projectInfo.UnitsUnderTest)
                    {
                        foreach (var operationUnderTest in unitUnderTest.OperationsUnderTest)
                        {
                            foreach (var testScenario in operationUnderTest.TestScenarios)
                            {
                                sb.AppendContentRow(
                                    projectInfo,
                                    unitUnderTest,
                                    operationUnderTest,
                                    testScenario,
                                    separator,
                                    nameFormatter);
                            }
                        }
                    }
                }
            }

            return(sb);
        }
Ejemplo n.º 22
0
        protected virtual TypeSyntax GetTypeName()
        {
            ILocatedOpenApiElement <OpenApiMediaType>?mediaType = MediaTypeSelector.Select(RequestBodyElement);

            if (mediaType == null)
            {
                throw new InvalidOperationException("No valid media type for this request");
            }

            ILocatedOpenApiElement <OpenApiSchema>?schemaElement = mediaType.GetSchema();

            if (schemaElement != null &&
                (schemaElement.Element.Type != "object" || schemaElement.Element.Reference != null))
            {
                return(Context.SchemaGeneratorRegistry.Get(schemaElement).TypeName);
            }

            INameFormatter formatter = Context.NameFormatterSelector.GetFormatter(NameKind.Class);
            NameSyntax     ns        = Context.NamespaceProvider.GetNamespace(RequestBodyElement);

            if (RequestBody.Reference != null)
            {
                // We're in the components section

                return(SyntaxFactory.QualifiedName(ns,
                                                   SyntaxFactory.IdentifierName(formatter.Format(RequestBody.Reference.Id + "RequestBody"))));
            }
            else
            {
                // We're in an operation

                var operation = RequestBodyElement.Parents().OfType <LocatedOpenApiElement <OpenApiOperation> >().First().Element;

                return(SyntaxFactory.QualifiedName(ns,
                                                   SyntaxFactory.IdentifierName(formatter.Format(operation.OperationId + "RequestBody"))));
            }
        }
Ejemplo n.º 23
0
 public NameParser(INameFormatter nameFormatter)
 {
     _nameFormatter = nameFormatter;
 }
Ejemplo n.º 24
0
 public TestMetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration, ICultureInfoProvider cultureInfoProvider)
     : base(nameFormatter, stepTypeConfiguration, cultureInfoProvider, new ValueFormattingConfiguration())
 {
 }
Ejemplo n.º 25
0
 public TestMetadataProvider(INameFormatter nameFormatter)
     : base(nameFormatter, new StepTypeConfiguration(), new DefaultCultureInfoProvider(), new ValueFormattingConfiguration())
 {
 }
Ejemplo n.º 26
0
 public TestMetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration) : base(nameFormatter, stepTypeConfiguration, new DefaultCultureInfoProvider())
 {
 }
 public void AddFormatter(INameFormatter <T> formatter)
 {
     _generalFormattersList.Add(formatter);
 }
Ejemplo n.º 28
0
 public TestableIntegrationContextBuilder WithNameFormatter(INameFormatter formatter)
 {
     _configuration.NameFormatterConfiguration().UpdateFormatter(formatter);
     return(this);
 }
Ejemplo n.º 29
0
 public MsTest2MetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration, ICultureInfoProvider cultureInfoProvider)
     : base(nameFormatter, stepTypeConfiguration, cultureInfoProvider)
 {
 }
Ejemplo n.º 30
0
 protected CoreMetadataProvider(INameFormatter nameFormatter, StepTypeConfiguration stepTypeConfiguration, ICultureInfoProvider cultureInfoProvider)
     : this(nameFormatter, stepTypeConfiguration, cultureInfoProvider, new ValueFormattingConfiguration())
 {
 }