using MongoDB.Driver;
using MongoDbGenericRepository;
using MongoDbGenericRepository.Models;
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace IntegrationTests.Infrastructure
{
public class TestRepository : BaseMongoRepository, ITestRepository
{
///
public TestRepository(string connectionString, string databaseName) : base(connectionString, databaseName)
{
}
public void DropTestCollection()
{
MongoDbContext.DropCollection();
}
public void DropTestCollection(string partitionKey)
{
MongoDbContext.DropCollection(partitionKey);
}
///
/// Gets the max of a property in a mongodb collections that is satisfying the filter.
///
/// The document type.
/// The type of the primary key.
///
public async Task GetByMaxAsync(Expression> filter, Expression> orderByDescending)
where TDocument : IDocument
where TKey : System.IEquatable
{
return await GetCollection().Find(Builders.Filter.Where(filter))
.SortByDescending(orderByDescending)
.FirstOrDefaultAsync();
}
}
}