예제 #1
0
 public Question Save(Question question)
 {
     var questionsList = mongoDatabase.GetCollection("Questions");
     WriteConcernResult result;
     bool hasError = false;
     if (string.IsNullOrEmpty(question._Id))
     {
         question._Id = ObjectId.GenerateNewId().ToString();
         result = questionsList.Insert<Question>(question);
         hasError = result.HasLastErrorMessage;
     }
     else
     {
         IMongoQuery query = Query.EQ("_id", question._Id);
         IMongoUpdate update = Update
             .Set("Body", question.Body)
             .Set("Votes", question.Votes);
         result = questionsList.Update(query, update);
         hasError = result.HasLastErrorMessage;
     }
     if (!hasError)
     {
         return question;
     }
     else
     {
         throw new Exception("");
     }
 }
        public void SaveTest()
        {
            var question = new Question
            {
                Body = "Jahirul Islam"
            };

            var data = repository.Save(question);

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