Skip to content

Commit bdf7d0e

Browse files
committed
Added tests for posting user description #241
1 parent 07c18c5 commit bdf7d0e

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

Source/Tests/Controllers/EventControllerTests.cs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class EventControllerTests : TestWithLoggingBase {
3737
private readonly EventController _eventController = IoC.GetInstance<EventController>();
3838
private readonly IEventRepository _eventRepository = IoC.GetInstance<IEventRepository>();
3939
private readonly IQueue<EventPost> _eventQueue = IoC.GetInstance<IQueue<EventPost>>();
40+
private readonly IQueue<EventUserDescription> _eventUserDescriptionQueue = IoC.GetInstance<IQueue<EventUserDescription>>();
4041
private readonly IOrganizationRepository _organizationRepository = IoC.GetInstance<IOrganizationRepository>();
4142
private readonly IProjectRepository _projectRepository = IoC.GetInstance<IProjectRepository>();
4243

@@ -75,7 +76,7 @@ public async Task CanPostCompressedStringAsync() {
7576
await ResetAsync();
7677

7778
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);
7980
var actionResult = await _eventController.PostAsync(await Encoding.UTF8.GetBytes("simple string").CompressAsync());
8081
Assert.IsType<StatusCodeResult>(actionResult);
8182
Assert.Equal(1, (await _eventQueue.GetQueueStatsAsync()).Enqueued);
@@ -96,7 +97,7 @@ public async Task CanPostSingleEventAsync() {
9697
await ResetAsync();
9798

9899
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);
100101
var actionResult = await _eventController.PostAsync(await Encoding.UTF8.GetBytes("simple string").CompressAsync());
101102
Assert.IsType<StatusCodeResult>(actionResult);
102103
Assert.Equal(1, (await _eventQueue.GetQueueStatsAsync()).Enqueued);
@@ -111,6 +112,26 @@ public async Task CanPostSingleEventAsync() {
111112
await RemoveAllEventsAsync();
112113
}
113114
}
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+
}
114135

115136
[Fact]
116137
public async Task CanPostManyEventsAsync() {
@@ -121,7 +142,7 @@ public async Task CanPostManyEventsAsync() {
121142

122143
try {
123144
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);
125146
var events = new RandomEventGenerator().Generate(batchSize);
126147
var compressedEvents = await Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(events)).CompressAsync();
127148
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
164185
return request;
165186
}
166187

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+
167199
private bool _isReset;
168200
private async Task ResetAsync() {
169201
if (!_isReset) {

0 commit comments

Comments
 (0)