public async Task <IActionResult> Delete(string hashtag, string name) { var recipeGuid = await this.GetRecipeGuid(name); var repository = new RecipeRepository(_settings.AzureStorageConnectionString); var item = await repository.GetAsync(recipeGuid); await repository.DeleteAsync(item); var viewModel = new HashtagLineViewModel(hashtag); return(Redirect(UrlBuilder.GetUrl(hashtag))); }
public async Task DeleteRecipe() { //Arrange Recipe recipe = new Recipe(); recipe.Id = 0; recipe.UserId = 1; recipe.Title = "recipe4"; recipe.Slug = "00-recipe4"; recipe.Instruction = "instruction4"; recipe.CreatedAt = DateTime.Now; //Act var addResult = await recipeRepository.AddAsync(recipe); //Assert Assert.IsNotNull(addResult); var deleteResult = await recipeRepository.DeleteAsync(addResult.Id); Assert.AreEqual(1, deleteResult); try { var getResult = await recipeRepository.GetByIdAsync(addResult.Id); } catch (InvalidOperationException) { //Success. } catch (Exception) { //Failure. //This assert statement ensures failure. Assert.AreEqual(1, 2); } }
public async Task <IActionResult> DeleteConfirmed(int id) { await _repository.DeleteAsync(id); return(RedirectToAction(nameof(Index))); }