public async Task OnJoinDirectChannel(MemberSummaryResponse member, ChannelSummaryResponse channel) { var clientIds = await GetChannelMemberClientConnectionIdsAsync(channel.Id, member.Id); // Tell the people in this room that you've joined await HubContext.Clients.Clients(clientIds).SendAsync(HubEvents.MemberJoined, member, channel); }
public async Task ShouldReturnMemberSummaryResponse() { // Arrange var saasUserId = "9190FEB0-FDF0-4DDD-AC92-750D8AA33DC2"; Member member = new Member(); _memberRepositoryMock.Setup(x => x.GetMemberBySaasUserIdAsync(It.Is <string>(saas => saas.Equals(saasUserId)))) .ReturnsAsync(member) .Verifiable(); MemberSummaryResponse memberSummary = new MemberSummaryResponse(); _domainModelsMapperMock.Setup(x => x.MapToMemberSummaryResponse(It.Is <Member>(m => m.Equals(member)))) .Returns(memberSummary) .Verifiable(); // Act var act = await _memberService.GetMemberBySaasUserIdAsync(saasUserId); // Assert act.Should().BeEquivalentTo(memberSummary); VerifyMocks(); }
public async Task ShouldReturnMemberSummaryResponse() { // Arrange var memberId = new Guid("BE5C68F1-5983-4C08-B57B-FD4EFD7295B8"); Member member = new Member(); _memberRepositoryMock.Setup(x => x.GetMemberByIdAsync(It.Is <Guid>(id => id.Equals(memberId)))) .ReturnsAsync(member) .Verifiable(); MemberSummaryResponse memberSummary = new MemberSummaryResponse(); _domainModelsMapperMock.Setup(x => x.MapToMemberSummaryResponse(It.Is <Member>(m => m.Equals(member)))) .Returns(memberSummary) .Verifiable(); // Act var act = await _memberService.GetMemberByIdAsync(memberId); // Assert act.Should().BeEquivalentTo(memberSummary); VerifyMocks(); }
public async Task ShouldReturnMemberSummaryResponseCollection() { // Arrange var channelId = new Guid("BE5C68F1-5983-4C08-B57B-FD4EFD7295B8"); _channelRepositoryMock.Setup(x => x.IsChannelExistsAsync(It.Is <Guid>(c => c.Equals(channelId)))) .ReturnsAsync(true) .Verifiable(); List <Member> members = new List <Member>(); _memberRepositoryMock.Setup(x => x.GetAllMembersByChannelIdAsync(It.Is <Guid>(c => c.Equals(channelId)))) .ReturnsAsync(members) .Verifiable(); List <MemberSummaryResponse> memberSummaries = new List <MemberSummaryResponse>(); foreach (var member in members) { var memberSummary = new MemberSummaryResponse(); _domainModelsMapperMock.Setup(x => x.MapToMemberSummaryResponse(It.Is <Member>(m => m.Equals(member)))) .Returns(memberSummary) .Verifiable(); memberSummaries.Add(memberSummary); } // Act var act = await _memberService.GetChannelMembersAsync(channelId); // Assert VerifyMocks(); act.Should().AllBeEquivalentTo(memberSummaries); }
public async Task Step2_ShouldCreateChannel() { // Arrange var admin = await _adminSignalRClient.AddClientAsync(); var client = await _userSignalRClient.AddClientAsync(); // Subscribe event ChannelSummaryResponse createdChannel = null; void OnChannelCreated(ChannelSummaryResponse channelSummaryResponse) { createdChannel = channelSummaryResponse; } _adminSignalRClient.ChannelCreated += OnChannelCreated; // Subscribe event MemberSummaryResponse joinedMember = null; ChannelSummaryResponse joinedChannel = null; void OnMemberJoined(MemberSummaryResponse memberSummary, ChannelSummaryResponse channelSummaryResponse) { joinedMember = memberSummary; joinedChannel = channelSummaryResponse; } _adminSignalRClient.MemberJoined += OnMemberJoined; var createChannelRequest = new CreateChannelRequest { Name = "channel_name_without_spaces", Description = "channel description", WelcomeMessage = "welcome message", Type = ChannelType.Private, RequestId = "3433E3F8-E363-4A07-8CAA-8F759340F769", AllowedMembers = new List <string> { admin.MemberId.ToString(), client.MemberId.ToString() } }; // Act _testChannel = await _adminSignalRClient.CreateChannelAsync(createChannelRequest); // Unsubscribe events _adminSignalRClient.ChannelCreated -= OnChannelCreated; _adminSignalRClient.MemberJoined -= OnMemberJoined; // Assert createdChannel.Should().NotBeNull(); createdChannel.Should().BeEquivalentTo(_testChannel); joinedMember.Should().NotBeNull(); joinedChannel.Should().NotBeNull(); joinedChannel.Should().BeEquivalentTo(_testChannel); }
public async Task ShouldReturnMemberSummaryResponse() { // Arrange _memberRepositoryMock.Setup(x => x.GetMemberBySaasUserIdAsync(It.IsAny <string>())) .ReturnsAsync((Member)null) .Verifiable(); var utcNow = DateTimeOffset.UtcNow; _dateTimeProviderMock.Setup(x => x.GetUtcNow()) .Returns(utcNow) .Verifiable(); var email = "*****@*****.**"; var newMember = new Member { Id = new Guid("B83AA222-6EFA-4A4D-97DB-E3131C7AF81B"), SaasUserId = "8DCBF4A0-4490-45A2-B932-CEB71D19E9BD", Email = email, Role = UserRole.User, IsBanned = false, Status = UserStatus.Online, LastActivity = utcNow, Name = email, LastNudged = utcNow, PhotoName = string.Empty, OwnedChannels = new List <Channel>(), Messages = new List <Message>(), ConnectedClients = new List <Client>(), Channels = new List <ChannelMember>(), Notifications = new List <Notification>() }; _memberRepositoryMock.Setup(x => x.AddMemberAsync(It.IsAny <Member>())) .Returns(Task.CompletedTask) .Verifiable(); var memberSummary = new MemberSummaryResponse { SaasUserId = newMember.SaasUserId, Email = newMember.Email }; _domainModelsMapperMock.Setup(x => x.MapToMemberSummaryResponse(It.IsAny <Member>())) .Returns(memberSummary) .Verifiable(); // Act var act = await _memberService.AddMemberAsync(newMember.SaasUserId, newMember.Email); // Assert VerifyMocks(); act.Should().BeEquivalentTo(memberSummary); }
public async Task ShouldReturnChannelSummaryResponse() { // Arrange var allowedChannel = new Channel { Id = new Guid("4C13BEC1-2979-4822-9AAC-520B474214FD") }; var saasUserId = "2A70F115-9F55-4024-829B-6521FE18680C"; _channelRepositoryMock.Setup(x => x.GetChannelWithCreatorAsync(It.Is <Guid>(channel => channel.Equals(allowedChannel.Id)))) .ReturnsAsync(allowedChannel) .Verifiable(); var member = new MemberSummaryResponse(); _memberServiceMock.Setup(x => x.GetMemberBySaasUserIdAsync(It.IsAny <string>())) .ReturnsAsync(member) .Verifiable(); var allowedChannelMember = new ChannelMember(); _channelMemberRepositoryMock.Setup(x => x.GetChannelMemberAsync( It.Is <Guid>(memberId => memberId.Equals(member.Id)), It.Is <Guid>(channelId => channelId.Equals(allowedChannel.Id)))) .ReturnsAsync(allowedChannelMember) .Verifiable(); var lastReadMessage = new Message(); _messageRepositoryMock.Setup(x => x.GetLastReadMessageAsync( It.Is <Guid>(memberId => memberId.Equals(member.Id)), It.Is <Guid>(channelId => channelId.Equals(allowedChannel.Id)))) .ReturnsAsync(lastReadMessage) .Verifiable(); var channelSummaryResponse = new ChannelSummaryResponse(); _domainModelsMapperMock.Setup(x => x.MapToChannelSummaryResponse( It.Is <Channel>(channel => channel.Equals(allowedChannel)), It.Is <ChannelMember>(channelMember => channelMember.Equals(allowedChannelMember)), It.Is <Message>(message => message.Equals(lastReadMessage)))) .Returns(channelSummaryResponse) .Verifiable(); var messages = new List <Message>(); _messageRepositoryMock.Setup(x => x.GetAllChannelMessagesWithOwnersAsync(It.IsAny <Guid>())) .ReturnsAsync(messages) .Verifiable(); // Act var result = await _channelService.GetChannelSummaryAsync(saasUserId, allowedChannel.Id); // Assert VerifyMocks(); result.Should().BeEquivalentTo(channelSummaryResponse); }
public async Task OnDeletedFromChannel(MemberSummaryResponse member, Guid channelId) { var channelClients = await GetChannelClientConnectionIdsAsync(channelId); var deletingMemberClients = (await MemberService.GetMemberClientsAsync(member.Id)).Select(client => client.ClientConnectionId).ToList(); await HubContext.Clients.Clients(deletingMemberClients).SendAsync(HubEvents.YouAreDeleted, member, channelId); await HubContext.Clients.Clients(channelClients).SendAsync(HubEvents.MemberDeleted, member, channelId); }
public async Task OnLeaveChannel(MemberSummaryResponse member, Guid channelId) { var clientIds = await GetChannelClientConnectionIdsAsync(channelId); var senderClients = await MemberService.GetMemberClientsAsync(member.Id); clientIds.AddRange(senderClients.Select(x => x.ClientConnectionId)); // Tell the people in this room that you've leaved await HubContext.Clients.Clients(clientIds).SendAsync(HubEvents.MemberLeft, member, channelId); }
internal static ChatUserModel DtoToChatUser(MemberSummaryResponse dto) { if (dto == null) { return(null); } return(new ChatUserModel { Id = dto.Id.ToString(), Username = dto.UserName, PhotoUrl = dto.AvatarUrl, LastActivity = dto.LastActivity, IsOnline = dto.Status == UserStatus.Online, Role = DtoToUserRole(dto.Role), IsActive = dto.IsActive }); }
public MemberLeftLocalizationVisitor(MemberSummaryResponse member) { _member = member; }
public MemberDeletedLocalizationVisitor(MemberSummaryResponse member) { _member = member; }