Exemple #1
0
        public async Task <IActionResult> GetChannels([FromQuery] string channelType)
        {
            object convertedChannelType;

            try
            {
                convertedChannelType = ChannelType.Create(channelType);
            }
            catch (ValidationException exp)
            {
                return(UnprocessableEntity(new { Message = exp.MessageToUser }));
            }

            switch (convertedChannelType)
            {
            case ChannelTypeSlack _:
            {
                var channelDtos = await _slackFacade.GetChannels(_configuration["SLACK_API_AUTH_TOKEN"]);

                var connections = channelDtos.Select(c =>
                                                     new ChannelDto
                    {
                        Id   = c.Id,
                        Name = c.Name,
                        Type = new ChannelTypeSlack()
                    });

                return(Ok(new ItemsEnvelope <ChannelDto>(connections)));
            }

            default:
                return(UnprocessableEntity($"Unsupported channelType {channelType}"));
            }
        }
        public void Create_will_return_a_ChannelTypeSlack_WHEN_given_string_slack()
        {
            // Arrange
            var name = "sLaCk";


            // Act / Assert
            ChannelType.Create(name);
        }
Exemple #3
0
        public async Task <IActionResult> GetConnections(
            [FromQuery] string clientType,
            [FromQuery] string clientId,
            [FromQuery] string channelType,
            [FromQuery] string channelId
            )
        {
            var query = new FindConnectionsByClientTypeClientIdChannelTypeChannelId();

            if (!string.IsNullOrEmpty(clientType))
            {
                query.ClientType = ClientType.Create(clientType);
            }

            if (!string.IsNullOrEmpty(clientId))
            {
                query.ClientId = ClientId.Create(clientId);
            }

            if (!string.IsNullOrEmpty(channelType))
            {
                query.ChannelType = ChannelType.Create(channelType);
            }

            if (!string.IsNullOrEmpty(channelId))
            {
                query.ChannelId = ChannelId.Create(channelId);
            }

            IEnumerable <Connection> connections;

            try
            {
                connections =
                    await _findConnectionsByClientTypeClientIdChannelTypeChannelIdQueryHandler.HandleAsync(query);
            }
            catch (ValidationException validationException)
            {
                return(StatusCode(
                           (int)HttpStatusCode.UnprocessableEntity,
                           new { message = validationException.MessageToUser }
                           ));
            }

            var connectionDtos = connections.Select(ConnectionDto.CreateFromConnection);

            return(Ok(new ItemsEnvelope <ConnectionDto>(connectionDtos)));
        }
        public void Create_will_tell_you_valid_types_WHEN_given_a_wrong_type_input()
        {
            // Arrange
            var name = "ThisIsNotAChannelType";


            // Act
            var exception = Record.Exception(() => ChannelType.Create(name));


            // Assert
            var startText       = "Your options are: '";
            var startPosition   = exception.Message.LastIndexOf(startText) + startText.Length + 1;
            var endPosition     = exception.Message.LastIndexOf("'");
            var lengthOfOptions = endPosition - startPosition;

            Assert.False(lengthOfOptions < 1);
        }