public async Task <IActionResult> Create([Bind("category, url")] LinkCreationViewModel viewModel) { if (ModelState.IsValid) { await _linkRepository.AddLinkToDatabaseAsync(viewModel); if (Request.IsAjaxRequest()) { return(PartialView("Index", await _linkRepository.AllLinksToListAsync())); } return(RedirectToAction("Index")); } return(View(viewModel)); }
public async Task AddLinkToDatabaseAsyncTest() { providerClass provider = new providerClass(); ILinkRepository repository = provider.giveRepository(); ApplicationDbContext context = provider.giveContext(); LinkCreationViewModel testCreate = new LinkCreationViewModel(); testCreate.url = "yahoo.com"; testCreate.category = "unittestcat"; await repository.AddLinkToDatabaseAsync(testCreate); Assert.That(context.Links.Any(l => l.category.Name == testCreate.category && l.url == testCreate.url)); context.Links.Remove(context.Links.Single(l => l.category.Name == testCreate.category && l.url == testCreate.url)); context.SaveChanges(); }