Esempio n. 1
0
        public void AddCategoryTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            postCategoryService.Add(new PostCategory()
            {
                Id = Guid.Parse("60a233e0-5fa1-4ee4-97aa-ddaa786d80fa")
            });
            Assert.Equal(1, applicationDbContext.PostCategories.Count());
        }
Esempio n. 2
0
        public void RemoveCategoryTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            postCategoryService.Add(new PostCategory()
            {
                Id = Guid.Parse("1717fcb1-f767-4652-ac64-7c265eafd571")
            });
            applicationDbContext.SaveChanges();
            postCategoryService.Remove(Guid.Parse("1717fcb1-f767-4652-ac64-7c265eafd571"));
            Assert.Equal(0, applicationDbContext.PostCategories.Count());
        }
Esempio n. 3
0
        public void UpdateCategoryTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            postCategoryService.Add(new PostCategory()
            {
                Id = Guid.Parse("117f991d-1f09-4a02-9880-e8fb1bdf287d")
            });
            applicationDbContext.SaveChanges();
            PostCategory postCategory = applicationDbContext.PostCategories.SingleOrDefault(s => s.Id == Guid.Parse("117f991d-1f09-4a02-9880-e8fb1bdf287d"));

            postCategoryService.Update(postCategory);
            Assert.Equal(1, applicationDbContext.PostCategories.Count());
        }
Esempio n. 4
0
        public void PostCategory_Create()
        {
            PostCategory category = new PostCategory();
            int          id       = 1;

            category.Name  = "Test2";
            category.Alias = "TEst22";

            //setup
            _categoryRepository.Setup(m => m.Add(category)).Returns((PostCategory p)
                                                                    =>
            {
                p.ID = 1;
                return(p);
            });
            var result = _categoryService.Add(category);

            Assert.AreEqual(1, result.ID);
        }
Esempio n. 5
0
        public HttpResponseMessage Post(HttpRequestMessage request, PostCategoryViewModel postCategoryVM)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                if (ModelState.IsValid)
                {
                    request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
                }
                else
                {
                    PostCategory newPostCategory = new PostCategory();
                    newPostCategory.UpdatePostCategory(postCategoryVM);

                    var category = _postCategoryService.Add(newPostCategory);
                    _postCategoryService.Save();

                    response = request.CreateResponse(HttpStatusCode.Created, category);
                }
                return response;
            }));
        }