Last active
October 21, 2019 08:29
-
-
Save mesutpiskin/7b101eb453f3600c4aabae9cce5f4a7c to your computer and use it in GitHub Desktop.
fake/dummy implementation of mongodb IAsyncCursor used for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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