Ejemplo n.º 1
0
        public void WhenInstanciatingDbQueryContextThenReturnsObject()
        {
            // Arrange
            FakeDbContext context = CreateDbContext();

            // Act
            DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context);

            // Assert
            Assert.NotNull(queryContext);
        }
Ejemplo n.º 2
0
        public void WhenDisposingQueryContexthenDisposeInnerDbContext()
        {
            // Arrange
            FakeDbContext context = CreateDbContext(10);
            DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context);

            // Act
            queryContext.Dispose();

            // Assert
            Assert.True(context.Disposed);
        }
Ejemplo n.º 3
0
        private static FakeDbContext CreateDbContext(int count = 0)
        {
            DbConnection connection = DbConnectionFactory.CreateTransient();

            FakeDbContext context = new FakeDbContext(connection);
            for (int i = 1; i <= count; i++)
            {
                context.Entities.Add(new FakeEntity { Property1 = "test" + i, Property2 = i });
            }

            context.SaveChanges();
            return context;
        }
Ejemplo n.º 4
0
        public async Task WhenFindingItemThenRetunsEntity()
        {
            // Arrange
            FakeDbContext context = CreateDbContext(10);
            DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context);

            // Act
            FakeEntity result = await queryContext.FindAsync <FakeEntity>("test3");

            // Assert
            Assert.NotNull(result);
            Assert.Equal(3, result.Property2);
            Assert.Equal("test3", result.Property1);
        }
Ejemplo n.º 5
0
        private static FakeDbContext CreateDbContext(int count = 0)
        {
            DbConnection connection = DbConnectionFactory.CreateTransient();

            FakeDbContext context = new FakeDbContext(connection);

            for (int i = 1; i <= count; i++)
            {
                context.Entities.Add(new FakeEntity {
                    Property1 = "test" + i, Property2 = i
                });
            }

            context.SaveChanges();
            return(context);
        }
Ejemplo n.º 6
0
        public void WhenQueryingItemsThenReturnsEntities()
        {
            // Arrange
            FakeDbContext context = CreateDbContext(10);
            DbQueryContext <FakeDbContext> queryContext = new DbQueryContext <FakeDbContext>(context);

            // Act
            var query = queryContext.Query <FakeEntity>();

            // Assert
            Assert.NotNull(query);
            Assert.Equal(context.Entities.Count(), query.Count());
            Assert.NotNull(query.FirstOrDefault());
            Assert.Equal(context.Entities.FirstOrDefault(), query.FirstOrDefault());
            Assert.Equal(context.Entities.Count(item => item.Property2 >= 5), query.Count(item => item.Property2 >= 5));
        }