Example #1
0
        public async Task <ICommandResult> Start(string group = "tea")
        {
            var context = await GetContextAsync().ConfigureAwait(false);

            var roomItemGroup = await _mediator.Send(new GetRoomItemGroupByNameQuery(roomId : context.Room.Id, userId : context.User.Id, name : group)).ConfigureAwait(false);

            if (roomItemGroup == null)
            {
                return(Response(ErrorStrings.StartRun_GroupInvalidName(group), ResponseType.User));
            }

            if (!roomItemGroup.Options.Any())
            {
                return(Response(ErrorStrings.StartRun_GroupNoOptions(roomItemGroup.Name), ResponseType.User));
            }

            var command = new StartRunCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                userId: context.User.Id,
                roomId: context.Room.Id,
                roomGroupId: roomItemGroup.Id,
                startTime: _clock.UtcNow());

            await _mediator.Send(command).ConfigureAwait(false);

            return(Response(new SlashCommandResponse
            {
                Text = ResponseStrings.RunStarted(context.Command.UserId, roomItemGroup.Name),
                Type = ResponseType.Channel,
                Attachments = AttachmentBuilder.BuildOptions(roomItemGroup.Options)
            }));
        }
        public void BuildOptions_SixOptions_TwoAttachments()
        {
            var options = new List <Option>
            {
                new Option
                {
                    Id   = 1,
                    Name = "test1"
                },
                new Option
                {
                    Id   = 2,
                    Name = "test2"
                },
                new Option
                {
                    Id   = 3,
                    Name = "test3"
                },
                new Option
                {
                    Id   = 4,
                    Name = "test4"
                },
                new Option
                {
                    Id   = 5,
                    Name = "test5"
                },
                new Option
                {
                    Id   = 6,
                    Name = "test6"
                },
            };

            var attachments = AttachmentBuilder.BuildOptions(options).ToList();

            Assert.Equal(2, attachments.Count);

            var attachment1 = attachments[0];
            var attachment2 = attachments[1];

            Assert.Equal(5, attachment1.Actions.Count);
            Assert.Single(attachment2.Actions);

            Assert.Equal(options[5].Id.ToString(), attachment2.Actions[0].Value);
        }