public async Task Should_create_enriched_events() { var ctx = Context(); var user1 = UserMocks.User("1"); var user2 = UserMocks.User("2"); var users = new List <IUser> { user1, user2 }; var userIds = users.Select(x => x.Id).ToArray(); var @event = new CommentCreated { Mentions = userIds }; A.CallTo(() => userResolver.QueryManyAsync(userIds, default)) .Returns(users.ToDictionary(x => x.Id)); var result = await sut.CreateEnrichedEventsAsync(Envelope.Create <AppEvent>(@event), ctx, default).ToListAsync(); Assert.Equal(2, result.Count); var enrichedEvent1 = result[0] as EnrichedCommentEvent; var enrichedEvent2 = result[1] as EnrichedCommentEvent; Assert.Equal(user1, enrichedEvent1 !.MentionedUser); Assert.Equal(user2, enrichedEvent2 !.MentionedUser); Assert.Equal("UserMentioned", enrichedEvent1.Name); Assert.Equal("UserMentioned", enrichedEvent2.Name); }
public void Should_trigger_precheck_if_event_type_correct() { TestForCondition(string.Empty, ctx => { var @event = new CommentCreated(); var result = sut.Trigger(Envelope.Create <AppEvent>(@event), ctx); Assert.True(result); }); }
public async Task Should_not_create_enriched_events_if_mentions_is_empty() { var ctx = Context(); var @event = new CommentCreated { Mentions = Array.Empty <string>() }; var result = await sut.CreateEnrichedEventsAsync(Envelope.Create <AppEvent>(@event), ctx, default).ToListAsync(); Assert.Empty(result); A.CallTo(() => userResolver.QueryManyAsync(A <string[]> ._, A <CancellationToken> ._)) .MustNotHaveHappened(); }
public void CreateComment() { var commentCommand = new CommentCreated() { UserId = 1010, RelatedDataEntityType = "Test Product", RelatedDataEntityId = 1, Type = 0, Body = "TestBody" }; var response = commentService.CreateComment(commentCommand); Assert.AreEqual(response.Type, Common.ServiceResponseTypes.Success); }
public async Task Should_not_create_enriched_events_if_users_cannot_be_resolved() { var ctx = Context(); var user1 = UserMocks.User("1"); var user2 = UserMocks.User("2"); var users = new List <IUser> { user1, user2 }; var userIds = users.Select(x => x.Id).ToArray(); var @event = new CommentCreated { Mentions = userIds }; var result = await sut.CreateEnrichedEventsAsync(Envelope.Create <AppEvent>(@event), ctx, default).ToListAsync(); Assert.Empty(result); }