public async Task CreateChannelWithoutSubs()
        {
            var user            = fillTestDbHelper.Users.FirstOrDefault();
            var expectedChannel = new ChannelVm
            {
                About       = RandomExtensions.NextString(10),
                ChannelName = "Created channel"
            };
            var actualChannel = await createChannelsService.CreateChannelAsync(expectedChannel, user.Id, null);

            Assert.True(expectedChannel.ChannelName == actualChannel.ChannelName &&
                        expectedChannel.About == actualChannel.About &&
                        actualChannel.ChannelUsers.Count == 1);
        }
Example #2
0
        public async Task <Response> CreateResponseAsync()
        {
            try
            {
                request.Channel.ChannelId = null;
                request.Channel.Tag       = null;
                ChannelVm channel = await createChannelsService.CreateChannelAsync(request.Channel, clientConnection.UserId.GetValueOrDefault(), request.Subscribers).ConfigureAwait(false);

                List <long> usersId = await loadChannelsService.GetChannelUsersIdAsync(channel.ChannelId.GetValueOrDefault()).ConfigureAwait(false);

                conversationsNoticeService.SendChannelNoticeAsync(channel, usersId, clientConnection);
                UsersConversationsCacheService.Instance.UpdateUsersChannelsAsync(usersId);
                nodeNoticeService.SendChannelNodeNoticeAsync(channel, clientConnection.UserId.Value, request.Subscribers);
                BlockSegmentVm segment = await BlockSegmentsService.Instance.CreateChannelSegmentAsync(channel, NodeSettings.Configs.Node.Id).ConfigureAwait(false);

                BlockGenerationHelper.Instance.AddSegment(segment);
                return(new ChannelsResponse(request.RequestId, channel));
            }
            catch (UserNotFoundException ex)
            {
                Logger.WriteLog(ex, request);
                return(new ResultResponse(request.RequestId, "Users not found.", ErrorCode.ObjectDoesNotExists));
            }
            catch (UserBlockedException ex)
            {
                Logger.WriteLog(ex, request);
                return(new ResultResponse(request.RequestId, "The user is blacklisted by another user.", ErrorCode.UserBlocked));
            }
        }