public void GetRecipeById_IdDoesNotExistsInDb_ShouldReturnBadRequest() { _service.Setup(s => s.GetRecipeById(1)).Returns((Recipe)null); var result = _controller.GetRecipeById(1); Assert.That(result, Is.TypeOf <NotFoundObjectResult>()); }
public void GetRecipeByID_Returns404NotFound_WhenNonExistentIDProvided() { mockRepo.Setup(repo => repo.GetRecipeById(0)).Returns(() => null); var controller = new RecipesController(mockRepo.Object, mapper); var result = controller.GetRecipeById(1); Assert.IsType <NotFoundResult>(result.Result); }
public async Task GetRecipeById_Returns_NotFound_When_Recipe_Doesnt_Exist() { // Arrange var recipesService = Substitute.For <IRecipesService>(); recipesService.FindAsync(Arg.Any <Guid>()).Returns(null as Recipe); var controller = new RecipesController(recipesService, AutoMapper.Mapper.Instance); // Act var result = await controller.GetRecipeById(Guid.NewGuid()); // Assert Assert.True(result.GetType().IsAssignableFrom(typeof(NotFoundResult))); }
public void GetRecipeById_ReturnsRecipeReadDto_WhenValidIDProvided() { mockRepo.Setup(repo => repo.GetRecipeById(1)).Returns(new Recipe { Id = 1, Title = "mock", Ingredients = "mock", Instructions = "mock", Description = "mock", Source = "mock", Rating = 5, PrepTime = "mock", ImageURL = "sampleURL.com/image.jpg" }); var controller = new RecipesController(mockRepo.Object, mapper); var result = controller.GetRecipeById(1); Assert.IsType <ActionResult <RecipeReadDto> >(result); }