public CreatePollCommandTests() { //Arrange _pollCommandValid = new CreatePollCommand(); _pollCommandValid.Poll_Description = "poll 1"; string option1 = "option 1"; string option2 = "option 2"; string option3 = "option 3"; _pollCommandValid.Options = new List <string> { option1, option2, option3 }; _pollCommandInvalid = new CreatePollCommand(); _pollCommandInvalid.Poll_Description = ""; _pollCommandInvalid.Options = new List <string> { "", "", "" }; //ACT _pollCommandValid.Validate(); _pollCommandInvalid.Validate(); }
public async Task <ActionResult <GenericCommandResult> > Post([FromBody] CreatePollCommand command, [FromServices] PollHandler handler) { //var user = User.Claims.FirstOrDefault(x=>x.Type == "user_id")?.Value; var ret = (GenericCommandResult)await handler.Handle(command); if (!ret.Success) { _logger.LogWarning("Post --> ", ret); return(BadRequest(ret)); } _logger.LogInformation("Post --> ", ret); return(Ok(ret)); }
public async Task <ServiceResponse <PollDto> > Handle(CreatePollCommand request, CancellationToken cancellationToken) { var createdId = await _pollRepository.CreateAsync(new PollDto { Title = request.Title, Status = request.Status, Type = request.Type, Options = request.Options }); var poll = await _pollRepository.GetByIdAsync(createdId); return(ServiceResponse <PollDto> .Success(_mapper.Map <PollDto>(poll))); }
public PollHandlerTests() { //Arrange _mockLogger = new Mock <ILoggerFactory>(); _createPollCommandValid = new CreatePollCommand(); _createPollCommandValid.Poll_Description = "poll 1"; string option1 = "option 1"; string option2 = "option 2"; string option3 = "option 3"; _createPollCommandValid.Options = new List <string> { option1, option2, option3 }; _createPollCommandInvalid = new CreatePollCommand(); _createPollCommandInvalid.Poll_Description = ""; _createPollCommandInvalid.Options = new List <string> { "", "", "" }; _polls = new List <Poll>(); var poll1 = new Poll(new DescriptionVO("poll 1")); poll1.addOptions(new OptionPoll(new DescriptionVO("opt 1"))); poll1.addOptions(new OptionPoll(new DescriptionVO("opt 2"))); var poll2 = new Poll(new DescriptionVO("poll 2")); poll2.addOptions(new OptionPoll(new DescriptionVO("opt 3"))); poll2.addOptions(new OptionPoll(new DescriptionVO("opt 4"))); _polls.Add(poll1); _polls.Add(poll2); _getPollByIdCommandValid = new UpdatePollByIdCommand(Guid.NewGuid()); _getPollByIdCommandInvalid = new UpdatePollByIdCommand(); //ACT }