private IEnumerable <Connection> MergeIntoConnections(
            IEnumerable <Capability> capabilities,
            IEnumerable <ChannelDto> channelDtos
            )
        {
            var connections = new List <Connection>();

            foreach (var channelDto in channelDtos)
            {
                var relevantCapability = capabilities.Where(c => c.SlackChannelId == channelDto.Id);

                connections.AddRange(
                    relevantCapability.Select(capability =>
                                              new Connection(
                                                  new ClientTypeCapability(),
                                                  new ClientName(capability.Name),
                                                  new ClientId(capability.Id.ToString()),
                                                  new ChannelTypeSlack(),
                                                  ChannelName.Create(channelDto.Name),
                                                  new ChannelId(capability.SlackChannelId)
                                                  )
                                              )
                    );
            }

            return(connections);
        }
Ejemplo n.º 2
0
        public void FixChannelNameForSlack_NumbersAndCharsDashSeparated_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "123Numbers-456MoreNumbers";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 3
0
        public void FixChannelNameForSlack_DashSeparated_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "dash-separated";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 4
0
        public void FixChannelNameForSlack_CharAndNumbers_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "Numbers123";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 5
0
        public void FixChannelNameForSlack_NumbersAndLowerCaseUnderscoreSeparated_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "123numbers_456moreNumbers";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 6
0
        public void FixChannelNameForSlack_LowerCasing_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "lowercase";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 7
0
        public void FixChannelNameForSlack_NameWithMultipleUpperCaseLetters_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "TestNoDoubleNSCreation";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 8
0
        public void FixChannelNameForSlack_LowerCaseAndNumbersDashSeparated_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelName = "numbers123-moreNumbers456";

            // Act
            var fixedChannelName = ChannelName.Create(channelName);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 9
0
        public async Task HandleAsync(RenameChannelCommand command)
        {
            var group = await _groupRepository.GetAsync(GroupId.From(command.GroupId)) ??
                        throw new GroupNotFoundException(GroupId.From(command.GroupId));

            var channel = await _channelRepository.GetAsync(group.Id, ChannelId.From(command.ChannelId)) ??
                          throw new ChannelNotFoundException(ChannelId.From(command.ChannelId));

            var name = ChannelName.Create(command.Name);

            group.RenameChannel(UserId.From(command.UserId), channel, name);
        }
Ejemplo n.º 10
0
        public void FixChannelNameForSlack_NameWithLength100_ReturnsValidSlackChannelName()
        {
            // Arrange
            var channelNameOfLength100 = string.Join("", Enumerable
                                                     .Repeat(0, 100)
                                                     .Select(n =>
                                                             (char)new Random().Next(97, 123)
                                                             )
                                                     );

            // Act
            var fixedChannelName = ChannelName.Create(channelNameOfLength100);

            // Assert
            AssertValidSlackChannelName(fixedChannelName);
        }
Ejemplo n.º 11
0
        public async Task CreateChannel_Given_valid_input_Should_create_channel()
        {
            // Arrange
            var sut         = new SlackFacade(_httpClient, _slackOptions, null);
            var channelName = ChannelName.Create(Guid.NewGuid().ToString());

            // Act
            var createChannelResponse = await sut.CreateChannel(channelName.ToString());

            // Assert
            Assert.True(createChannelResponse.Ok);
            Assert.Equal(channelName, createChannelResponse.Channel.Name);
            Assert.NotEmpty(createChannelResponse.Channel.Id.ToString());

            //Clean up integration test resources.
            await sut.ArchiveChannel(createChannelResponse.Channel.Id);
        }
Ejemplo n.º 12
0
        public async Task InviteToChannel_Given_valid_input_Should_invite_to_channel()
        {
            // Arrange
            var sut         = new SlackFacade(_httpClient, _slackOptions, null, new MemoryCache(new MemoryCacheOptions()));
            var channelName = ChannelName.Create(Guid.NewGuid().ToString());
            var userEmail   = _configuration.SLACK_TESTING_USER_EMAIL;

            // Act
            var createChannelResponse = await sut.CreateChannel(channelName.ToString());

            await sut.InviteToChannel(userEmail, createChannelResponse.Channel.Id.ToString());

            // Assert
            Assert.True(createChannelResponse.Ok);

            //Clean up integration test resources.
            await sut.ArchiveChannel(createChannelResponse.Channel.Id);
        }
Ejemplo n.º 13
0
        public async Task SendNotificationToChannel_Given_valid_input_Should_send_notfication_to_channel()
        {
            // Arrange
            var          sut         = new SlackFacade(_httpClient, _slackOptions, null, new MemoryCache(new MemoryCacheOptions()));
            var          channelName = ChannelName.Create(Guid.NewGuid().ToString());
            const string message     = "Integration test message.";

            // Act
            var createChannelResponse = await sut.CreateChannel(channelName.ToString());

            var sendNotificationToChannelResponse = await sut.SendNotificationToChannel(createChannelResponse.Channel.Id, message : message);

            // Assert
            Assert.True(sendNotificationToChannelResponse.Ok);
            Assert.NotEmpty(sendNotificationToChannelResponse.TimeStamp);

            //Clean up integration test resources.
            await sut.ArchiveChannel(createChannelResponse.Channel.Id);
        }
Ejemplo n.º 14
0
        public async Task HandleAsync(CreateChannelCommand command)
        {
            var groupId = GroupId.From(command.GroupId);
            var group   = await _groupRepository.GetAsync(groupId) ?? throw new GroupNotFoundException(groupId);

            if (await _channelRepository.ExistsAsync(group.Id, ChannelId.From(command.ChannelId)))
            {
                throw new ChannelAlreadyExistsException(command.ChannelId);
            }

            var channel = group.CreateChannel(UserId.From(command.UserId), ChannelId.From(command.ChannelId), ChannelName.Create(command.ChannelName));

            await _channelRepository.AddAsync(channel);
        }