public async Task UpdateAsync(SiteRule rule, SiteRule updatedRule) { _db .Entry(updatedRule) .CurrentValues .SetValues(updatedRule); }
public async void Post_PersistsRule_WithSiteRuleService() { var rule = new SiteRule(); await _controller.Post(rule); _mockSiteRuleService.Verify(m => m.CreateSiteRuleAsync(rule), Times.Once); }
public async Task <IActionResult> Put(int userId, int siteId, [FromBody] SiteRule updatedRule) { var rule = await FindOrThrowAsync(userId, siteId); await _siteRuleService.UpdateSiteRuleAsync(rule, updatedRule); return(NoContent()); }
public async void Post_InvalidModelState_ThrowsError() { _controller.ModelState.AddModelError("mock", "error"); var rule = new SiteRule(); Func <Task> act = () => _controller.Post(rule); await Assert.ThrowsAsync <HttpException>(act); }
public SiteRuleResource(SiteRule rule) { UserId = rule.UserId; SiteId = rule.SiteId; Domain = rule.Site?.Domain; Time = rule.Time; Points = rule.Points; Created = rule.Created; Modified = rule.Modified; }
public async void Delete_DeletesSiteRule_WithSiteRuleService() { var userId = 1; var siteId = 1; var existingSiteRule = new SiteRule(); _mockSiteRuleService.Setup(m => m.FindSiteRuleAsync(userId, siteId)).ReturnsAsync(existingSiteRule); await _controller.Delete(userId, siteId); _mockSiteRuleService.Verify(m => m.DeleteSiteRuleAsync(existingSiteRule), Times.Once); }
public async void Put_UpdatesSiteRule_WithSiteRuleService() { var userId = 1; var siteId = 1; var existingRule = new SiteRule(); var updatedRule = new SiteRule(); _mockSiteRuleService.Setup(m => m.FindSiteRuleAsync(userId, siteId)).ReturnsAsync(existingRule); await _controller.Put(userId, siteId, updatedRule); _mockSiteRuleService.Verify(m => m.UpdateSiteRuleAsync(existingRule, updatedRule), Times.Once); }
public async Task <IActionResult> Post([FromBody] SiteRule rule) { if (!ModelState.IsValid) { throw new HttpException(HttpStatusCode.BadRequest, ModelState.GetErrors()); } await _siteRuleService.CreateSiteRuleAsync(rule); var associatedSite = await _siteService.FindSiteAsync(rule.SiteId); rule.Site = associatedSite; return(CreatedAtAction("Get", new { rule.UserId, rule.SiteId }, new SiteRuleResource(rule))); }
public async void Post_AssignsAssociatedSite() { var site = new Site() { Id = 1, Domain = "foo.com" }; var rule = new SiteRule() { SiteId = site.Id }; _mockSiteService.Setup(m => m.FindSiteAsync(rule.SiteId)).ReturnsAsync(site); await _controller.Post(rule); _mockSiteService.Verify(m => m.FindSiteAsync(rule.SiteId), Times.Once); Assert.Equal(rule.Site, site); }
public async Task UpdateSiteRuleAsync(SiteRule rule, SiteRule updatedRule) { await _siteRuleRepository.UpdateAsync(rule, updatedRule); await _work.CompleteAsync(); }
public async Task DeleteSiteRuleAsync(SiteRule rule) { await _siteRuleRepository.DeleteAsync(rule); await _work.CompleteAsync(); }
public async Task DeleteAsync(SiteRule rule) { _db .SiteRules .Remove(rule); }
public async Task CreateAsync(SiteRule rule) { await _db .SiteRules .AddAsync(rule); }