Ejemplo n.º 1
0
        public async Task CanUpdateOption()
        {
            var authorizedClient = SystemTestExtension.GetTokenAuthorizeHttpClient(_factory);

            var updateOptionCommand = new UpdateOptionCommand
            {
                Id              = 1,
                Text            = "Yukaridakilerden hangisi aslinda asagidadir?",
                VisibilityOrder = 321,
                QuestionId      = 1
            };

            var serializedUpdateCommand = JsonConvert.SerializeObject(updateOptionCommand);

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

            //Must be successful
            httpResponse.EnsureSuccessStatusCode();

            Assert.True(httpResponse.IsSuccessStatusCode);
            Assert.Equal(HttpStatusCode.OK, httpResponse.StatusCode);
        }
Ejemplo n.º 2
0
        public async Task ShouldGetModelForValidInformation()
        {
            var updateOption = new UpdateOptionCommand
            {
                Id              = _optionId,
                TenantId        = _tenantId,
                UpdatedBy       = _adminUserId,
                QuestionId      = _questionId,
                Text            = "option1",
                VisibilityOrder = 1,
                IsCorrect       = true
            };

            var optionModel = await _updateOptionCommandHandler.Handle(updateOption, CancellationToken.None);

            Assert.Null(optionModel.Errors);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <ResponseModel <UpdateOptionModel> > > Put([FromBody] UpdateOptionCommand command)
        {
            try
            {
                command.UpdatedBy = Claims[ClaimTypes.Sid].ToInt();
                command.TenantId  = Guid.Parse(Claims[ClaimTypes.UserData]);

                var updateOptionModel = await Mediator.Send(command);

                return(Ok(updateOptionModel));
            }
            catch (NotFoundException)
            {
                return(NotFound());
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(Conflict(new ResponseModel <UpdateOptionModel>(new Error(HttpStatusCode.Conflict, ex))));
            }
            catch
            {
                return(StatusCode(HttpStatusCode.InternalServerError.ToInt()));
            }
        }
Ejemplo n.º 4
0
        public async Task <int> Handle(UpdateOptionCommand request, CancellationToken cancellationToken)
        {
            try
            {
                var option = await _context.Options
                             .FirstOrDefaultAsync(a => a.Id == request.Option.Id, cancellationToken);

                if (option == null)
                {
                    throw new ArgumentException($"Can't find this option by id = {request.Option.Id}");
                }

                _mapper.Map(request.Option, option);
                _context.Update(option);

                return(await _context.SaveChangesAsync(cancellationToken));
            }
            catch (Exception ex)
            {
                _logger.LogError(new EventId(), ex.Message);
            }

            return(-1);
        }