Ejemplo 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());
        }
Ejemplo 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());
        }
Ejemplo 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());
        }
Ejemplo n.º 4
0
        public void GetCategoryTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            applicationDbContext.PostCategories.Add(new PostCategory()
            {
                Id = Guid.Parse("44c8487f-6cd4-49c7-ae20-0af6f08e557d")
            });
            applicationDbContext.SaveChanges();
            var postCategory = postCategoryService.Get(Guid.Parse("44c8487f-6cd4-49c7-ae20-0af6f08e557d"));

            Assert.NotNull(postCategory);
            Assert.IsType <PostCategory>(postCategory);
            Assert.Equal(Guid.Parse("44c8487f-6cd4-49c7-ae20-0af6f08e557d"), postCategory.Id);
        }
 public HttpResponseMessage Update(HttpRequestMessage request, PostCategoryModel PostCategoryModel)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var PostCategoryService = new PostCategoryService();
             PostCategoryService.Update(PostCategoryModel);
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
 public HttpResponseMessage DeleteMulti(HttpRequestMessage request, int[] id)
 {
     return(CreateHttpResponse(request, () =>
     {
         HttpResponseMessage response = null;
         if (!ModelState.IsValid)
         {
             response = request.CreateResponse(HttpStatusCode.BadRequest, ModelState);
         }
         else
         {
             var PostCategoryService = new PostCategoryService();
             PostCategoryService.DeleteAll(id);
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         return response;
     }));
 }
Ejemplo n.º 7
0
        public void GetCategoriesTests()
        {
            var builder = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(Guid.NewGuid().ToString());

            applicationDbContext = new ApplicationDbContext(builder.Options, _configuration);
            repository           = new Repository <PostCategory>(applicationDbContext);
            postCategoryService  = new PostCategoryService(repository);
            for (int i = 0; i < 10; i++)
            {
                applicationDbContext.PostCategories.Add(new PostCategory()
                {
                    Id = Guid.NewGuid()
                });
            }
            applicationDbContext.SaveChanges();
            var postCategory = postCategoryService.GetAll();

            Assert.NotNull(postCategory);
            Assert.Equal(10, postCategory.Count());
        }
Ejemplo n.º 8
0
 public void Initialize()
 {
     _categoryRepository = new Mock <IPostCategoryRepository>();
     _unitOfWork         = new Mock <IUnitOfWork>();
     _categoryService    = new PostCategoryService(_categoryRepository.Object, _unitOfWork.Object);
     _postCategoryList   = new List <PostCategory>()
     {
         new PostCategory()
         {
             ID = 1, Name = "MD1"
         },
         new PostCategory()
         {
             ID = 2, Name = "MD2"
         },
         new PostCategory()
         {
             ID = 3, Name = "MD3"
         },
     };
 }
        private PostCategoryService GetMockedPostCategoryService()
        {
            var mockedDbContext = MockDefaultHelper
                                  .GetMockedDbContext()
                                  .AddMockedCategories();

            var mockedDbContextQuery = MockDefaultHelper
                                       .GetMockedDbContext()
                                       .AddMockedCategories();

            var mockedCategoryValidator = new CategoryValidator();

            var mockedPostCategorySpecificationsValidator = new PostCategorySpecificationsValidator();

            var mockedPostCategoryService = new PostCategoryService(
                mockedDbContext.Object,
                mockedCategoryValidator,
                mockedPostCategorySpecificationsValidator);

            return(mockedPostCategoryService);
        }
Ejemplo n.º 10
0
 public void Initialize()
 {
     PostCategoryService = new PostCategoryService();
 }
Ejemplo n.º 11
0
 public PostCategoryController(ErrorService errorService, PostCategoryService postCategoryService) :
     base(errorService)
 {
     _postCategoryService = postCategoryService;
 }
Ejemplo n.º 12
0
 public PostCategoryController(PostCategoryService postCategoryService, IMapper mapper)
 {
     _postCategoryService = postCategoryService;
     _mapper = mapper;
 }
Ejemplo n.º 13
0
 public PostCategoriesController(PostCategoryService categoryService)
 {
     _categoryService = categoryService;
 }