public void Articles_Data_Post_Insert_Test() { 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 model = new Post(title: "Test", sendDate: DateTime.Now, publishedDate: null, visitCount: 0, content: "test", description: "test", postImage: "test", slug: "test", authorId: 1, tagId: 1, categoryId: 1, author: author, category: cat) { Id = rep.GetNextId() }; uni.BeginTransAction(); EntityAction result = rep.Create(model); Assert.AreEqual(result, EntityAction.Added); uni.RollBack(); }
public void Articles_Service_Post_Get_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 model = new Post(title: "Test", sendDate: DateTime.Now, publishedDate: null, visitCount: 0, content: "test", description: "test", postImage: "test", slug: "test", authorId: 1, tagId: 1, categoryId: 1, author: author, category: cat) { Id = rep.Object.GetNextId() }; rep.Setup(a => a.Get(1)).Returns(model); IPostService service = new PostService(rep.Object); var result = service.Get(1); Assert.IsNotNull(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); }