Esempio n. 1
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            if (_correlationService.TryHttpCorrelate(out string errorMessage))
            {
                CorrelationInfo correlationInfo = _correlationService.GetCorrelationInfo();
                _logger.LogInformation(
                    "Gets the HTTP correlation: [OperationId={OperationId}, TransactionId={TransactionId}]",
                    correlationInfo.OperationId,
                    correlationInfo.TransactionId);

                string json = JsonConvert.SerializeObject(correlationInfo);
                return(new OkObjectResult(json));
            }

            return(new BadRequestObjectResult(errorMessage));
        }
Esempio n. 2
0
        public void Correlation_GetCorrelationInfo_UsesStubbedCorrelation()
        {
            // Arrange
            var expected            = new CorrelationInfo($"operation-{Guid.NewGuid()}", $"transaction-{Guid.NewGuid()}");
            var correlationAccessor = new DefaultCorrelationInfoAccessor();

            correlationAccessor.SetCorrelationInfo(expected);

            IOptions <HttpCorrelationInfoOptions> options = Options.Create(new HttpCorrelationInfoOptions());
            IHttpContextAccessor      contextAccessor     = Mock.Of <IHttpContextAccessor>();
            ILogger <HttpCorrelation> logger = NullLogger <HttpCorrelation> .Instance;
            var correlation = new HttpCorrelation(options, contextAccessor, correlationAccessor, logger);

            // Act
            CorrelationInfo actual = correlation.GetCorrelationInfo();

            // Assert
            Assert.Same(expected, actual);
        }