public async Task DbContextMock_CreateDbQueryMock_PassEntities_DbQueryShouldContainEntities() { var dbContextMock = new DbContextMock <TestDbContext>(Options); dbContextMock.CreateDbQueryMock(x => x.QueryModels, new[] { new QueryModel { ArticleCount = 2, AuthorName = "Author 1" }, new QueryModel { ArticleCount = 5, AuthorName = "Author 2" }, }); Assert.That(dbContextMock.Object.QueryModels.Count(), Is.EqualTo(2)); Assert.That(await dbContextMock.Object.QueryModels.CountAsync(), Is.EqualTo(2)); var result = await dbContextMock.Object.QueryModels.FirstAsync(x => x.AuthorName.Equals("Author 1")); Assert.That(result.ArticleCount, Is.EqualTo(2)); result = await dbContextMock.Object.Query <QueryModel>().FirstAsync(x => x.AuthorName.Equals("Author 2")); Assert.That(result.ArticleCount, Is.EqualTo(5)); }
public void DbContextMock_CreateDbQueryMock_ShouldSetupMockForDbQuerySelector() { var dbContextMock = new DbContextMock <TestDbContext>(Options); var dbQueryMock = dbContextMock.CreateDbQueryMock(x => x.QueryModels); var dbQuery = dbContextMock.Object.Query <QueryModel>(); Assert.That(dbQuery, Is.Not.Null); Assert.That(dbQuery, Is.EqualTo(dbQueryMock.Object)); }