public bool TotallyEquals(IndexSet other) { if (Object.ReferenceEquals(other, null)) { return(false); } if (Object.ReferenceEquals(this, other)) { return(true); } return(Equals(other) && IndexIsUnique.Equals(other.IndexIsUnique) && IndexType.Equals(other.IndexType) && Columns.Equals(other.Columns) && IncludedColumns.Equals(other.IncludedColumns) && HasFilter.Equals(other.HasFilter) && FilterDefinition.Equals(other.FilterDefinition) && KeyConstraintTypeCode.Equals(other.KeyConstraintTypeCode)); }
public Task <IAsyncEnumerable <T> > FindAll( FilterDefinition <T> filter = null, SortDefinition <T> sort = null ) { // HACK: We silently ignore the sort here if ((filter != null && !filter.Equals(Builders <T> .Filter.Empty))) { throw new NotImplementedException(); } T[] result = _dispatcher.Dispatch(s => s .Query(_name) .Select(d => BsonSerializer.Deserialize <T>(d)) .ToArray() ); return(Task.FromResult(result.ToAsyncEnumerable())); }
public void Test_GetBooks_Verify() { //Arrange var mockContext = new Mock <IMongoContext>(); var mockCollection = CreateMockCollection(); Book document = new Book(); document.Author = "asdas"; document.BookName = "sadasd"; document.Id = ObjectId.GenerateNewId().ToString(); mockCollection.Object.InsertOne(document); BookstoreDatabaseSettings setting = new BookstoreDatabaseSettings(); setting.BooksCollectionName = "Book"; var mockIDBsettings = new Mock <IOptions <BookstoreDatabaseSettings> >(); mockContext.Setup(x => x.GetCollection <Book>("Book")).Returns(mockCollection.Object); mockIDBsettings.Setup(x => x.Value).Returns(setting); var filterExpression1 = (Expression <Func <Book, bool> >)(x => x.Id == document.Id); // var expectedEntities = new List<Book>(); // expectedEntities.Add(document); // var mockCursor = new Mock<IAsyncCursor<Book>>(); // mockCursor.Setup(_ => _.Current).Returns(expectedEntities); //<-- Note the entities here // mockCursor // .SetupSequence(_ => _.MoveNext(It.IsAny<CancellationToken>())) // .Returns(true) // .Returns(false); // mockCursor // .SetupSequence(_ => _.MoveNextAsync(It.IsAny<CancellationToken>())) // .Returns(Task.FromResult(true)) // .Returns(Task.FromResult(false)); // mockCollection.Setup(x => x.FindSync<Book>( // filterExpression1, // null, // CancellationToken.None // )) //.Returns(mockCursor.Object); //Act BookService service = new BookService(mockIDBsettings.Object, mockContext.Object); var result = service.Get(document.Id); //ASSERT mockContext.Verify(x => x.GetCollection <Book>("Book"), Times.Once); var bookMock = new Mock <IFindFluent <Book, Book> >(); //mockCollection.Verify(m => m.Find<Book>(FilterDefinition<Book>.Empty, null, CancellationToken.None), Times.Once); var options = new FindOptions <Book>(); var cancellationToken = new CancellationTokenSource().Token; var filterDefinition = Builders <Book> .Filter.Eq("BookName", "sadasd"); var filters = FilterDefinition <Book> .Equals("BookName", "sadasd"); //mockCollection.Verify(m => m.FindSync<Book>(filterDefinition, options, cancellationToken)); var filterExpression = (Expression <Func <Book, bool> >)(x => x.Id == document.Id); Expression <Func <Book, bool> > predicate = x => x.BookName == "sadasd"; // Expression<Func<Person, bool>> predicate = x => x.Name == captured[0]; mockCollection.Verify(m => m.FindSync <Book>(predicate, null, CancellationToken.None), Times.Once); }