Esempio n. 1
0
        public async Task Handle(RoomCreatedEvent notification, CancellationToken cancellationToken)
        {
            if (!notification.CreateDefaultItemGroup)
            {
                return;
            }

            var command = new CreateRoomItemGroupCommand(
                id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                roomId: notification.Id,
                userId: notification.CreatedBy,
                name: "tea");

            await _mediator.Send(command, CancellationToken.None).ConfigureAwait(false);

            //create some options
            foreach (var name in DefaultItemNames)
            {
                var optionCommand = new CreateOptionCommand(
                    id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                    userId: notification.CreatedBy,
                    groupId: command.Id,
                    name: name);

                await _mediator.Send(optionCommand, CancellationToken.None).ConfigureAwait(false);
            }
        }
Esempio n. 2
0
        public async Task CanCreateOptionAsync()
        {
            var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var createOptionCommand = new CreateOptionCommand
            {
                CreateOptionModels = new List <CreateOptionCommandModel>
                {
                    new CreateOptionCommandModel
                    {
                        QuestionId      = 1,
                        Text            = "option1",
                        VisibilityOrder = 1
                    }
                }
            };

            var serializedOptionCommand = JsonConvert.SerializeObject(createOptionCommand);

            // The endpoint or route of the controller action.
            var httpResponse = await authorizedClient.PostAsync(requestUri : "/Option",
                                                                content : new StringContent(content: serializedOptionCommand,
                                                                                            encoding: Encoding.UTF8,
                                                                                            mediaType: StringConstants.ApplicationJson));

            // Must be successful.
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.Created, httpResponse.StatusCode);
        }
Esempio n. 3
0
        public async Task <ICommandResult> AddOption(string groupName, string optionName)
        {
            if (string.IsNullOrWhiteSpace(groupName) || string.IsNullOrWhiteSpace(optionName))
            {
                return(Response(ErrorStrings.AddOption_BadArguments(), ResponseType.User));
            }

            var context = await GetContextAsync().ConfigureAwait(false);

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

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

            var command =
                new CreateOptionCommand(
                    id: await _idGenerator.GenerateAsync().ConfigureAwait(false),
                    userId: context.User.Id,
                    groupId: group.Id,
                    name: optionName);

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

            return(Response(ResponseStrings.OptionAddedToGroup(optionName, group.Name), ResponseType.User));
        }
Esempio n. 4
0
        public async Task <ActionResult <ResponseModel <CreateOptionModel> > > Post([FromBody] CreateOptionCommand command)
        {
            try
            {
                command.CreatedBy = Claims[ClaimTypes.Sid].ToInt();
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var createOptionModel = await Mediator.Send(command);

                return(Created($"api/option/{createOptionModel.Items}", createOptionModel));
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <CreateOptionModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }
Esempio n. 5
0
        public async Task ShouldGetModelForValidInformation()
        {
            var createOption = new CreateOptionCommand
            {
                TenantId           = _tenantId,
                CreatedBy          = _adminUserId,
                CreateOptionModels = new List <CreateOptionCommandModel>
                {
                    new CreateOptionCommandModel
                    {
                        QuestionId      = _questionId,
                        Text            = "option1",
                        VisibilityOrder = 1
                    }
                }
            };

            var optionModel = await _createOptionCommandHandler.Handle(createOption, CancellationToken.None);

            Assert.Null(optionModel.Errors);
        }