public void Pop_gets_items_from_the_proper_queue_with_their_data()
        {
            var q1 = new MongoQueue(db, "Q1");
            var q2 = new MongoQueue(db, "Q2");

            q2.Push(new BsonDocument { { "hello", "1" } });
            q1.Push(new BsonDocument { { "goodbye", "2" } });
            q2.Push(new BsonDocument { { "hello", "3" } });

            var item = q1.Pop();
            item.ShouldNotBeNull();
            item["goodbye"].AsString.ShouldEqual("2");
            q1.Pop().ShouldBeNull();
        }
 public void Close_removes_the_item()
 {
     var q = new MongoQueue(db, "Q1");
     q.Push(new BsonDocument());
     var item = q.Pop();
     collection.Count().ShouldEqual(1);
     item.Close();
     collection.Count().ShouldEqual(0);
 }
 public void Recurring_schedules_get_repeated()
 {
     var q = new MongoQueue(db, "Q1");
     q.Push(new BsonDocument(), new Schedule { Repeat = Repeat.Custom, NextRun = DateTime.UtcNow.AddMinutes(-1) });
     q.Pop().Reschedule(DateTime.UtcNow.AddMinutes(30));
     var doc = collection.FindOneAs<BsonDocument>();
     var meta = doc["MongoQueue"].AsBsonDocument;
     meta.Contains("Machine").ShouldEqual(false);
     meta["Schedule"].ToBsonDocument()["NextRun"].AsDateTime.ShouldBeInRange(DateTime.UtcNow.AddMinutes(29), DateTime.UtcNow.AddMinutes(30));
 }
        public void Pop_gets_expired_items()
        {
            var q1 = new MongoQueue(db, "Q1");
            q1.Push(new BsonDocument { { "goodbye", "2" } });
            var item = q1.Pop();
            item.ShouldNotBeNull();
            q1.Pop().ShouldBeNull();

            collection.Update(Query.Exists("MongoQueue.Machine"), Update.Set("MongoQueue.Schedule.NextRun", DateTime.UtcNow.AddMinutes(-31)));
            q1.Pop().ShouldNotBeNull();
        }