public void AddPost(Post post) { string connectionString = "mongodb://localhost:27017,localhost:27018,localhost:27019"; MongoServer server = MongoServer.Create(connectionString); var database = server.GetDatabase(DBSettings.DatabaseName); var collection = database.GetCollection<Post>("post"); //drop collection //collection.Drop(); collection.Save(post); }
public void AddPostTest() { PostRepository target = new PostRepository(); Random rand = new Random(); string title = String.Format("Title{0}",rand.Next(1,10000)); var post = new Post() { Title = title, Body = "This isn't a very long post.", CharCount = 27, Comments = new List<Comment> { { new Comment() { TimePosted = new DateTime(2010,1,1), Email = "*****@*****.**", Body = "This article is too short!" } }, { new Comment() { TimePosted = new DateTime(2010,1,2), Email = "*****@*****.**", Body = "I agree with Bob." } } } }; target.AddPost(post); Post postFromDb = target.GetPost(title); Assert.IsTrue(post.Id == postFromDb.Id); }