public void TestGetRecipes() { var result = rc.GetRecipes(1); Assert.Equal(context.Recipes.ToList()[0], result.ToList()[0]); Assert.Equal(context.Recipes.ToList()[1], result.ToList()[1]); Assert.Equal(context.Recipes.ToList()[2], result.ToList()[2]); }
public void GetRecipes_Returns_OkNegotiatedContentResult() { // Arrange var mockRepository = new Mock <IRecipesRepository>(); var controller = new RecipesController(mockRepository.Object); // Act IHttpActionResult actionResult = controller.GetRecipes(); // Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <IQueryable <Recipe> >)); }
public void GetRecipes_ReturnsBadRequestResult_IfRecipeIdIsLessThanZero() { //Arrange var repoMock = new Mock <IRecipesRepository>(MockBehavior.Loose); var controller = new RecipesController(repoMock.Object); var invalidId = -5; //Act var result = controller.GetRecipes(invalidId); //Assert Assert.IsType <BadRequestResult>(result); }
public void GetRecipes_ReturnsNotFoundResult_IfNoSuchRecipeExists() { //Arrange var repoMock = new Mock <IRecipesRepository>(MockBehavior.Loose); var controller = new RecipesController(repoMock.Object); var invalidId = 8500; //Act var result = controller.GetRecipes(invalidId); //Assert Assert.IsType <NotFoundResult>(result); }
public async Task Gets_All_Recipes() { var recipes = await _fixture.Context.Recipes .AsNoTracking() .Select(r => new { r.Id, r.Name }) .ToListAsync(); var actuals = (await _controller.GetRecipes()) .ToList(); actuals.Should().BeEquivalentTo(recipes); }
public void GetRecipes_Empty_ReturnsOk() { // Arrange recipesServiceMock = new Mock <IRecipesService>(); recipesServiceMock .Setup(m => m.GetRecipes()) .Returns(new List <RecipeDto>()); recipesController = new RecipesController(recipesServiceMock.Object, mapper); // Act var result = recipesController.GetRecipes(); // Assert Assert.IsTrue(result.GetType() == typeof(OkObjectResult)); }
public void GetRecipes_Success() { var result = _recipesController.GetRecipes(); result.Should().NotBeNull(); try { var res = (Microsoft.AspNetCore.Mvc.OkObjectResult)result; res.StatusCode.Should().Be((int)HttpStatusCode.OK); } catch (Exception) { var res = (Microsoft.AspNetCore.Mvc.NoContentResult)result; res.StatusCode.Should().Be((int)HttpStatusCode.NoContent); } }
public void GetReturnsRecipeWithSameId() { // Arrange var mockRepository = new Mock <IRecipesRepository>(); mockRepository.Setup(x => x.GetRecipe(12)) .Returns(new Recipe { Id = 12 }); var controller = new RecipesController(mockRepository.Object); // Act IHttpActionResult actionResult = controller.GetRecipes(12); var contentResult = actionResult as OkNegotiatedContentResult <Recipe>; // Assert Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(12, contentResult.Content.Id); }
public void GetAllRecipesTest() { List <Recipe> listExpected = new List <Recipe>(); var recipe1 = new Recipe() { Description = "Test description 1", Hidden = false, Id = 1, Name = "Test Recipe Name 1", UserId = "user1" }; var recipe2 = new Recipe() { Description = "Test description 2", Hidden = false, Id = 2, Name = "Test Recipe Name 2", UserId = "user2" }; var recipe3 = new Recipe() { Description = "Test description 3", Hidden = false, Id = 3, Name = "Test Recipe Name 3", UserId = "user1" }; listExpected.Add(recipe1); listExpected.Add(recipe2); listExpected.Add(recipe3); _recipesService.Setup(i => i.GetRecipes()) .Returns(listExpected); var result = _recipesController.GetRecipes(); Assert.AreEqual(result, listExpected); }
public void GetRecipes_ReturnsJsonResultWithRecipeDtos_GivenValidParentId() { //Arrange var repoMock = new Mock <IRecipesRepository>(); repoMock.Setup(repo => repo.GetRecipes(0)) .Returns(new Dictionary <RecipeNode, RecipeLogEntry>() { { new RecipeNode() { RecipeID = 1, AncestryPath = "1/" }, new RecipeLogEntry() { VersionID = 1, RecipeID = 1, Title = "Pizza", Description = "Pizza description" } }, { new RecipeNode() { RecipeID = 2, AncestryPath = "2/" }, new RecipeLogEntry() { VersionID = 2, RecipeID = 2, Title = "Cake", Description = "Cake description" } }, { new RecipeNode() { RecipeID = 3, AncestryPath = "3/" }, new RecipeLogEntry() { VersionID = 3, RecipeID = 3, Title = "Taco", Description = "Taco description" } } }); var controller = new RecipesController(repoMock.Object); var expectedResult = new[] { new RecipeDto() { RecipeID = 1, AncestryPath = "1/", Title = "Pizza", Description = "Pizza description" }, new RecipeDto() { RecipeID = 2, AncestryPath = "2/", Title = "Cake", Description = "Cake description" }, new RecipeDto() { RecipeID = 3, AncestryPath = "3/", Title = "Taco", Description = "Taco description" } }; //Act var result = controller.GetRecipes(0); //Assert var actualResult = Assert.IsType <JsonResult>(result); Assert.True(expectedResult.SequenceEqual((IEnumerable <RecipeDto>)(actualResult.Value), new RecipeDtoEqualityComparer())); }