public void AddComment_ShouldRedirectAfterAdding()
        {
            AddComentBM bm = new AddComentBM()
            {
                Username  = "******",
                PetId     = 1,
                IsLostPet = true,
                Content   = "Test Comment"
            };

            this._controller.WithCallTo(c => c.AddComment(bm)).ShouldRedirectToRoute("");
        }
Beispiel #2
0
        public ActionResult AddComment(AddComentBM bind)
        {
            if (ModelState.IsValid)
            {
                this.service.AddComment(bind);
            }

            if (bind.IsLostPet)
            {
                return(RedirectToAction("Details", "LostPets", new { id = bind.PetId }));
            }

            return(RedirectToAction("Details", "FoundPets", new { id = bind.PetId }));
        }
        public void AddComment_ShouldAddCommentSuccessfully()
        {
            AddComentBM bm = new AddComentBM()
            {
                Username  = "******",
                PetId     = 1,
                IsLostPet = true,
                Content   = "Test Comment"
            };

            this._controller.AddComment(bm);

            Assert.AreEqual(1, this._context.LostPets.Find(1).Comments.Count);
            Assert.AreEqual("Test Comment", this._context.LostPets.Find(1).Comments.First().Content);
        }
Beispiel #4
0
        public void AddComment(AddComentBM bind)
        {
            var author = this.Context.Users.FirstOrDefault(u => u.UserName == bind.Username);

            Comment comment = new Comment
            {
                Author     = author,
                Content    = bind.Content,
                DatePosted = DateTime.Now,
            };

            if (bind.IsLostPet)
            {
                LostPet lostPet = this.Context.LostPets.FirstOrDefault(p => p.Id == bind.PetId);
                lostPet.Comments.Add(comment);
            }
            else
            {
                FoundPet foundPet = this.Context.FoundPets.FirstOrDefault(p => p.Id == bind.PetId);
                foundPet.Comments.Add(comment);
            }

            this.Context.SaveChanges();
        }