Skip to content

Instantly share code, notes, and snippets.

@mesutpiskin
Last active October 21, 2019 08:29
Show Gist options
  • Save mesutpiskin/7b101eb453f3600c4aabae9cce5f4a7c to your computer and use it in GitHub Desktop.
Save mesutpiskin/7b101eb453f3600c4aabae9cce5f4a7c to your computer and use it in GitHub Desktop.
fake/dummy implementation of mongodb IAsyncCursor used for testing
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MongoDB.Driver;
namespace MyProject.Test
{
public class DummyAsyncCursor<TEntity> : IAsyncCursor<TEntity>
{
private readonly IEnumerable<TEntity> _items;
private readonly IEnumerator<TEntity> _enumerator;
public DummyAsyncCursor(IEnumerable<TEntity> items)
{
_items = items ?? Enumerable.Empty<TEntity>();
_enumerator = items.GetEnumerator();
}
public IEnumerable<TEntity> Current
{
get { return _items; }
}
public Task<bool> MoveNextAsync(CancellationToken cancellationToken)
{
return Task.FromResult(_enumerator.MoveNext());
}
public void Dispose() { }
public bool MoveNext(CancellationToken cancellationToken = default)
{
return _enumerator.MoveNext();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment