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()); }
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()); }
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()); }
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; })); }
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()); }
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); }
public void Initialize() { PostCategoryService = new PostCategoryService(); }
public PostCategoryController(ErrorService errorService, PostCategoryService postCategoryService) : base(errorService) { _postCategoryService = postCategoryService; }
public PostCategoryController(PostCategoryService postCategoryService, IMapper mapper) { _postCategoryService = postCategoryService; _mapper = mapper; }
public PostCategoriesController(PostCategoryService categoryService) { _categoryService = categoryService; }