public async Task RemoveComment_RemovingComment_MethodFailed() { var data = new List <Comments> { new Comments { id = 1, comment = "BBB" }, new Comments { id = 2, comment = "ZZZ" } }.AsQueryable(); var mockSet = new Mock <DbSet <Comments> >(); mockSet.As <IDbAsyncEnumerable <Comments> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Comments>(data.GetEnumerator())); mockSet.As <IQueryable <Comments> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Comments>(data.Provider)); mockSet.As <IQueryable <Comments> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Comments> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Comments> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <PlaceReviewerDbEntities>(); mockContext.Setup(m => m.Comments).Returns(mockSet.Object); var commentLogic = new CommentLogic { Context = mockContext.Object }; var b = await commentLogic.RemoveComment(5); Assert.AreEqual(b, 0); mockSet.Verify(m => m.Remove(It.IsAny <Comments>()), Times.Never); mockContext.Verify(m => m.SaveChangesAsync(), Times.Never); }
public async Task GetComment_ReturningCommentWithSprecifiedId_NullReturned() { var data = new List <Comments> { new Comments { id = 1, comment = "BBB" }, new Comments { id = 2, comment = "ZZZ" }, new Comments { id = 3, comment = "AAA" } }.AsQueryable(); var mockSet = new Mock <DbSet <Comments> >(); mockSet.As <IDbAsyncEnumerable <Comments> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Comments>(data.GetEnumerator())); mockSet.As <IQueryable <Comments> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Comments>(data.Provider)); mockSet.As <IQueryable <Comments> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Comments> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Comments> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <PlaceReviewerDbEntities>(); mockContext.Setup(c => c.Comments).Returns(mockSet.Object); var logic = new CommentLogic { Context = mockContext.Object }; var comment = await logic.GetComment(4); Assert.AreEqual(comment.Id, -1); }
public async Task <Result> AddAsync(CommentLogic comment) { try { comment.Id = Guid.NewGuid().ToString(); comment.PostDate = DateTime.Now; var commentDb = mapper.Map <CommentLogic, CommentDb>(comment); var result = await dbmanager.AddAsync(commentDb); return(Result.Ok()); } catch (DbUpdateConcurrencyException e) { return(Result.Fail(e.Message)); } catch (DbUpdateException e) { return(Result.Fail(e.Message)); } catch (DbEntityValidationException e) { return(Result.Fail(e.Message)); } catch (Exception) { return(Result.Fail("Exception")); } }
public Result DeleteAsync(CommentLogic comment, UserLogic user) { try { if (user.Comments.Contains(comment) || user.IsAdmin) { var commentDb = mapper.Map <CommentLogic, CommentDb>(comment); dbmanager.RemoveAsync(commentDb); return(Result.Ok()); } else { return(Result.Fail("Unauthorized")); } } catch (DbUpdateConcurrencyException e) { return(Result.Fail(e.Message)); } catch (DbUpdateException e) { return(Result.Fail(e.Message)); } catch (DbEntityValidationException e) { return(Result.Fail(e.Message)); } catch (Exception) { return(Result.Fail("Exception")); } }
public async Task SaveComment_UpdatingValidComment_CommentUpdated() { var data = new List <Comments> { new Comments { id = 999, comment = "q", placeId = "a", userId = 1 } }.AsQueryable(); var mockSet = new Mock <DbSet <Comments> >(); mockSet.As <IDbAsyncEnumerable <Comments> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Comments>(data.GetEnumerator())); mockSet.As <IQueryable <Comments> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Comments>(data.Provider)); mockSet.As <IQueryable <Comments> >().Setup(m => m.Expression).Returns(data.Expression); var mockContext = new Mock <PlaceReviewerDbEntities>(); mockContext.Setup(m => m.Comments).Returns(mockSet.Object); var commentLogic = new CommentLogic { Context = mockContext.Object }; var b = await commentLogic.SaveComment(new DtoComment { Id = 999, Login = "******", Comment = "aaaa", PlaceId = "[email protected]" }); Assert.AreEqual(b, 1); mockSet.Verify(m => m.Add(It.IsAny <Comments>()), Times.Never); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }
public FormComment(ArticleLogic logicA, UserLogic logicU, CommentLogic logicC) { InitializeComponent(); this.logicA = logicA; this.logicC = logicC; this.logicU = logicU; }
public ReleaseController(IHostingEnvironment he, IConfiguration configuration) { this.he = he; mapper = new ReleaseMapper(LogicFactory.CreateTimeCalculationLogic()); releaseLogic = LogicFactory.CreateReleaseLogic(); commentLogic = LogicFactory.CreateCommentLogic(); timeLogic = LogicFactory.CreateTimeCalculationLogic(); }
public VideoController(VideoLogic videoLogic, CategoryLogic categoryLogic, ReportLogic reportLogic, CommentLogic commentLogic, UserLogic userLogic, IHostingEnvironment environment) { _videoLogic = videoLogic; _categoryLogic = categoryLogic; _reportLogic = reportLogic; _commentLogic = commentLogic; _userLogic = userLogic; _environment = environment; }
public async Task <HttpResponseMessage> SaveComment(string comment, int id, string login, string placeId) { var response = Request.CreateResponse(HttpStatusCode.OK, new DtoResponse { Success = await new CommentLogic().SaveComment(new DtoComment { Comment = comment, Id = id, Login = login, PlaceId = placeId, Date = CommentLogic.GetDateTimeNow().ToString("g", CultureInfo.InvariantCulture) }) }); return(response); }
public async Task GetAllComments_ReturningAllComments_AllCommentsReturned() { var data = new List <Comments> { new Comments { comment = "BBB", userId = 1, Users = new Users { id = 1 }, placeId = "a" }, new Comments { comment = "ZZZ", userId = 1, Users = new Users { id = 1 }, placeId = "a" }, new Comments { comment = "AAA", userId = 1, Users = new Users { id = 1 }, placeId = "a" } }.AsQueryable(); var mockSet = new Mock <DbSet <Comments> >(); mockSet.As <IDbAsyncEnumerable <Comments> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Comments>(data.GetEnumerator())); mockSet.As <IQueryable <Comments> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Comments>(data.Provider)); mockSet.As <IQueryable <Comments> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Comments> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Comments> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <PlaceReviewerDbEntities>(); mockContext.Setup(c => c.Comments).Returns(mockSet.Object); var logic = new CommentLogic { Context = mockContext.Object }; var com = await logic.GetComments("a"); Assert.AreEqual(3, com.Length); Assert.AreEqual("BBB", com[0].Comment); Assert.AreEqual("ZZZ", com[1].Comment); Assert.AreEqual("AAA", com[2].Comment); }
public List <Comment> CommentId(int id) { List <Comment> cList = new List <Comment>(); CommentLogic cLogic = new CommentLogic(); List <CommentLogic> cLogicList = cLogic.CommentId(id); foreach (CommentLogic listObj in cLogicList) { Comment comment = new Comment(); comment.id = listObj.id; comment.sender = listObj.sender; comment.text = listObj.text; comment.postDate = listObj.date; cList.Add(comment); } return(cList); }
public ActionResult CommentAdd(string AdvertisementId, string sender, string CommentText) { foreach (Advertisement item in (List <Advertisement>)Session["AdverId"]) { AdvertisementId = item.id.ToString(); } if (String.IsNullOrWhiteSpace(CommentText)) { ViewData["message"] = "Write a comment before submiting"; } else { CommentLogic cLogic = new CommentLogic(); cLogic.CommentAdd(Convert.ToInt32(AdvertisementId), Session["username"].ToString(), CommentText, DateTime.Now); Comment cModel = new Comment(); List <Comment> cList = cModel.CommentId(Convert.ToInt32(AdvertisementId)); ViewBag.commentList = cList; } return(View("Page")); }
public async Task SaveComment_AddingValidComment_CommentAdded() { var data = new List <Comments>().AsQueryable(); var mockSet = new Mock <DbSet <Comments> >(); mockSet.As <IDbAsyncEnumerable <Comments> >() .Setup(m => m.GetAsyncEnumerator()) .Returns(new TestDbAsyncEnumerator <Comments>(data.GetEnumerator())); mockSet.As <IQueryable <Comments> >() .Setup(m => m.Provider) .Returns(new TestDbAsyncQueryProvider <Comments>(data.Provider)); mockSet.As <IQueryable <Comments> >().Setup(m => m.Expression).Returns(data.Expression); var mockContext = new Mock <PlaceReviewerDbEntities>(); mockContext.Setup(m => m.Comments).Returns(mockSet.Object); var commentLogic = new CommentLogic { Context = mockContext.Object }; var b = await commentLogic.SaveComment(new DtoComment()); Assert.AreEqual(b, 1); mockSet.Verify(m => m.Add(It.IsAny <Comments>()), Times.Once()); mockContext.Verify(m => m.SaveChangesAsync(), Times.Once()); }
public void Setup() { commentLogic = new CommentLogic(new CommentMemoryContext()); }
public FormCommentsSearch(CommentLogic logic) { InitializeComponent(); this.logic = logic; }
public void Initialize() { _mockCommentRepo = new MockCommentRepository(); _commentLogic = new CommentLogic(_mockCommentRepo); }
public CommentController() { commentLogic = LogicFactory.CreateCommentLogic(); }