Ejemplo n.º 1
0
 public Comment Save(Comment comment)
 {
     var commentsList = mongoDatabase.GetCollection("Comments");
     WriteConcernResult result;
     bool hasError = false;
     if (string.IsNullOrEmpty(comment._Id))
     {
         comment._Id = ObjectId.GenerateNewId().ToString();
         result = commentsList.Insert<Comment>(comment);
         hasError = result.HasLastErrorMessage;
     }
     else
     {
         IMongoQuery query = Query.EQ("_id", comment._Id);
         IMongoUpdate update = Update
             .Set("Body", comment.Body);
         result = commentsList.Update(query, update);
         hasError = result.HasLastErrorMessage;
     }
     if (!hasError)
     {
         return comment;
     }
     else
     {
         throw new Exception("");
     }
 }
Ejemplo n.º 2
0
        public void SaveTest()
        {
            var comment = new Comment
            {
                Body = "Jahirul Islam"
            };

            var data = repository.Save(comment);

            //Xunit.Assert.NotNull(data);
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.IsNotNull(data);
        }