public void AddsCorrelationHeaderWithContext()
        {
            var client             = new HttpClient();
            var options            = new CorrelationOptions();
            var correlationContext = new CorrelationContext(Utilities.Options.Create(options));

            var id           = Guid.NewGuid().ToString();
            var sourceId     = Guid.NewGuid().ToString();
            var sourceName   = "testSource";
            var instanceId   = Guid.NewGuid().ToString();
            var instanceName = "testSource-instanceName";
            var userId       = "userId";
            var ipAddress    = "194.25.76.122";

            correlationContext.TrySetValues(id, sourceId, sourceName, instanceId, instanceName, userId, ipAddress);

            client.SetCorrelationValues(CreateServiceProvider(correlationContext, options));

            var result = client.DefaultRequestHeaders.Single(h => h.Key == CorrelationHeaders.HeaderKey);

            Assert.NotEqual(default(KeyValuePair <string, IEnumerable <string> >), result);
            byte[] data = Convert.FromBase64String(result.Value.Single());
            string json = Encoding.UTF8.GetString(data);

            dynamic parsedHeader  = JObject.Parse(json);
            string  correlationId = (string)parsedHeader.id;

            Assert.Equal(id, (string)parsedHeader.id);
            Assert.Equal(sourceId, (string)parsedHeader.sourceId);
            Assert.Equal(sourceName, (string)parsedHeader.sourceName);
            Assert.Equal(instanceId, (string)parsedHeader.instanceId);
            Assert.Equal(instanceName, (string)parsedHeader.instanceName);
            Assert.Equal(userId, (string)parsedHeader.userId);
            Assert.Equal(ipAddress, (string)parsedHeader.ipAddress);
        }
        public void SetValuesFirstTime()
        {
            var options      = new CorrelationOptions();
            var context      = new CorrelationContext(Options.Create(options));
            var id           = Guid.NewGuid().ToString();
            var sourceId     = Guid.NewGuid().ToString();
            var sourceName   = "appName";
            var instanceId   = Guid.NewGuid().ToString();
            var instanceName = "appName-instanceName";
            var userId       = "userId";
            var ipAddress    = "194.25.76.122";

            var result = context.TrySetValues(id, sourceId, sourceName, instanceId, instanceName, userId, ipAddress);

            Assert.True(result);
            Assert.Equal(id, context.Id);
            Assert.Equal(sourceId, context.SourceId);
            Assert.Equal(sourceName, context.SourceName);
            Assert.Equal(instanceId, context.InstanceId);
            Assert.Equal(instanceName, context.InstanceName);
            Assert.Equal(userId, context.UserId);
            Assert.Equal(ipAddress, context.IpAddress);

            byte[]  data         = Convert.FromBase64String(context.DgpHeader);
            string  json         = Encoding.UTF8.GetString(data);
            dynamic parsedHeader = JObject.Parse(json);

            Assert.Equal(id, (string)parsedHeader.id);
            Assert.Equal(sourceId, (string)parsedHeader.sourceId);
            Assert.Equal(sourceName, (string)parsedHeader.sourceName);
            Assert.Equal(instanceId, (string)parsedHeader.instanceId);
            Assert.Equal(instanceName, (string)parsedHeader.instanceName);
            Assert.Equal(userId, (string)parsedHeader.userId);
            Assert.Equal(ipAddress, (string)parsedHeader.ipAddress);
        }
コード例 #3
0
        public void KeepFirstTimeValues()
        {
            var options      = new CorrelationOptions();
            var context      = new CorrelationContext(Options.Create(options));
            var id           = Guid.NewGuid().ToString();
            var sourceId     = Guid.NewGuid().ToString();
            var sourceName   = "appName";
            var instanceId   = Guid.NewGuid().ToString();
            var instanceName = "appName-instanceName";
            var userId       = "userId";
            var ipAddress    = "194.25.76.122";

            context.TrySetValues(id, sourceId, sourceName, instanceId, instanceName, userId, ipAddress);
            var result = context.TrySetValues(id, sourceId, "otherSoure", instanceId, instanceName, userId, ipAddress);

            Assert.False(result);
            Assert.Equal(id, context.Id);
            Assert.Equal(sourceId, context.SourceId);
            Assert.Equal(sourceName, context.SourceName);
            Assert.Equal(instanceId, context.InstanceId);
            Assert.Equal(instanceName, context.InstanceName);
            Assert.Equal(userId, context.UserId);
            Assert.Equal(ipAddress, context.IpAddress);
        }
コード例 #4
0
        public void AddHeadersToClientWithServiceProvider()
        {
            var client             = new HttpClient();
            var options            = new CorrelationOptions();
            var correlationContext = new CorrelationContext(Utilities.Options.Create(options));

            var id           = Guid.NewGuid().ToString();
            var sourceId     = Guid.NewGuid().ToString();
            var sourceName   = "testSource";
            var instanceId   = Guid.NewGuid().ToString();
            var instanceName = "testSource-instanceName";
            var userId       = "userId";
            var ipAddress    = "194.25.76.122";

            correlationContext.TrySetValues(id, sourceId, sourceName, instanceId, instanceName, userId, ipAddress);

            client.SetCorrelationValues(CreateServiceProvider(correlationContext, options));

            Assert.NotNull(client.DefaultRequestHeaders.Single(h => h.Key == options.IdHeaderKey));
            Assert.Equal(correlationContext.Id.ToString(), client.DefaultRequestHeaders.Single(h => h.Key == options.IdHeaderKey).Value.Single());

            Assert.NotNull(client.DefaultRequestHeaders.Single(h => h.Key == options.SourceHeaderKey));
            Assert.Equal(correlationContext.SourceId.ToString(), client.DefaultRequestHeaders.Single(h => h.Key == options.SourceHeaderKey).Value.Single());
        }