public async Task <IEnumerable <Torrent> > GetTorrents(Expression <Func <Torrent, bool> > filter)
        {
            if (filter != null)
            {
                var whereString = MongoWhereBuilder.ToMongoSql(filter);

                return(await collection.Find(whereString).ToListAsync());
            }
            else
            {
                return(await collection.Find(new BsonDocument()).ToListAsync());
            }
        }
Exemple #2
0
 public void ShouldBeFindTorrentsWithNullDescription()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Description == null);
     Assert.Equal("{Description : null}", where);
 }
Exemple #3
0
 public void ShouldBeFindTorrentsThatDoesNotEqual()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId != "sometest");
     Assert.Equal("{TorrentId : {$ne : 'sometest'}}", where);
 }
Exemple #4
0
 public void ShouldBeFindTorrentsByDescriptionAndOrTitles()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Description.Contains("1080p") & (t.Title.Contains("Avengers") || t.Title.Contains("Jurassic")));
     Assert.Equal("{$and:[{Description : /1080p/gi}, {$or:[{Title : /Avengers/gi}, {Title : /Jurassic/gi}]}]}", where);
 }
Exemple #5
0
 public void ShouldBeFindTorrentsByTitleAndDescription()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Title.Contains("Avengers") && t.Description.Contains("Avengers"));
     Assert.Equal("{$and:[{Title : /Avengers/gi}, {Description : /Avengers/gi}]}", where);
 }
Exemple #6
0
 public void ShouldBeFindTorrentsThatContains()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Description.Contains("Avengers"));
     Assert.Equal("{Description : /Avengers/gi}", where);
 }
Exemple #7
0
 public void ShouldBeFindTorrentsThatEndsWith()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId.EndsWith("1384/"));
     Assert.Equal("{TorrentId : /1384\\/$/gi}", where);
 }
Exemple #8
0
 public void ShouldBeFindTorrentsThatStartWith()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId.StartsWith("http://thepiratebay"));
     Assert.Equal("{TorrentId : /^http:\\/\\/thepiratebay/gi}", where);
 }
Exemple #9
0
 public void ShouldBeFindByTorrentIdExactValue()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId == "http://thepiratebay.org/torrent/24281384/");
     Assert.Equal("{TorrentId : 'http:\\/\\/thepiratebay.org\\/torrent\\/24281384\\/'}", where);
 }
Exemple #10
0
 public void ShouldBeFindAll()
 {
     var where = MongoWhereBuilder.ToMongoSql <Torrent>(null);
     Assert.Equal("{}", where);
 }
        public async Task <long> DeleteTorrents(Expression <Func <Torrent, bool> > filter)
        {
            var result = await collection.DeleteManyAsync(MongoWhereBuilder.ToMongoSql(filter));

            return(result.DeletedCount);
        }