public void SetUp() { _fixture = new CustomAutoFixture(); _expectedContextManageCount = _hasCurrentContext ? 0 : 1; _contextService = _fixture.Freeze <IContextService <DbContext_Fake> >(); _dbSetService = _fixture.Freeze <IDbSetService <DbContext_Fake, Foo> >(); _context = new DbContext_Fake(); _contextService.HasCurrentContext().Returns(_hasCurrentContext); _contextService.InitContext().Returns(_context); _contextService.GetCurrentContext().Returns(_context); _dbSet = Substitute.For <DbSet <Foo>, IQueryable <Foo> >(); _dbSetService.GetDbSet(Arg.Any <DbContext_Fake>()) .Returns(_dbSet); _foos = _fixture.CreateMany <Foo>(); var asyncQueryableFoos = _foos.AsQueryable().BuildMock(); _query = _fixture.Create <IQuery <Foo> >(); _query.Query(Arg.Any <IQueryable <Foo> >()) .Returns(asyncQueryableFoos); _sut = _fixture.Create <ContextRepository <DbContext_Fake, Foo> >(); }
public void When_calling_QueryAsync_with_null_repository_Then_ArgumentNullException_is_thrown() { Assert.Multiple(() => { Assert.That(() => RepositoryExtensions.QueryAsync((IRepository <Foo>)null, q => q), Throws.InstanceOf <ArgumentNullException>()); Assert.That(() => RepositoryExtensions.QueryAsync((IRepository <Foo>)null, q => q, _fixture.CreateMany <string>()), Throws.InstanceOf <ArgumentNullException>()); }); }