public PollQueriesTests() { //arrange _polls = new List <Poll>(); var poll1 = new Poll(new DescriptionVO("poll 1")); var opt1 = new OptionPoll(new DescriptionVO("opt 3")); opt1.increaseQty(); poll1.addOptions(opt1); poll1.increaseView(); var opt2 = new OptionPoll(new DescriptionVO("opt 3")); opt2.increaseQty(); poll1.addOptions(opt2); var poll2 = new Poll(new DescriptionVO("poll 2")); var opt3 = new OptionPoll(new DescriptionVO("opt 3")); opt1.increaseQty(); poll2.addOptions(opt3); var opt4 = new OptionPoll(new DescriptionVO("opt 4")); opt3.increaseQty(); poll2.addOptions(opt4); poll2.increaseView(); _polls.Add(poll1); _polls.Add(poll2); }
public OptionPoll AddOption(OptionPoll option) { using (IDbConnection db = new SqlConnection(connectionString)) { var sqlQuery = "INSERT INTO OptionPoll (PollId, TextOption) VALUES(@PollId, @TextOption); SELECT CAST(SCOPE_IDENTITY() as int)"; int Id = db.Query <int>(sqlQuery, option).FirstOrDefault(); return(db.Query <OptionPoll>("SELECT * FROM OptionPoll WHERE Id = @Id", new { Id }).FirstOrDefault()); } }
public void Update(OptionPoll optionPoll) { try { _context.Entry(optionPoll).State = EntityState.Modified; //_context.SaveChanges(); } catch (DbUpdateConcurrencyException ex) { throw ex; } }
public void Poll_whenCreateObject3_returnNotification() { DescriptionVO description = new DescriptionVO(""); Poll poll = new Poll(description); DescriptionVO option1 = new DescriptionVO("poll 1"); DescriptionVO option2 = new DescriptionVO("poll 1"); OptionPoll optionPoll1 = new OptionPoll(option1); OptionPoll optionPoll2 = new OptionPoll(option2); poll.addOptions(optionPoll1); poll.addOptions(optionPoll2); Assert.AreEqual(3, poll.Notifications.Count); }
public async Task <ICommandResult> Handle(CreatePollCommand command) { try { // fail fast validation command.Validate(); if (command.Invalid) { return(new GenericCommandResult(true, "Enquete inválida", command.Notifications)); } DescriptionVO description = new DescriptionVO(command.Poll_Description); Poll poll = new Poll(description); List <OptionPoll> opt = new List <OptionPoll>(); foreach (var item in command.Options) { DescriptionVO vo = new DescriptionVO(item); OptionPoll option = new OptionPoll(vo); poll.addOptions(option); } await _pollRepository.Create(poll); if (Commit()) { return(new GenericCommandResult(true, "Enquete gravada com sucesso", new CreatePollCommandResult(poll.Id))); } else { return(new GenericCommandResult(false, "Falha ao gravar enquete", null)); } } catch (Exception ex) { _logger.LogError("CreatePollCommand --> ", ex); return(new GenericCommandResult(false, "Falha ao gravar enquete", null)); } }
public OptionPoll AppOption(OptionPoll option) { return(pollService.AddOption(option)); }