@@ -37,6 +37,7 @@ public class EventControllerTests : TestWithLoggingBase {
37
37
private readonly EventController _eventController = IoC . GetInstance < EventController > ( ) ;
38
38
private readonly IEventRepository _eventRepository = IoC . GetInstance < IEventRepository > ( ) ;
39
39
private readonly IQueue < EventPost > _eventQueue = IoC . GetInstance < IQueue < EventPost > > ( ) ;
40
+ private readonly IQueue < EventUserDescription > _eventUserDescriptionQueue = IoC . GetInstance < IQueue < EventUserDescription > > ( ) ;
40
41
private readonly IOrganizationRepository _organizationRepository = IoC . GetInstance < IOrganizationRepository > ( ) ;
41
42
private readonly IProjectRepository _projectRepository = IoC . GetInstance < IProjectRepository > ( ) ;
42
43
@@ -75,7 +76,7 @@ public async Task CanPostCompressedStringAsync() {
75
76
await ResetAsync ( ) ;
76
77
77
78
try {
78
- _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( new User { EmailAddress = TestConstants . UserEmail , Id = TestConstants . UserId , OrganizationIds = new [ ] { TestConstants . OrganizationId } , Roles = new [ ] { AuthorizationRoles . Client } } . ToIdentity ( TestConstants . ProjectId ) ) , true , false ) ;
79
+ _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( GetClientToken ( ) . ToIdentity ( ) ) , true , false ) ;
79
80
var actionResult = await _eventController . PostAsync ( await Encoding . UTF8 . GetBytes ( "simple string" ) . CompressAsync ( ) ) ;
80
81
Assert . IsType < StatusCodeResult > ( actionResult ) ;
81
82
Assert . Equal ( 1 , ( await _eventQueue . GetQueueStatsAsync ( ) ) . Enqueued ) ;
@@ -96,7 +97,7 @@ public async Task CanPostSingleEventAsync() {
96
97
await ResetAsync ( ) ;
97
98
98
99
try {
99
- _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( new User { EmailAddress = TestConstants . UserEmail , Id = TestConstants . UserId , OrganizationIds = new [ ] { TestConstants . OrganizationId } , Roles = new [ ] { AuthorizationRoles . Client } } . ToIdentity ( TestConstants . ProjectId ) ) , true , false ) ;
100
+ _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( GetClientToken ( ) . ToIdentity ( ) ) , true , false ) ;
100
101
var actionResult = await _eventController . PostAsync ( await Encoding . UTF8 . GetBytes ( "simple string" ) . CompressAsync ( ) ) ;
101
102
Assert . IsType < StatusCodeResult > ( actionResult ) ;
102
103
Assert . Equal ( 1 , ( await _eventQueue . GetQueueStatsAsync ( ) ) . Enqueued ) ;
@@ -111,6 +112,26 @@ public async Task CanPostSingleEventAsync() {
111
112
await RemoveAllEventsAsync ( ) ;
112
113
}
113
114
}
115
+
116
+ [ Fact ]
117
+ public async Task CanPostUserDescriptionAsync ( ) {
118
+ await ResetAsync ( ) ;
119
+
120
+ _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( GetClientToken ( ) . ToIdentity ( ) ) , true , false ) ;
121
+ var actionResult = await _eventController . SetUserDescriptionAsync ( "TestReferenceId" , new EventUserDescription { Description = "Test Description" , EmailAddress = TestConstants . UserEmail } ) ;
122
+ Assert . IsType < StatusCodeResult > ( actionResult ) ;
123
+
124
+ var stats = await _eventUserDescriptionQueue . GetQueueStatsAsync ( ) ;
125
+ Assert . Equal ( 1 , stats . Enqueued ) ;
126
+ Assert . Equal ( 0 , stats . Completed ) ;
127
+
128
+ var userDescriptionJob = IoC . GetInstance < EventUserDescriptionsJob > ( ) ;
129
+ await userDescriptionJob . RunAsync ( ) ;
130
+
131
+ stats = await _eventUserDescriptionQueue . GetQueueStatsAsync ( ) ;
132
+ Assert . Equal ( 1 , stats . Dequeued ) ;
133
+ Assert . Equal ( 1 , stats . Abandoned ) ; // Event doesn't exist
134
+ }
114
135
115
136
[ Fact ]
116
137
public async Task CanPostManyEventsAsync ( ) {
@@ -121,7 +142,7 @@ public async Task CanPostManyEventsAsync() {
121
142
122
143
try {
123
144
await Run . InParallelAsync ( batchCount , async i => {
124
- _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( new User { EmailAddress = TestConstants . UserEmail , Id = TestConstants . UserId , OrganizationIds = new [ ] { TestConstants . OrganizationId } , Roles = new [ ] { AuthorizationRoles . Client } } . ToIdentity ( TestConstants . ProjectId ) ) , true , false ) ;
145
+ _eventController . Request = CreateRequestMessage ( new ClaimsPrincipal ( GetClientToken ( ) . ToIdentity ( ) ) , true , false ) ;
125
146
var events = new RandomEventGenerator ( ) . Generate ( batchSize ) ;
126
147
var compressedEvents = await Encoding . UTF8 . GetBytes ( JsonConvert . SerializeObject ( events ) ) . CompressAsync ( ) ;
127
148
var actionResult = await _eventController . PostAsync ( compressedEvents , version : 2 , userAgent : "exceptionless/2.0.0.0" ) ;
@@ -164,6 +185,17 @@ private HttpRequestMessage CreateRequestMessage(ClaimsPrincipal user, bool isCom
164
185
return request ;
165
186
}
166
187
188
+ private Core . Models . Token GetClientToken ( ) {
189
+ var token = new Core . Models . Token ( ) ;
190
+ token . Id = StringExtensions . GetNewToken ( ) ;
191
+ token . CreatedUtc = token . ModifiedUtc = DateTime . UtcNow ;
192
+ token . Type = TokenType . Access ;
193
+ token . CreatedBy = TestConstants . UserId ;
194
+ token . OrganizationId = TestConstants . OrganizationId ;
195
+ token . ProjectId = TestConstants . ProjectId ;
196
+ return token ;
197
+ }
198
+
167
199
private bool _isReset ;
168
200
private async Task ResetAsync ( ) {
169
201
if ( ! _isReset ) {
0 commit comments