Esempio n. 1
0
        public void Update(FlyComment comment)
        {
            if (comment.Id > 0)
            {
                var commentToUpdate = GetById(comment.Id);

                if (commentToUpdate != null)
                {
                    _context.Entry(commentToUpdate).CurrentValues.SetValues(comment);
                }
            }

            _context.SaveChanges();
        }
Esempio n. 2
0
        private void ValidateInsert(FlyComment comment)
        {
            if (comment == null)
                throw new ArgumentException("FlyComment is required!");

            if (comment.Author == null)
                throw new ArgumentException("Author is required!");

            if (comment.Fly == null)
                throw new ArgumentException("Fly is required!");

            if (string.IsNullOrWhiteSpace(comment.Comment))
                throw new ArgumentException("Comment is required!");
        }
Esempio n. 3
0
        public void CanInsertComment()
        {
            var commentRepository = new Mock<IFlyCommentRepository>();

            commentRepository.Setup(s => s.GetAll())
                             .Returns(new List<FlyComment>
                                 {
                                     new FlyComment {Id = 1, Author = new FlyOwner {Id = 1}, Fly = new Fly {Id = 1}, Comment = "Comment" },
                                     new FlyComment {Id = 2, Author = new FlyOwner {Id = 2}, Fly = new Fly {Id = 1}, Comment = "Comment 2" }
                                 }.AsQueryable());

            var commentService = new FlyCommentService(commentRepository.Object);

            var comment = new FlyComment { Author = new FlyOwner { Id = 1 }, Fly = new Fly { Id = 1 }, Comment = "Comment 3" };

            commentService.Insert(comment);

            commentRepository.Verify(v => v.Insert(It.IsAny<FlyComment>()), Times.Once());
        }
Esempio n. 4
0
        public void CanNotInsertWithotComment()
        {
            var commentRepository = new Mock<IFlyCommentRepository>();

            commentRepository.Setup(s => s.GetAll())
                             .Returns(new List<FlyComment>
                                 {
                                     new FlyComment {Id = 1, Author = new FlyOwner {Id = 1}, Fly = new Fly {Id = 1}, Comment = "Comment" },
                                     new FlyComment {Id = 2, Author = new FlyOwner {Id = 2}, Fly = new Fly {Id = 1}, Comment = "Comment 2" }
                                 }.AsQueryable());

            var commentService = new FlyCommentService(commentRepository.Object);

            try
            {
                var comment = new FlyComment { Author = new FlyOwner { Id = 1 }, Fly = new Fly { Id = 1 } };
                commentService.Insert(comment);
                Assert.Fail("Validation not implemented!");
            }
            catch (ArgumentException argx)
            {
                Assert.AreEqual("Comment is required!", argx.Message);
                commentRepository.Verify(v => v.Insert(It.IsAny<FlyComment>()), Times.Never());
            }
            catch (Exception)
            {
                Assert.Fail("Validation not implemented!");
            }
        }
Esempio n. 5
0
 public void Insert(FlyComment comment)
 {
     _context.FlyComments.Add(comment);
     _context.SaveChanges();
 }
Esempio n. 6
0
 public void Insert(FlyComment comment)
 {
     ValidateInsert(comment);
     _commentRepository.Insert(comment);
 }