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()); } }
public void ShouldBeFindTorrentsWithNullDescription() { var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Description == null); Assert.Equal("{Description : null}", where); }
public void ShouldBeFindTorrentsThatDoesNotEqual() { var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId != "sometest"); Assert.Equal("{TorrentId : {$ne : 'sometest'}}", where); }
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); }
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); }
public void ShouldBeFindTorrentsThatContains() { var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.Description.Contains("Avengers")); Assert.Equal("{Description : /Avengers/gi}", where); }
public void ShouldBeFindTorrentsThatEndsWith() { var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId.EndsWith("1384/")); Assert.Equal("{TorrentId : /1384\\/$/gi}", where); }
public void ShouldBeFindTorrentsThatStartWith() { var where = MongoWhereBuilder.ToMongoSql <Torrent>(t => t.TorrentId.StartsWith("http://thepiratebay")); Assert.Equal("{TorrentId : /^http:\\/\\/thepiratebay/gi}", where); }
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); }
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); }