public async Task CreateAsync(Countdown countdown) { using (SqlConnection connection = Connection) { const string query = "INSERT INTO Countdowns (Description, EndsOn, CreatedOn, CreatedById) " + "OUTPUT INSERTED.Id " + "VALUES (@Description, @EndsOn, @CreatedOn, @CreatedById)"; countdown.Id = (await connection.QueryAsync<long>(query, countdown)).Single(); } }
public Task CreateAsync(Countdown countdown) { return Task.Run(() => InMemoryCountdowns.Add(countdown)); }
public async Task VoteWithCountdownId_CreatesANotificationForTheOwner() { var voteService = TestableVoteService.Create(); var countdownVote = new Vote { CountdownId = TestableVoteService.CountdownId, CastedById = TestableVoteService.AccountId, Value = 1 }; var countdown = new Countdown { Description = "Test description", Id = TestableVoteService.CountdownId }; voteService.MockCountdownRepository .Setup(x => x.GetByIdAsync(TestableVoteService.CountdownId)) .Returns(Task.FromResult(countdown)); await voteService.CastAsync(countdownVote); string expectedContent = string.Format("Upvoted on a Countdown - <a href=\"/Countdown/{0}\">{1}</a>", countdown.Id, countdown.Description); voteService.MockNotificationDispatcher .Verify(x => x.Dispatch( It.Is<Notification>( n => n.AccountId == TestableVoteService.OwnerId && n.Content == expectedContent && n.Read == false && // TODO - Refactor this DateTime bit -> Possibly Inject an IClock and mock it (n.CreatedOn.Date == DateTime.UtcNow.Date && n.CreatedOn.Hour == DateTime.UtcNow.Hour && n.CreatedOn.Minute == DateTime.UtcNow.Minute) && n.ReadOn == null && n.Type == NotificationType.Vote )), Times.Once()); }
public static void ExtractUpdates(this CountdownViewModel countdownViewModel, Countdown countdown) { Mapper.Map(countdown, countdownViewModel); }