public Result <Link> TrackClick(string shortcut) { var linkResult = _linkService.FindLinkByShortcut(shortcut); if (linkResult.Status != 200) { return(linkResult); } var click = new Click { DateTimeClicked = DateTime.UtcNow, LinkId = linkResult.Data.Id }; var success = _clickRepository.Create(click); if (!success) { return(new Result <Link>(500) { ErrorMessage = "Unable to track click" }); } else { return(_linkService.FindLinkByShortcut(shortcut)); } }
public void Create_ValidClickSupplied_CreatesClick() { var validLink = new Link { Id = 4, Url = "https://test.com/" }; var validClick = new Click { Id = 1, DateTimeClicked = DateTime.UtcNow, }; _applicationDbContext.Setup(a => a.AddClick(validClick)); _applicationDbContext.Setup(a => a.SaveChanges()).Returns(1); var result = _clickRepository.Create(validClick); Assert.True(result); }