示例#1
0
        public void CanCreateNewBlogPost()
        {
            // Act.
            BlogPost post = BlogPost.Create(new BlogPost
            {
                DatePublished = DateTime.Now,
                Title         = "My Blog Post",
                Text          = "Some text"
            });

            // Assert.
            Assert.That(post.ID, Is.Not.EqualTo(ObjectId.Empty));
        }
示例#2
0
        public void CanDropAllCollections()
        {
            // Arrange.
            BlogPost.Create(new BlogPost
            {
                DatePublished = DateTime.Now,
                Title         = "Blog post title",
                Text          = "My blog post"
            });
            Assert.That(OrmongoConfiguration.GetMongoDatabase().CollectionExists("BlogPost"), Is.True);

            // Act.
            OrmongoConfiguration.DropAllCollections();

            // Assert.
            Assert.That(OrmongoConfiguration.GetMongoDatabase().CollectionExists("BlogPost"), Is.False);
        }
示例#3
0
        public void CanCloseConnection()
        {
            // Arrange.
            BlogPost.Create(new BlogPost
            {
                DatePublished = DateTime.Now,
                Title         = "Blog post title",
                Text          = "My blog post"
            });
            Assert.That(OrmongoConfiguration.GetMongoServer().State, Is.EqualTo(MongoServerState.Connected));

            // Act.
            OrmongoConfiguration.CloseConnection();

            // Assert.
            Assert.That(OrmongoConfiguration.GetMongoServer().State, Is.EqualTo(MongoServerState.Disconnected));
        }
示例#4
0
        public void DefaultScope()
        {
            // Arrange.
            var defaultScope = BlogPost.DefaultScope;

            BlogPost.DefaultScope = items => items.OrderBy(d => d.Title);
            BlogPost post1 = BlogPost.Create(new BlogPost
            {
                Title = "Z",
            });
            BlogPost post2 = BlogPost.Create(new BlogPost
            {
                Title = "A",
            });

            // Act.
            BlogPost retrievedPost = BlogPost.All().First();

            // Assert.
            Assert.That(retrievedPost.ID, Is.EqualTo(post2.ID));

            // Clean up.
            BlogPost.DefaultScope = defaultScope;
        }