public async Task GIVEN_query_with_ClientId_set_EXPECT_only_capabilities_with_given_id() { // Arrange var idOfWantedSender = Guid.NewGuid(); var capabilityRepository = new StubCapabilityRepository(); await capabilityRepository.Add(Capability.Create( idOfWantedSender, "foo", "slackChannelId", "slackUserGroupId" )); await capabilityRepository.Add(Capability.Create( idOfWantedSender, "bar", "slackChannelId", "slackUserGroupId" )); await capabilityRepository.Add(Capability.Create( Guid.NewGuid(), "sheep", "slackChannelId", "slackUserGroupId" )); var slackFacadeSpy = new SlackFacadeSpy(); var sut = new FindConnectionsByClientTypeClientIdChannelTypeChannelIdHandler(capabilityRepository, slackFacadeSpy); var clientIdOfWantedSender = new ClientId(idOfWantedSender.ToString()); var query = new FindConnectionsByClientTypeClientIdChannelTypeChannelId( new ClientTypeCapability(), clientIdOfWantedSender, new ChannelTypeSlack(), null ); // Act var results = await sut.HandleAsync(query); // Assert Assert.All( results, connection => Assert.Equal(clientIdOfWantedSender, connection.ClientId) ); }
public async Task Handle_WILL_InviteToChannel_AND_AddUserGroupUser() { // Arrange var capability = Capability.Create( id: Guid.NewGuid(), name: "FooCapability", slackChannelId: "FooChannelId", slackUserGroupId: "FooUserGroupId" ); var slackFacadeSpy = new SlackFacadeSpy(); var stubCapabilityRepository = new StubCapabilityRepository(); await stubCapabilityRepository.Add(capability); var slackMemberJoinedCapabilityDomainEventHandler = new SlackMemberJoinedCapabilityDomainEventHandler( null, slackFacadeSpy, stubCapabilityRepository, new SlackService(slackFacadeSpy, null) ); var memberEmail = "*****@*****.**"; var memberJoinedCapabilityDomainEvent = MemberJoinedCapabilityDomainEvent.Create(capability.Id, memberEmail); // Act await slackMemberJoinedCapabilityDomainEventHandler.HandleAsync(memberJoinedCapabilityDomainEvent); // Assert Assert.Equal(memberEmail, slackFacadeSpy.InvitedToChannel[new SlackChannelIdentifier(capability.SlackChannelId)].Single()); Assert.Equal(memberEmail, slackFacadeSpy.UserGroupsUsers[capability.SlackUserGroupId].Single()); }
public async Task GIVEN_empty_query_EXPECT_connections_for_all_capabilities() { // Arrange var capabilityRepository = new StubCapabilityRepository(); await capabilityRepository.Add(Capability.Create( Guid.NewGuid(), "foo", "slackChannelId", "slackUserGroupId" )); await capabilityRepository.Add(Capability.Create( Guid.NewGuid(), "bar", "slackChannelId", "slackUserGroupId" )); var slackFacadeSpy = new SlackFacadeSpy(); slackFacadeSpy.Conversations.AddRange(new [] { new ChannelDto { Id = "slackChannelId", Name = "slackChannelName" } }); var sut = new FindConnectionsByClientTypeClientIdChannelTypeChannelIdHandler(capabilityRepository, slackFacadeSpy); var query = new FindConnectionsByClientTypeClientIdChannelTypeChannelId( null, null, null, null ); // Act var results = await sut.HandleAsync(query); Assert.All( capabilityRepository.GetAll().Result, capability => results.Single(r => r.ClientId.ToString() == capability.Id.ToString() ) ); }
public async Task Handle_will_SendNotificationToChannel_Ded_AND_SendNotificationToChannel_CapabilityId() { // Arrange var capability = Capability.Create( Guid.NewGuid(), "", "slackChannelId", "" ); var slackFacadeSpy = new SlackFacadeSpy(); var stubCapabilityRepository = new StubCapabilityRepository(); await stubCapabilityRepository.Add(capability); var slackContextAddedToCapabilityDomainEventHandler = new SlackContextAddedToCapabilityDomainEventHandler( stubCapabilityRepository, slackFacadeSpy, new ExternalEventMetaDataStore() ); var contextAddedToCapabilityDomainEvent = ContextAddedToCapabilityDomainEvent.Create( capability.Id, "", "", Guid.NewGuid(), "" ); // Act await slackContextAddedToCapabilityDomainEventHandler .HandleAsync(contextAddedToCapabilityDomainEvent); // Assert var hardCodedDedChannelId = new SlackChannelIdentifier("GFYE9B99Q"); Assert.NotEmpty(slackFacadeSpy.ChannelsMessages[hardCodedDedChannelId]); Assert.NotEmpty(slackFacadeSpy.ChannelsMessages[capability.SlackChannelId.ToString()]); }
public async Task Handle_WILL_remove_user_from_channel_AND_user_group_AND_notify_user() { // Arrange var capability = Capability.Create( Guid.NewGuid(), "", "slackChannelId", "theUserGroup" ); var userEmail = "*****@*****.**"; await capability.AddMember(userEmail); var nullLogger = new NullLogger <SlackMemberLeftCapabilityDomainEventHandler>(); var slackFacadeSpy = new SlackFacadeSpy(); var stubCapabilityRepository = new StubCapabilityRepository(); await stubCapabilityRepository.Add(capability); var slackMemberLeftCapabilityDomainEventHandler = new SlackMemberLeftCapabilityDomainEventHandler( nullLogger, slackFacadeSpy, stubCapabilityRepository ); var memberLeftCapabilityDomainEvent = MemberLeftCapabilityDomainEvent.Create(capability.Id, userEmail); // Act await slackMemberLeftCapabilityDomainEventHandler.HandleAsync(memberLeftCapabilityDomainEvent); // Assert Assert.Equal(userEmail, slackFacadeSpy.RemovedFromChannel[capability.SlackChannelId.ToString()].First()); Assert.Equal(userEmail, slackFacadeSpy.RemovedFromUsergroup[capability.SlackUserGroupId.ToString()].First()); Assert.NotEmpty(slackFacadeSpy.UsersToNotifications[userEmail]); }