public void Initializer_IsIdempotent_ServiceBusRequest() { string functionName = "MyFunction"; // Simulate an HttpRequest var request = new RequestTelemetry { ResponseCode = string.Empty, Name = "", }; Activity requestActivity = new Activity("dummy"); requestActivity.Start(); requestActivity.AddTag(LogConstants.NameKey, functionName); requestActivity.AddTag(LogConstants.SucceededKey, "true"); var initializer = new WebJobsTelemetryInitializer(new WebJobsSdkVersionProvider()); initializer.Initialize(request); initializer.Initialize(request); Assert.Equal(functionName, request.Name); Assert.Equal("0", request.ResponseCode); Assert.Equal(true, request.Success); Assert.Null(request.Url); Assert.DoesNotContain(request.Properties, p => p.Key == LogConstants.SucceededKey); }
public void Initializer_IsIdempotent_HttpRequest() { string functionName = "MyFunction"; string status = "409"; Uri uri = new Uri("http://localhost/api/somemethod?secret=secret"); // Simulate an HttpRequest var request = new RequestTelemetry { Url = uri, ResponseCode = status, Name = "POST /api/somemethod", }; Activity requestActivity = new Activity("dummy"); requestActivity.Start(); requestActivity.AddTag(LogConstants.NameKey, functionName); requestActivity.AddTag(LogConstants.SucceededKey, "true"); var initializer = new WebJobsTelemetryInitializer(new WebJobsSdkVersionProvider()); initializer.Initialize(request); initializer.Initialize(request); Assert.Equal(functionName, request.Context.Operation.Name); Assert.Equal(status, request.ResponseCode); Assert.Equal(true, request.Success); Assert.Equal(functionName, request.Name); Assert.True(request.Properties.TryGetValue(LogConstants.HttpMethodKey, out var actualHttpMethod)); Assert.Equal("POST", actualHttpMethod); Assert.True(request.Properties.TryGetValue(LogConstants.HttpPathKey, out var actualHttpPath)); Assert.Equal("/api/somemethod", actualHttpPath); Assert.DoesNotContain(request.Properties, p => p.Key == LogConstants.SucceededKey); }