public void Get_ReturnsGuidCorrelationId()
        {
            string correlationId = CorrelationIdentifier.Get();
            Guid   result;

            Assert.IsTrue(Guid.TryParse(correlationId, out result));
        }
        public void Get_WithTraceIdentifierInContext_ReturnsTraceIdentifierCorrelationId()
        {
            var         mockHttpContextAccessor = new Mock <IHttpContextAccessor>();
            HttpContext context = new DefaultHttpContext();

            context.TraceIdentifier = "test_traceIdentifier";
            mockHttpContextAccessor.Setup(x => x.HttpContext).Returns(context);

            string correlationId = CorrelationIdentifier.Get(mockHttpContextAccessor.Object);

            Assert.AreEqual("test_traceIdentifier", correlationId);
        }
        public async Task <IActionResult> Get(string identifier)
        {
            if (!Resolver.IsSupported(identifier))
            {
                Error unsupportedIdentifier = new Error
                {
                    Message       = "The specified DID method is not supported. Only ION (https://github.com/decentralized-identity/ion) based identifiers can be resolved.",
                    Type          = Error.Types.RequestResolveIdentifier,
                    Code          = Error.Codes.UnsupportedDidMethod,
                    CorrelationId = CorrelationIdentifier.Get(this.httpContextAccessor)
                };

                return(BadRequest(unsupportedIdentifier));
            }

            JObject document;

            try
            {
                using (Resolver resolver = new Resolver(this.connection))
                {
                    document = await resolver.Resolve(identifier);
                }
            }
            catch (ConnectionException connectionException)
            {
                // If we get a 404, just return a vanilla
                // not found
                if (connectionException.StatusCode == HttpStatusCode.NotFound)
                {
                    return(NotFound());
                }

                // For exceptions that are not 404,
                // wrap in an error and return
                Error connectionError = new Error
                {
                    Message       = connectionException.ReasonPhrase,
                    Type          = Error.Types.RequestResolveIdentifier,
                    Code          = Error.Codes.RemoteServiceError,
                    CorrelationId = CorrelationIdentifier.Get(this.httpContextAccessor)
                };

                return(new ObjectResult(connectionError)
                {
                    StatusCode = (int)connectionException.StatusCode
                });
            }

            return(Json(document));
        }