public void MongoRepository_Supports_Basic_Crud_Operations()
        {
            const string connectionString = "mongodb://127.0.0.1";

            if (!MongoDbRepositoryManager.ServerIsRunning(connectionString))
            {
                AssertIgnores.MongoServerIsNotRunning();
            }

            var repo = new MongoDbRepository<Order, string>(connectionString);

            // Create
            var create = new Order { Name = "Big sale" };
            repo.Add(create);

            // Read
            var read = repo.Get(create.OrderId);
            read.Name.ShouldEqual(create.Name);

            // Update
            read.Name = "Really big sale";
            repo.Update(read);

            var all = repo.GetAll();

            var update = repo.Get(read.OrderId);
            update.OrderId.ShouldEqual(read.OrderId);
            update.Name.ShouldEqual(read.Name);

            // Delete
            repo.Delete(update);
            var delete = repo.Get(read.OrderId);
            delete.ShouldBeNull();
        }
        public void MongoDb_Supports_Basic_Crud_Operations()
        {
            const string connectionString = "mongodb://localhost";

            if (!MongoDbRepositoryManager.ServerIsRunning(connectionString))
            {
                AssertIgnores.MongoServerIsNotRunning();
            }

            var server = new MongoClient(connectionString).GetServer();
            var databaseNames = server.GetDatabaseNames();
            foreach (var db in databaseNames)
            {
                server.DropDatabase(db);
            }

            var database = server.GetDatabase("Order");
            var orders = database.GetCollection<Order>("Order");

            Console.WriteLine("* CREATE *");

            var create = new Order { Name = "Big sale" };
            database.GetCollection<Order>("Order").Insert(create);

            foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
            {
                Console.WriteLine(order.Name + ", " + order.OrderId);
            }

            Console.WriteLine("* READ *");

            var read = orders.AsQueryable().FirstOrDefault(e => e.OrderId == create.OrderId);
            read.Name.ShouldEqual(create.Name);

            Console.WriteLine("* UPDATE *");

            read.Name = "Really big sale";
            database.GetCollection<Order>("Order").Save(read);

            foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
            {
                Console.WriteLine(order.Name + ", " + order.OrderId);
            }

            var update = database.GetCollection<Order>("Order").AsQueryable().FirstOrDefault(e => e.OrderId == read.OrderId);
            update.OrderId.ShouldEqual(read.OrderId);
            update.Name.ShouldEqual(read.Name);

            Console.WriteLine("* DELETE *");

            var delete = database.GetCollection<Order>("Order").AsQueryable().FirstOrDefault(e => e.OrderId == update.OrderId);

            database.GetCollection<Order>("Order").Remove(Query.EQ("OrderId", delete.OrderId));

            foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
            {
                Console.WriteLine(order.Name + ", " + order.OrderId);
            }

            database.GetCollection<Order>("Order").RemoveAll();

            Console.WriteLine("* DELETE ALL *");

            foreach (var order in database.GetCollection<Order>("Order").AsQueryable())
            {
                Console.WriteLine(order.Name + ", " + order.OrderId);
            }

            server.DropDatabase("Order");
        }