public void UpdateTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());
            var author            = new UserDetailModel();
            var dbAuthor          = userRepository.Insert(author);

            var commentOld = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Mamka mi zjedla rezen.",
            };

            var commentNew = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Content   = "Ocko mi zjedol rezen nakoniec.",
                Author    = dbAuthor
            };

            var commentDetail = commentRepository.Insert(commentNew);

            commentRepository.Update(commentNew);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(commentNew.Timestamp, commentDatabase.Timestamp);
            Assert.Equal(commentNew.Content, commentDatabase.Content);

            commentRepository.Remove(commentDatabase.Id);
        }
Example #2
0
        public void DetailModelToEntity_ShouldBeEqual()
        {
            var user = new UserDetailModel
            {
                FirstName = "John",
                LastName  = "Doe"
            };

            var model = new CommentDetailModel
            {
                Author = user,
                Id     = Guid.NewGuid(),
                Text   = "This is a comment!"
            };

            var returned = CommentMapper.DetailModelToEntity(model);

            Assert.Equal(model.Author.FirstName, returned.Author.FirstName);
            Assert.Equal(model.Author.LastName, returned.Author.LastName);
            Assert.Equal(model.Id, returned.Id);
            Assert.Equal(model.Text, returned.Text);
            Assert.Equal(model.Image, returned.Picture);
            Assert.Equal(model.Timestamp, returned.Timestamp);

            Assert.IsType <Comment>(returned);
        }
Example #3
0
 private void SearchInComment(CommentDetailModel comment, HashSet <PostDetailModel> postWithSearchedText, PostDetailModel post)
 {
     if (comment.Content.Contains(SearchText))
     {
         postWithSearchedText.Add(post);
     }
 }
        public void GetByIdTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());

            var author = new UserDetailModel();

            var dbAuthor = userRepository.Insert(author);

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Dneska som mala na obed kuraci steak",
            };

            var commentDetail = commentRepository.Insert(comment);

            var commentDatabase = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentDatabase);
            Assert.Equal(comment.Timestamp, commentDatabase.Timestamp);
            Assert.NotNull(commentDatabase.Author);
            Assert.Equal(comment.Content, commentDatabase.Content);
            commentRepository.Remove(commentDatabase.Id);
        }
Example #5
0
        public CommentDetailModel Add(CommentDetailModel detail)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var comment = CommentMapper.MapCommentDetailModelToEntity(detail);
                comment.Id = Guid.NewGuid();


                Guid idUser = detail.UserId;
                Console.WriteLine("NEW ID:");
                Console.WriteLine(idUser);
                Guid idTopic = detail.TopicId;
                Console.WriteLine("NEW TOPIC ID:");
                Console.WriteLine(idTopic);
                if (idUser != Guid.Empty)
                {
                    comment.User = teamCommunicationDbContext.Users.First(c => c.Id == idUser);
                }
                if (idTopic != Guid.Empty)
                {
                    comment.Topic = teamCommunicationDbContext.Topics.First(c => c.Id == idTopic);
                }
                teamCommunicationDbContext.Comments.Add(comment);
                teamCommunicationDbContext.SaveChanges();

                return(CommentMapper.MapCommentEntityToDetailModel(comment));
            }
        }
Example #6
0
        public async Task <IActionResult> PutComment(Guid id, CommentDetailModel comment)
        {
            if (id != comment.Id)
            {
                return(BadRequest());
            }

            try
            {
                facade.Save(comment);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CommentExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #7
0
        public void UpdateCommentContent_Test()
        {
            //Arrange
            var postDetailModel = new PostDetailModel()
            {
                Title = "NewTitle",
            };
            var commentModelOld = new CommentDetailModel()
            {
                CreationTime = new DateTime(),
                Content      = "OldContent"
            };
            var userDetailModel = new UserDetailModel()
            {
                Name     = "NewUser",
                Email    = "*****@*****.**",
                Password = "******"
            };

            //Act
            var returnedUserModel          = _userRepository.Create(userDetailModel);
            var returnedPostDetailModel    = _postRepository.Create(postDetailModel, returnedUserModel);
            var returnedCommentDetailModel = _commentRepository.Create(commentModelOld, returnedUserModel, returnedPostDetailModel);

            returnedPostDetailModel = _postRepository.AddComment(returnedPostDetailModel, returnedCommentDetailModel);
            var returnedUpdatedComment = _commentRepository.UpdateContent(returnedCommentDetailModel, "NewContent");

            //Assert
            Assert.Equal("NewContent", returnedUpdatedComment.Content);

            //Teardown
            _commentRepository.Delete(returnedCommentDetailModel);
            _postRepository.Delete(returnedPostDetailModel);
            _userRepository.Delete(returnedUserModel);
        }
Example #8
0
        public void GetById_ShouldBeEqual()
        {
            var user = new UserDetailModel
            {
                FirstName = "Alfred",
                Id        = Guid.NewGuid(),
                LastName  = "Hitchcock"
            };

            var team = new TeamDetailModel
            {
                Id   = Guid.NewGuid(),
                Name = "Musicians"
            };

            var comment = new CommentDetailModel
            {
                Author    = user,
                Id        = Guid.NewGuid(),
                Timestamp = new DateTime(2019, 10, 22)
            };

            var createdModel = fixture.Repository.Create(new UserLogModel
            {
                Id     = Guid.NewGuid(),
                Action = Operation.CommentCreate,
            });

            Assert.Equal(createdModel.Id, fixture.Repository.GetById(createdModel.Id).Id);

            fixture.Repository.Delete(createdModel.Id);
        }
Example #9
0
        public void Create_WithNonExistingItem_DoesNotThrow()
        {
            var model = new CommentDetailModel
            {
                text = "Testovací komentář",
                date = new DateTime(2019, 4, 6, 20, 02, 37)
            };

            var returnedModel = fixture.Repository.Add(model);

            Assert.NotNull(returnedModel);

            var model1 = new CommentDetailModel
            {
                text = "Testovací komentář1",
                date = new DateTime(2019, 4, 6, 20, 02, 37)
            };

            var returnedModel1 = fixture.Repository.Add(model1);

            returnedModel1 = fixture.Repository.Add(model1);

            fixture.Repository.Update(returnedModel);
            Assert.NotNull(returnedModel);

            var returnedModel1After = fixture.Repository.GetById(returnedModel1.Id);

            Assert.Equal(returnedModel1.text, returnedModel1After.text);

            fixture.Repository.Remove(returnedModel.Id);
            fixture.Repository.Remove(returnedModel1.Id);
        }
Example #10
0
        private void CommentDetailStaff_Load(object sender, EventArgs e)
        {
            CommentDetailModel cmtdm    = new CommentDetailModel();
            ArrayList          cmtdList = cmtdm.GetAllDataToArrayList();

            commentDetailBindingSource.DataSource = cmtdList;
            gcCmtDetail.DataSource = commentDetailBindingSource;
        }
Example #11
0
 public void Delete(CommentDetailModel detailModel)
 {
     using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
     {
         RemoveCommentFromUserActivity(detailModel.Id, dbContext);
         dbContext.Remove(dbContext.Find(typeof(Comment), detailModel.Id));
         dbContext.SaveChanges();
     }
 }
Example #12
0
 public static Comment MapCommentDetailModelToEntity(CommentDetailModel model)
 {
     return(new Comment
     {
         Id = model.Id,
         date = model.date,
         text = model.text,
     });
 }
 public void Update(CommentDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = CommentMapper.DetailModelToEntity(model);
         dbContext.Comments.Update(entity);
         dbContext.SaveChanges();
     }
 }
 public CommentDetailModel Create(CommentDetailModel model)
 {
     using (var dbContext = dbContextFactory.CreateDbContext())
     {
         var entity = CommentMapper.DetailModelToEntity(model);
         dbContext.Comments.Add(entity);
         dbContext.SaveChanges();
         return(CommentMapper.EntityToDetailModel(entity));
     }
 }
Example #15
0
 public Comment MapCommentToEntity(CommentDetailModel comment)
 {
     return(new Comment
     {
         Id = comment.Id,
         Text = comment.Text,
         CommentAdditionTime = comment.CommentAdditionTime,
         User = MapUserToEntity(comment.User),
         Post = MapPostToEntity(comment.Post)
     });
 }
Example #16
0
 public static Comment MapToEntity(CommentDetailModel commentDetailModel)
 {
     return(new Comment
     {
         Id = commentDetailModel.Id,
         Author = UserMapper.MapListModelToEntity(commentDetailModel.Author),
         BelongsTo = PostMapper.MapListModelToEntity(commentDetailModel.BelongsTo),
         CreationTime = commentDetailModel.CreationTime,
         Content = commentDetailModel.Content
     });
 }
Example #17
0
        public void Update(CommentDetailModel detail)
        {
            using (var teamCommunicationDbContext = dbContextFactory.CreateDbContext())
            {
                var comment = teamCommunicationDbContext.Comments.First(c => c.Id == detail.Id);

                comment.text = detail.text;
                comment.date = detail.date;

                teamCommunicationDbContext.SaveChanges();
            }
        }
Example #18
0
 public CommentDetailModel Save(CommentDetailModel model)
 {
     if (model.Id == Guid.Empty)
     {
         return(repository.Add(model));
     }
     else
     {
         repository.Update(model);
         return(model);
     }
 }
Example #19
0
        public CommentDetailModel Create(CommentDetailModel comment)
        {
            using (var dbContext = _dbContextFactory.CreateDbContext())
            {
                var entity = _mapper.MapCommentToEntity(comment);
                dbContext.Entry(entity).State = EntityState.Unchanged;
                dbContext.Comments.Add(entity);
                dbContext.SaveChanges();

                return(_mapper.MapCommentDetailModelFromEntity(entity));
            }
        }
Example #20
0
        public void AddComment_PostModel_Test()
        {
            var userModel = _userRepository.Create(new UserDetailModel
            {
                Name     = "Dan",
                Email    = "*****@*****.**",
                Password = "******",
            });

            var postModel = _postRepository.Create(new PostDetailModel
            {
                Title = "Funguje to",
            }, userModel);


            for (int i = 0; i < 5; i++)
            {
                var commModel = new CommentDetailModel
                {
                    Content = i.ToString() + " Komentar k Funguje to",
                };

                commModel = _commentRepository.Create(commModel, userModel, postModel);
                postModel = _postRepository.AddComment(postModel, commModel);
            }

            var commOneModel = new CommentDetailModel
            {
                Content = " Komentar k Funguje to",
            };

            commOneModel = _commentRepository.Create(commOneModel, userModel, postModel);
            postModel    = _postRepository.AddComment(postModel, commOneModel);


            Assert.NotNull(postModel);
            Assert.NotEmpty(postModel.Comments);
            Assert.Equal(6, postModel.Comments.Count);

            postModel = _postRepository.RemoveComment(postModel, commOneModel);

            Assert.Equal(5, postModel.Comments.Count);

            //TearDown

            foreach (var comment in postModel.Comments)
            {
                postModel = _postRepository.RemoveComment(postModel, comment);
            }

            _postRepository.Delete(postModel.Id);
            _userRepository.Delete(userModel.Id);
        }
Example #21
0
 private void btnRestore_ItemClick(object sender, ItemClickEventArgs e)
 {
     if (cmtdIDSelected != "")
     {
         CommentDetailModel cmtd = new CommentDetailModel();
         cmtd.RestoreCommentDetail(Convert.ToInt32(cmtdIDSelected));
         XtraMessageBox.Show("Restore successful !!!", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
         CommentDetailStaff_Load(sender, e);
     }
     else
     {
         XtraMessageBox.Show("Please choose a food item to 'restore' !!!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
     }
 }
Example #22
0
        private Task AddCommentAsync(Guid postId)
        {
            return(Task.Run(() =>
            {
                var post = _postRepository.GetById(postId);

                var comment = new CommentDetailModel();
                comment.Content = Content;

                var returnedComment = _commentRepository.Create(comment, CurrentUser, post);

                _postRepository.AddComment(post, returnedComment);
            }));
        }
        public CommentEntity MapToCommentEntity(CommentDetailModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new CommentEntity()
            {
                Id = model.Id,
                Timestamp = model.Timestamp,
                Content = model.Content,
                Author = _mappers.UserMapper.MapToUserEntity(model.Author),
            });
        }
Example #24
0
        public PostDetailModel AddComment(PostDetailModel postModel, CommentDetailModel commentModel)
        {
            using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
            {
                var postEntity = dbContext.Posts
                                 .Include(c => c.Comments)
                                 .ThenInclude(a => a.Author)
                                 .Include(u => u.Author)
                                 .First(p => p.Id == postModel.Id);

                dbContext.Posts.Update(postEntity);
                dbContext.SaveChanges();

                return(PostMapper.MapToDetailModel(postEntity));
            }
        }
Example #25
0
        public CommentDetailModel UpdateContent(CommentDetailModel commentModel, string content)
        {
            using (var dbContext = _dbContextFactory.CreateTeamChatDbContext())
            {
                var commentEntity = dbContext.Comments
                                    .Include(a => a.Author)
                                    .Include(p => p.BelongsTo)
                                    .ThenInclude(a => a.Author)
                                    .First(c => c.Id == commentModel.Id);

                commentEntity.Content = content;
                dbContext.Comments.Update(commentEntity);
                dbContext.SaveChanges();
                return(CommentMapper.MapToDetailModel(commentEntity));
            }
        }
        public static Comment DetailModelToEntity(CommentDetailModel model)
        {
            if (model == null)
            {
                return(null);
            }

            return(new Comment
            {
                Id = model.Id,
                Timestamp = model.Timestamp,
                Text = model.Text,
                Picture = model.Image,
                Thread = ThreadMapper.DetailModelToEntity(model.Thread),
                Author = UserMapper.DetailModelToEntity(model.Author)
            });
        }
Example #27
0
        public async Task <ActionResult <Comment> > PostComment(CommentDetailModel detail)
        {
            DateTime date = DateTime.Now;

            CommentDetailModel comment = facade.CreateNew();

            comment.text    = detail.text;
            comment.TopicId = detail.TopicId;
            comment.UserId  = detail.UserId;
            comment.date    = date;
            if (facade.Save(comment) == null)
            {
                return(NotFound());
            }

            return(Ok());
        }
        public void InsertTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());

            var comment = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = new UserDetailModel(),
                Content   = "Pockaj, kym mi doperie pracka",
            };

            var commentDetail = commentRepository.Insert(comment);
            var commentId     = commentRepository.GetById(commentDetail.Id);

            Assert.NotNull(commentId);
            commentRepository.Remove(commentId.Id);
        }
Example #29
0
        public void Update_ShouldNotEqual()
        {
            var user = new UserDetailModel
            {
                FirstName = "Alfred",
                Id        = Guid.NewGuid(),
                LastName  = "Hitchcock"
            };

            var team = new TeamDetailModel
            {
                Id   = Guid.NewGuid(),
                Name = "Musicians"
            };

            var comment = new CommentDetailModel
            {
                Author    = user,
                Id        = Guid.NewGuid(),
                Timestamp = new DateTime(2019, 10, 22)
            };

            var model = new UserLogModel
            {
                Id        = Guid.NewGuid(),
                Action    = Operation.CommentCreate,
                Comment   = comment,
                Team      = team,
                Timestamp = new DateTime(2019, 4, 15),
                User      = user
            };

            var oldTimestamp = model.Timestamp;

            var createdModel = fixture.Repository.Create(model);

            model.Timestamp = new DateTime(1998, 3, 19);

            fixture.Repository.Update(model);

            var newTimestamp = fixture.Repository.GetById(model.Id).Timestamp;

            Assert.NotEqual(oldTimestamp, newTimestamp);

            fixture.Repository.Delete(createdModel.Id);
        }
        public void GetUserLastCommentTest()
        {
            var commentRepository = new CommentRepository(new InMemoryDbContextFactory());
            var userRepository    = new UserRepository(new InMemoryDbContextFactory());
            var author            = new UserDetailModel();

            var dbAuthor = userRepository.Insert(author);

            var commentFirst = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Ta podlaha v kuchyni je spinava.",
            };

            var commentSecond = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Mam chut ju umyt.",
            };

            var commentLast = new CommentDetailModel()
            {
                Timestamp = DateTime.Now,
                Author    = dbAuthor,
                Content   = "Ok, idem ju fakt umyt.",
            };

            var commentFirstDb  = commentRepository.Insert(commentFirst);
            var commentSecondDb = commentRepository.Insert(commentSecond);
            var commentDetail   = commentRepository.Insert(commentLast);

            var commentsDatabase = commentRepository.GetUserLastComments(dbAuthor.Id, 2);

            Assert.Equal(2, commentsDatabase.Count());
            Assert.Equal(commentSecond.Timestamp, commentsDatabase.Last().Timestamp);
            Assert.Equal(commentSecond.Content, commentsDatabase.Last().Content);
            Assert.Equal(commentLast.Timestamp, commentsDatabase.First().Timestamp);
            Assert.Equal(commentLast.Content, commentsDatabase.First().Content);

            commentRepository.Remove(commentFirstDb.Id);
            commentRepository.Remove(commentSecondDb.Id);
            commentRepository.Remove(commentDetail.Id);
        }