public void RandomActEnsurePropertiesWork()
        {
            // Arrange
            RandomActsModel RandomAct = new RandomActsModel();
            List<Comment> list_comment = new List<Comment>();
            Comment this_comment = new Comment { UserComment = "hey" };
            list_comment.Add(this_comment);
            ApplicationUser this_user = new ApplicationUser();
            DateTime this_datetime = new DateTime(2015, 1, 16);

            // Act
            RandomAct.RandomActTitle = "Bought Coffee";
            RandomAct.RandomActDescription = "Bought Coffee for a girl who was having a bad day";
            RandomAct.PointsEarned = 3;
            RandomAct.Date = this_datetime;
            RandomAct.PicURL = "https://www.google.com/";
            RandomAct.Owner = this_user;
            RandomAct.Comments = list_comment;

            // Assert
            Assert.AreEqual("Bought Coffee", RandomAct.RandomActTitle);
            Assert.AreEqual(3, RandomAct.PointsEarned);
            Assert.AreEqual("Bought Coffee for a girl who was having a bad day", RandomAct.RandomActDescription);
            Assert.AreEqual(1, RandomAct.Comments.Count);
            Assert.AreEqual(this_datetime, RandomAct.Date);
            Assert.AreEqual("https://www.google.com/", RandomAct.PicURL);
            Assert.AreEqual(this_user, RandomAct.Owner);
        }
        public void CommentEnsurePropertiesWork()
        {
            Comment Comment = new Comment { UserComment = "I'm so glad you gave that girl five dollars" };

            ApplicationUser this_user = new ApplicationUser();
            Comment.User = this_user;

            Assert.AreEqual("I'm so glad you gave that girl five dollars", Comment.UserComment);
            Assert.AreEqual(Comment.User, this_user);
        }
 public void CommentEnsureICanCreateAnInstance()
 {
     Comment Comment = new Comment();
     Assert.IsNotNull(Comment);
 }
Esempio n. 4
0
        public void Post(int id, [FromBody]Comment NewComment)
        {
            var userID = User.Identity.GetUserId();
            ApplicationUser owner = nirvana_repo.Users.FirstOrDefault(u => u.Id == userID);

            Comment new_comment = new Comment { UserComment = NewComment.UserComment, ActId = id, Date = DateTime.Now, User = owner };

            try
            {
                nirvana_repo.CreateComment(new_comment, id);
            }
            catch
            {
                throw new ArgumentException();
            }
        }
        public bool CreateComment(Comment comm_2_add, int ActId)
        {
            var query = from r in context.Acts where r.RandomActId == ActId select r;
            RandomActsModel found_act = null;
            bool result = true;

            try
            {
                found_act = query.Single();
                found_act.Comments.Add(comm_2_add);
                context.SaveChanges();
            }
            catch (InvalidOperationException)
            {
                result = false;
            }
            catch (ArgumentNullException)
            {
                result = false;
            }

            return result;
        }