public HttpResponseMessage UpdateBlog([FromUri] int id, [FromBody] Blogs model) { BlogsService blogSvc = new BlogsService(); blogSvc.UpdateBlog(id, model); return(Request.CreateResponse(HttpStatusCode.OK, id)); }
public void GetBlogById_ShouldThrowKeyNotFoundException_IfInvalidIdIsGiven() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = GetTestData().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var expected = typeof(KeyNotFoundException); Type actual = null; try { var result = service.GetBlogById <BlogViewModel>(3); } catch (KeyNotFoundException e) { actual = e.GetType(); } //assert Assert.Equal(expected, actual); }
public async Task GetCountShouldWorkCorretly() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog = new Blog() { Id = 1, Name = "Name", }; var blog2 = new Blog() { Id = 2, Name = "Name", }; var blog3 = new Blog() { Id = 3, Name = "Name", }; await db.Blogs.AddRangeAsync(blog, blog2, blog3); await db.SaveChangesAsync(); Assert.Equal(3, service.GetCount()); }
public HttpResponseMessage CreateBlog(Blogs model) { BlogsService blogSvc = new BlogsService(); int id = blogSvc.CreateBlog(model); return(Request.CreateResponse(HttpStatusCode.OK, id)); }
public HttpResponseMessage DeleteBlog(int id) { BlogsService blogSvc = new BlogsService(); blogSvc.DeleteBlog(id); return(Request.CreateResponse(HttpStatusCode.OK, id)); }
public ProfilesController(ProfilesService service, BlogsService blogsService, CommentsService commentsService, AccountsService acctsService) { _service = service; _blogService = blogsService; _commentService = commentsService; _acctService = acctsService; }
public HttpResponseMessage GetBlogs() { BlogsService blogsSvc = new BlogsService(); List <Blogs> blogList = blogsSvc.GetBlogs(); return(Request.CreateResponse(HttpStatusCode.OK, blogList)); }
public void Create_ShouldCreateBlogAndReturnTheId() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var service = new BlogsService(repo.Object); //do var result = service.Create("Title", "Content"); //assert result.Should().NotBeNull().And.BeOfType <Task <int> >(); }
public async Task <IActionResult> SingleAsync( IFormFile file, string FileTitle) { try { if (HttpContext.Request.Form.Files.Any()) { // Only accept .zip files if (file.ContentType == "application/x-zip-compressed") { string path = Path.Combine( environment.WebRootPath, "files", file.FileName); // Create directory if not exists string directoryName = Path.GetDirectoryName(path); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } using (var stream = new FileStream(path, FileMode.Create)) { await file.CopyToAsync(stream); } // Save to database if (FileTitle == "") { FileTitle = "[Unknown]"; } FilesDTO objFilesDTO = new FilesDTO(); objFilesDTO.FileName = FileTitle; objFilesDTO.FilePath = file.FileName; BlogsService objBlogsService = new BlogsService(blogsContext, environment); await objBlogsService.CreateFilesAsync(objFilesDTO); } } return(StatusCode(200)); } catch (Exception ex) { return(StatusCode(500, ex.Message)); } }
public void GetBlogById_ShouldReturnTheViewModel_ForTheGivenId() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = GetTestData().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var result = service.GetBlogById <BlogViewModel>(1); //assert result.Should().NotBeNull().And.BeOfType <BlogViewModel>(); }
public void GetAll_ShouldReturnEmpty_WithNoDataGiven() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = new List <Blog>().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var result = service.GetAll(); //assert Assert.Empty(result); }
public void GetAll_ShouldReturnCorrectNumberOfBlogs() { Mapper.Initialize(x => x.AddProfile <MapperConfiguration>()); var repo = new Mock <IRepository <Blog> >(); var categories = GetTestData().AsQueryable(); repo.Setup(x => x.All()).Returns(categories); var service = new BlogsService(repo.Object); //do var result = service.GetAll(); //assert Assert.Equal(2, result.Count()); }
public async Task GetBlogsShouldReturnTheExactNumberOfBlogs() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog = new Blog() { Id = 1, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; var blog2 = new Blog() { Id = 2, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; var blog3 = new Blog() { Id = 3, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; await db.Blogs.AddRangeAsync(blog, blog2, blog3); await db.SaveChangesAsync(); var getBlogs = service.GetBlogs <BlogDetailsViewModel>(2); Assert.Equal(2, getBlogs.Count()); Assert.Equal(1, getBlogs.FirstOrDefault().Id); }
public async Task GetAllBlogsShouldReturnEveryBlog() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog = new Blog() { Id = 1, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; var blog2 = new Blog() { Id = 2, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; var blog3 = new Blog() { Id = 3, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; await db.Blogs.AddRangeAsync(blog, blog2, blog3); await db.SaveChangesAsync(); var getAll = service.GetAll <BlogDetailsViewModel>(1); Assert.Equal(3, getAll.Count()); }
public async Task EditBlogShouldEditProperly() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog = new Blog() { Id = 1, Name = "Name", Description = "Description", SubName = "SubName", Category = "Category", Author = "Author", }; AutoMapperConfig.RegisterMappings(typeof(EditBlogInputModel).Assembly); var blogEdit = new Web.ViewModels.Blog.EditBlogInputModel() { Id = 1, Name = "Name2", Description = "Description2", SubName = "SubName2", Category = "Category2", Author = "Author2", }; await db.Blogs.AddAsync(blog); await db.SaveChangesAsync(); await service.UpdateAsync(1, blogEdit); Assert.Equal("Name2", blog.Name); Assert.Equal("Description2", blog.Description); Assert.Equal("SubName2", blog.SubName); Assert.Equal("Category2", blog.Category); Assert.Equal("Author2", blog.Author); }
public async Task DeleteShouldWorkCorretly() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog = new Blog() { Id = 1, Name = "Name", }; await db.Blogs.AddAsync(blog); await db.SaveChangesAsync(); await service.DeleteAsync(1); Assert.Equal(0, db.Blogs.Count()); }
public async Task GetByIdShouldWorkCorrectly() { var db = GetDatabase(); var blogsRepository = new EfDeletableEntityRepository <Blog>(db); var service = new BlogsService(blogsRepository); var blog2 = new Blog() { Id = 2, Name = "Name", }; await db.Blogs.AddAsync(blog2); await db.SaveChangesAsync(); AutoMapperConfig.RegisterMappings(typeof(BlogDetailsViewModel).Assembly); var lol = service.GetById <BlogDetailsViewModel>(2); Assert.Equal(2, lol.Id); }
public AccountController(ProfilesService pservice, BlogsService bservice, CommentsService cservice) { _pservice = pservice; _bservice = bservice; _cservice = cservice; }
public BlogsController(BlogsService ks) { _ks = ks; }
public ProfileController(ProfilesService ps, BlogsService bs) { _ps = ps; _bs = bs; }
public AccountController(AccountsService service, BlogsService blogService, CommentsService commentService) { _service = service; _blogService = blogService; _commentService = commentService; }
public BlogsController(BlogsService bs) { _bs = bs; }
public BlogsController() { _service = new BlogsService(ModelState); }
public BlogsController(BlogsService service, CommentsService commentsService, ProfilesService profilesService) { _service = service; _commentsService = commentsService; _profileService = profilesService; }
public ProfilesController(ProfilesService pservice, BlogsService admservice) { _pservice = pservice; _admservice = admservice; }
public BlogsController(BlogsService blogsService, CommentsService commentsService) { _blogsService = blogsService; _commentsService = commentsService; }
public PostsController(PostsService postsService, BlogsService blogsService) { this.postsService = postsService; this.blogsService = blogsService; }
public BlogsController(BlogsService service) { _service = service; }
public AccountsController(AccountsService service, BlogsService blogsService) { _service = service; _blogsService = blogsService; }
public BlogsController(BlogsService service, AccountsService acctsService) { _service = service; _acctService = acctsService; }