Skip to content

Commit 4827552

Browse files
authored
Implemented HTTP client and server activities (#26)
* Implemented activities for HTTP clients and servers * Added more tests for Server and Client Activities and renamed everything named scope to activity
1 parent 5e76ad2 commit 4827552

16 files changed

+856
-63
lines changed

src/Abstractions.Tests/EventWrittenEventArgsExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Map_SourceNull()
2626
[Fact(DisplayName = "Map: Should throw an argument null exception for sessionName")]
2727
public void Map_SessionNameNull()
2828
{
29-
TestEventSource.Log.ProbeEvents(listener =>
29+
TestEventSource.Log.Listen(listener =>
3030
{
3131
// arrange
3232
TestEventSource.Log.DoSomething();
@@ -46,7 +46,7 @@ public void Map_SessionNameNull()
4646
[Fact(DisplayName = "Map: Should return an event")]
4747
public void Map_Success()
4848
{
49-
TestEventSource.Log.ProbeEvents(listener =>
49+
TestEventSource.Log.Listen(listener =>
5050
{
5151
// arrange
5252
TestEventSource.Log.DoSomething();

src/Abstractions/EventSourceNames.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ internal static class EventSourceNames
66
public const string Application = "ChilliCream-Application";
77
public const string Default = "ChilliCream-Common";
88
public const string ProviderActivation = "ChilliCream-Diagnostics-ProviderActivation";
9-
public const string Request = "ChilliCream-Request";
9+
public const string RequestActivity = "ChilliCream-RequestActivity";
1010
}
1111
}

src/Abstractions/TelemetryEvent.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class TelemetryEvent
3636

3737
/// <summary>
3838
/// Gets or sets the provider-specific integer value that uniquely identifies an event
39-
/// within the scope of the provider.
39+
/// within the activity of the provider.
4040
/// </summary>
4141
public int Id { get; set; }
4242

src/Core.Tests/DefaultEventSourceTests.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void CriticalDisabled()
4040
[Fact(DisplayName = "Critical: Should write one critical message to the log stream")]
4141
public void CriticalEnabled()
4242
{
43-
DefaultEventSource.Log.ProbeEvents((listener) =>
43+
DefaultEventSource.Log.Listen((listener) =>
4444
{
4545
// arrange
4646
string expectedMessage = "{2}";
@@ -73,7 +73,7 @@ public void CriticalFormatDisabled()
7373
[Fact(DisplayName = "Critical: Should write one critical message to the log stream")]
7474
public void CriticalFormatEnabled()
7575
{
76-
DefaultEventSource.Log.ProbeEvents((listener) =>
76+
DefaultEventSource.Log.Listen((listener) =>
7777
{
7878
// arrange
7979
string expectedMessage = "{2}";
@@ -136,7 +136,7 @@ public void ErrorDisabled()
136136
[Fact(DisplayName = "Error: Should write one error message to the log stream")]
137137
public void ErrorEnabled()
138138
{
139-
DefaultEventSource.Log.ProbeEvents((listener) =>
139+
DefaultEventSource.Log.Listen((listener) =>
140140
{
141141
// arrange
142142
string expectedMessage = "{2}";
@@ -169,7 +169,7 @@ public void ErrorFormatDisabled()
169169
[Fact(DisplayName = "Error: Should write one error message to the log stream")]
170170
public void ErrorFormatEnabled()
171171
{
172-
DefaultEventSource.Log.ProbeEvents((listener) =>
172+
DefaultEventSource.Log.Listen((listener) =>
173173
{
174174
// arrange
175175
string expectedMessage = "{2}";
@@ -232,7 +232,7 @@ public void InfoDisabled()
232232
[Fact(DisplayName = "Info: Should write one info message to the log stream")]
233233
public void InfoEnabled()
234234
{
235-
DefaultEventSource.Log.ProbeEvents((listener) =>
235+
DefaultEventSource.Log.Listen((listener) =>
236236
{
237237
// arrange
238238
string expectedMessage = "{2}";
@@ -265,7 +265,7 @@ public void InfoFormatDisabled()
265265
[Fact(DisplayName = "Info: Should write one info message to the log stream")]
266266
public void InfoFormatEnabled()
267267
{
268-
DefaultEventSource.Log.ProbeEvents((listener) =>
268+
DefaultEventSource.Log.Listen((listener) =>
269269
{
270270
// arrange
271271
string expectedMessage = "{2}";
@@ -328,7 +328,7 @@ public void VerboseDisabled()
328328
[Fact(DisplayName = "Verbose: Should write one verbose message to the log stream")]
329329
public void VerboseEnabled()
330330
{
331-
DefaultEventSource.Log.ProbeEvents((listener) =>
331+
DefaultEventSource.Log.Listen((listener) =>
332332
{
333333
// arrange
334334
string expectedMessage = "{2}";
@@ -361,7 +361,7 @@ public void VerboseFormatDisabled()
361361
[Fact(DisplayName = "Verbose: Should write one verbose message to the log stream")]
362362
public void VerboseFormatEnabled()
363363
{
364-
DefaultEventSource.Log.ProbeEvents((listener) =>
364+
DefaultEventSource.Log.Listen((listener) =>
365365
{
366366
// arrange
367367
string expectedMessage = "{2}";
@@ -424,7 +424,7 @@ public void WarningDisabled()
424424
[Fact(DisplayName = "Warning: Should write one warning message to the log stream")]
425425
public void WarningEnabled()
426426
{
427-
DefaultEventSource.Log.ProbeEvents((listener) =>
427+
DefaultEventSource.Log.Listen((listener) =>
428428
{
429429
// arrange
430430
string expectedMessage = "{2}";
@@ -457,7 +457,7 @@ public void WarningFormatDisabled()
457457
[Fact(DisplayName = "Warning: Should write one warning message to the log stream")]
458458
public void WarningFormatEnabled()
459459
{
460-
DefaultEventSource.Log.ProbeEvents((listener) =>
460+
DefaultEventSource.Log.Listen((listener) =>
461461
{
462462
// arrange
463463
string expectedMessage = "{2}";

src/Core/Activity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace Thor.Core
77
{
88
/// <summary>
9-
/// A default activity to group log events even across threads.
9+
/// A default activity to group telemetry events across threads and processes.
1010
/// </summary>
1111
/// <example>
1212
/// Here is an Example of creating an activity.

src/Core/Application.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
namespace Thor.Core
55
{
66
/// <summary>
7-
/// An application scope.
7+
/// An application activity.
88
/// </summary>
99
public static class Application
1010
{
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
using System;
2+
using Thor.Core.Testing.Utilities;
3+
using Xunit;
4+
5+
namespace Thor.Core.Http.Tests
6+
{
7+
public class ClientRequestActivityTests
8+
{
9+
#region Create
10+
11+
[Fact(DisplayName = "Create: Should throw an argument null exception for method")]
12+
public void Create_MethodNull()
13+
{
14+
// arrange
15+
const string method = null;
16+
Uri uri = new Uri("http://127.0.0.1/api/events");
17+
18+
// act
19+
Action verify = () => ClientRequestActivity.Create(method, uri);
20+
21+
// assert
22+
Assert.Throws<ArgumentNullException>("method", verify);
23+
}
24+
25+
[Fact(DisplayName = "Create: Should throw an argument null exception for uri")]
26+
public void Create_UriNull()
27+
{
28+
// arrange
29+
const string method = "GET";
30+
Uri uri = null;
31+
32+
// act
33+
Action verify = () => ClientRequestActivity.Create(method, uri);
34+
35+
// assert
36+
Assert.Throws<ArgumentNullException>("uri", verify);
37+
}
38+
39+
[Fact(DisplayName = "Create: Should create a client activity")]
40+
public void Create()
41+
{
42+
RequestActivityEventSource.Log.Listen(listener =>
43+
{
44+
// arrange
45+
const string method = "GET";
46+
Uri uri = new Uri("http://127.0.0.1/api/events");
47+
48+
// act
49+
using (ClientRequestActivity.Create(method, uri))
50+
{
51+
// do nothing here
52+
}
53+
54+
// assert
55+
Assert.Collection(listener.OrderedEvents,
56+
e =>
57+
{
58+
Assert.Equal("Initiate {2} {3}", e.Message);
59+
Assert.Equal(method, e.Payload[2]);
60+
Assert.Equal(uri.ToString(), e.Payload[3]);
61+
},
62+
e =>
63+
{
64+
Assert.Equal("Receive {3} {4}", e.Message);
65+
Assert.Equal(0, e.Payload[3]);
66+
Assert.Equal("UNKNOWN", e.Payload[4]);
67+
});
68+
});
69+
}
70+
71+
[Fact(DisplayName = "Create: Should create and link a client activity with its parent activity")]
72+
public void Create_Outeractivity()
73+
{
74+
RequestActivityEventSource.Log.Listen(listener =>
75+
{
76+
// arrange
77+
const string method = "POST";
78+
Uri uri = new Uri("http://127.0.0.1/api/events");
79+
80+
// act
81+
using (Activity.Create("Outer activity"))
82+
{
83+
using (ClientRequestActivity.Create(method, uri))
84+
{
85+
// do nothing here
86+
}
87+
}
88+
89+
// assert
90+
Assert.Collection(listener.OrderedEvents,
91+
e => Assert.Equal("Begin activity transfer", e.Message),
92+
e =>
93+
{
94+
Assert.Equal("Initiate {2} {3}", e.Message);
95+
Assert.Equal(method, e.Payload[2]);
96+
Assert.Equal(uri.ToString(), e.Payload[3]);
97+
},
98+
e => Assert.Equal("End activity transfer", e.Message),
99+
e =>
100+
{
101+
Assert.Equal("Receive {3} {4}", e.Message);
102+
Assert.Equal(0, e.Payload[3]);
103+
Assert.Equal("UNKNOWN", e.Payload[4]);
104+
});
105+
});
106+
}
107+
108+
#endregion
109+
110+
#region SetResponse
111+
112+
[Fact(DisplayName = "SetResponse: Should set the response proper")]
113+
public void SetResponse()
114+
{
115+
RequestActivityEventSource.Log.Listen(listener =>
116+
{
117+
// arrange
118+
const string method = "GET";
119+
Uri uri = new Uri("http://127.0.0.1/api/events");
120+
Guid userId = Guid.NewGuid();
121+
122+
// act
123+
using (ClientRequestActivity activity = ClientRequestActivity.Create(method, uri))
124+
{
125+
activity.SetResponse(200, userId);
126+
}
127+
128+
// assert
129+
Assert.Collection(listener.OrderedEvents,
130+
e =>
131+
{
132+
Assert.Equal("Initiate {2} {3}", e.Message);
133+
Assert.Equal(method, e.Payload[2]);
134+
Assert.Equal(uri.ToString(), e.Payload[3]);
135+
},
136+
e =>
137+
{
138+
Assert.Equal("Receive {3} {4}", e.Message);
139+
Assert.Equal(userId, e.Payload[2]);
140+
Assert.Equal(200, e.Payload[3]);
141+
Assert.Equal("OK", e.Payload[4]);
142+
});
143+
});
144+
}
145+
146+
#endregion
147+
}
148+
}

0 commit comments

Comments
 (0)