[TestFixture]
|
public class InterfaceSample
|
{
|
[Test]
|
public async Task Test()
|
{
|
var subject = DriverTestConfiguration.Client.GetDatabase("test").GetCollection<MyEntity>("test");
|
await subject.DeleteManyAsync("{}");
|
await subject.InsertOneAsync(new MyEntity { Id = 3, Type = "awesome" });
|
|
var entity = await Find(subject, 3);
|
}
|
|
private Task<T> Find<T>(IMongoCollection<T> collection, int id) where T : IEntity
|
{
|
return collection.Find(x => x.Id == id).FirstOrDefaultAsync();
|
}
|
}
|
|
public interface IEntity
|
{
|
int Id { get; set; }
|
}
|
|
public class MyEntity : IEntity
|
{
|
public int Id { get; set; }
|
|
public string Type { get; set; }
|
}
|