public EntityAction Create(PostCreateModel entity) { if (SlugExsits(entity.Slug)) { return(EntityAction.Exception); } entity.PostId = rep.GetNextId(); var post = entity.ToPost(); EntityAction result = rep.Create(post); return(result); }
public EntityAction Update(PostCreateModel entity) { //Todo: The Slug Has Not Exsits var post = rep.Get(entity.PostId); //post.CategoryId; post.Category = null; entity.ToPost(post); EntityAction result = rep.Update(post); return(result); }
public void Articles_Service_Post_Update_Test() { Mock <IPostRepository> rep = new Mock <IPostRepository>(); rep.Setup(a => a.GetNextId()).Returns(1); AuthorRefrence author = new AuthorRefrence(lastName: "test", name: "test", userName: "******" ); author.Id = 1; Category cat = new Category(name: "test", slug: "test", isParent: true, lineAge: ""); cat.Id = 1; var modttel = new PostCreateModel() { AuthorId = 1, CategoryId = 1, Content = " ", Description = " ", PostId = 1, PostImage = " ", PublishedDate = null, SendDate = PersianDate.Now, Slug = "Tala", TagId = 1, Title = " salam ", VisitCount = 1, }; var model = modttel.ToPost(); rep.Setup(a => a.Update(model)).Returns(EntityAction.Updated); IPostService service = new PostService(rep.Object); var result = service.Update(modttel); Assert.AreEqual(result, EntityAction.None); }