예제 #1
0
        public void Verify_QueriesMethods_WorksProperly()
        {
            int setCalls = 0;

            var dbsetMock = new Mock <DbSet <TestEntity> >();

            var dbModelMock = new Mock <EfDbModel>();

            dbModelMock.Setup(x => x.Set <TestEntity>()).Returns(dbsetMock.Object);

            Func <string, EfDbModel> createDbContextBehaviour = (cs) =>
            {
                return(dbModelMock.Object);
            };

            var dbContext = new EfDbContext(createDbContextBehaviour);

            dbContext.CreateDbContext();

            var queryable = dbContext.Query <TestEntity>();

            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));

            dbContext.Add(new TestEntity());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.Add(It.IsAny <TestEntity>()), Times.Once());

            dbContext.AddRange(new List <TestEntity>());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.AddRange(It.IsAny <List <TestEntity> >()), Times.Once());

            dbContext.Remove(new TestEntity());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.Remove(It.IsAny <TestEntity>()), Times.Once());

            dbContext.RemoveRange(new List <TestEntity>());
            setCalls++;

            dbModelMock.Verify(x => x.Set <TestEntity>(), Times.Exactly(setCalls));
            dbsetMock.Verify(x => x.RemoveRange(It.IsAny <List <TestEntity> >()), Times.Once());
        }
        public async Task <ActionResult <IList <CarStatusLookup> > > GetCarStatusLookup()
        {
            List <CarStatusLookup> carStatusLookups = await _dbContext.Query <CarStatusLookup>().ToListAsync();

            return(carStatusLookups);
        }