public void TestGetAllCategoryIngredient()
        {
            var repository          = new Mock <IRepository <CategoryIngredient> >();
            var categoryIngredients = new List <CategoryIngredient>();
            var r1 = new CategoryIngredient()
            {
                categoryId = 1, name = "fromage"
            };
            var r2 = new CategoryIngredient()
            {
                categoryId = 2, name = "fruit"
            };
            var r3 = new CategoryIngredient()
            {
                categoryId = 3, name = "poisson"
            };

            categoryIngredients.Add(r1);
            categoryIngredients.Add(r2);
            categoryIngredients.Add(r3);
            repository.Setup(x => x.GetAll()).Returns(categoryIngredients.AsQueryable()).Verifiable();
            var controller = new CategoryIngredientsController(repository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var response = controller.Get();
            IQueryable <CategoryIngredient> s;

            Assert.IsTrue(response.TryGetContentValue <IQueryable <CategoryIngredient> >(out s));
            Assert.AreEqual(categoryIngredients.AsQueryable().Count(), s.Count());
            Assert.AreEqual(categoryIngredients.AsQueryable().First(), s.First());
        }
Exemplo n.º 2
0
        public HttpResponseMessage Post(CategoryIngredient entity)
        {
            var res = _repo.Add(entity);

            if (!res)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }
            return(Request.CreateResponse(HttpStatusCode.Created, entity));
        }
Exemplo n.º 3
0
        public HttpResponseMessage Get(int id)
        {
            CategoryIngredient res = _repo.Get(id);

            if (res == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }
            return(Request.CreateResponse(res));
        }
        public void TestPostCategoryIngredient()
        {
            var repository         = new Mock <IRepository <CategoryIngredient> >();
            var categoryIngredient = new CategoryIngredient()
            {
                categoryId = 1, name = "fromage"
            };

            repository.Setup(x => x.Add(categoryIngredient)).Returns(true).Verifiable();
            var controller = new CategoryIngredientsController(repository.Object);

            controller.Request       = new HttpRequestMessage();
            controller.Configuration = new HttpConfiguration();

            var response = controller.Post(categoryIngredient);
            CategoryIngredient s;

            Assert.IsTrue(response.TryGetContentValue <CategoryIngredient>(out s));
            Assert.AreEqual(categoryIngredient, s);
            Assert.AreNotEqual(10, s.categoryId);
        }