public void Add_WhenNameIsValid_ShouldAddTheCategory()
        {
            bool isItemAdded = false;
            var repository = Mock.Create<IRepository<Category>>();

            var categoryModel = new CategoryModel()
            {
                Name = "NEW TEST NAME"
            };
            var categoryEntity = new Category()
            {
                Id = 1,
                Name = categoryModel.Name
            };
            Mock.Arrange(() => repository.Add(Arg.IsAny<Category>()))
                .DoInstead(() => isItemAdded = true)
                .Returns(categoryEntity);

            var controller = new CategoriesController(repository);
            SetupController(controller);

            controller.PostCategory(categoryModel);

            Assert.IsTrue(isItemAdded);
        }
 public void MyTestMethod2()
 {
     var cat = new Category()
     {
         Name = "TEST EDI KVO SI "
     };
     dbContext.Set<Category>().Add(cat);
     dbContext.SaveChanges();
     Assert.IsTrue(cat.Id > 0);
 }
        public void Add_WhenNameIsValid_ShouldReturnNotZeroId()
        {
            //using (TransactionScope scope = new TransactionScope())
            //{
            var categoryName = "Test category";
            var category = new Category()
            {
                Name = categoryName
            };

            var createdCategory = this.categoriesRepository.Add(category);
            Assert.IsTrue(createdCategory.Id != 0);
            //}
        }
        public void Add_WhenNameIsValid_ShouldAddCategoryToDatabase()
        {
            //using (TransactionScope scope = new TransactionScope())
            //{
            var categoryName = "Test category";
            var category = new Category()
            {
                Name = categoryName
            };

            var createdCategory = this.categoriesRepository.Add(category);
            var foundCategory = this.dbContext.Set<Category>().Find(createdCategory.Id);
            Assert.IsNotNull(foundCategory);
            Assert.AreEqual(categoryName, foundCategory.Name);
            //}
        }
        public void GetAll_WhenASingleCategoryInRepository_ShouldReturnSingleCategory()
        {
            var repository = Mock.Create<IRepository<Category>>();            
            var categoryToAdd = new Category()
            {
                Name = "Test category"
            };
            IList<Category> categoryEntities = new List<Category>();
            categoryEntities.Add(categoryToAdd);
            Mock.Arrange(() => repository.All()).Returns(() => categoryEntities.AsQueryable());

            var controller = new CategoriesController(repository);

            var categoryModels = controller.GetAll();
            Assert.IsTrue(categoryModels.Count() == 1);
            Assert.AreEqual(categoryToAdd.Name, categoryModels.First().Name);
        }
        public HttpResponseMessage PostCategory(CategoryModel model)
        {
            var entityToAdd = new Category()
            {
                Name = model.Name
            };

            var createdEntity = this.categoriesRepository.Add(entityToAdd);


            var createdModel = new CategoryModel()
            {
                Id = createdEntity.Id,
                Name = createdEntity.Name
            };

            var response = Request.CreateResponse<CategoryModel>(HttpStatusCode.Created, createdModel);
            var resourceLink = Url.Link("DefaultApi", new { id = createdModel.Id });

            response.Headers.Location = new Uri(resourceLink);
            return response;
        }
        public void GetAllCategories_WhenASingleCategoryInRepository_ShouldReturnSingleCategory()
        {
            var repository = new FakeRepository<Category>();

            var categoryToAdd = new Category()
            {
                Name = "Test category"
            };
            repository.entities.Add(categoryToAdd);

            var controller = new CategoriesController(repository);

            var categoriesModels = controller.GetAll();
            Assert.IsTrue(categoriesModels.Count() == 1);
            Assert.AreEqual(categoryToAdd.Name, categoriesModels.First().Name);
        }
 public void MyTestMethod()
 {
     int catId = 0;
     using (TransactionScope scope = new TransactionScope())
     {
         var cat = new Category()
         {
             Name = "NEW CATEGORY"
         };
         this.dbContext.Set<Category>().Add(cat);
         this.dbContext.SaveChanges();
         scope.Complete();
         catId = cat.Id;
     }
     Assert.IsTrue(catId != 0);
     var catEntity = this.dbContext.Set<Category>().Find(catId);
     Assert.IsNotNull(catEntity);
 }