public void CallDbSetFakeDirectly()
        {
            var context = ContextFaker.CreateContext <TestContext>();

            var data = new Acorn[] { };

            IQueryable <Acorn>  dataQueryable  = data.AsQueryable();
            IEnumerator <Acorn> dataEnumerator = dataQueryable.GetEnumerator();

            var mockSet = A.Fake <DbSet <Acorn> >(builder =>
            {
                builder.Implements(typeof(IDbAsyncEnumerable <Acorn>));
                builder.Implements(typeof(IQueryable <Acorn>));
            });

            var mockEnumerable = (IDbAsyncEnumerable <Acorn>)mockSet;

            A.CallTo(() => (mockEnumerable).GetAsyncEnumerator())
            .Returns(new TestDbAsyncEnumerator <Acorn>(dataEnumerator));

            A.CallTo(() => ((IQueryable <Acorn>)mockSet).Provider)
            .Returns(new TestDbAsyncQueryProvider <Acorn>(dataQueryable.Provider));

            A.CallTo(() => ((IQueryable <Acorn>)mockSet).Expression).Returns(dataQueryable.Expression);
            A.CallTo(() => ((IQueryable <Acorn>)mockSet).ElementType).Returns(dataQueryable.ElementType);
            A.CallTo(() => ((IQueryable <Acorn>)mockSet).GetEnumerator()).Returns(dataEnumerator);

            A.CallTo(() => context.Acorns).Returns(mockSet);

            Assert.Empty(context.Acorns.ToArray());
        }
        public void SupportsLinqQuerying()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            var result = context.Acorns.Where(a => (a.Id + a.NutritionValue) % 2 == 0).OrderBy(a => a.Id);

            Assert.Equal(TestDataFactory.AcornTestData.Where(a => (a.Id + a.NutritionValue) % 2 == 0).OrderBy(a => a.Id), result, Comparer);
        }
예제 #3
0
        public async Task SingleAsyncNotPresentThrowsCorrectException()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            await
            Assert.ThrowsAsync <InvalidOperationException>(
                () => context.Acorns.SingleAsync(a => a.Id == int.MaxValue));
        }
예제 #4
0
        public async Task SupportsAsyncLinqQuerying()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            var result = await context.Acorns.Where(a => a.NutritionValue > 5).ToArrayAsync();

            Assert.Equal(TestDataFactory.AcornTestData.Where(a => a.NutritionValue > 5).OrderBy(a => a.Id), result.OrderBy(a => a.Id), Comparer);
        }
예제 #5
0
        public async Task CanQueryDbSetWithObjectsAsync()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            var result = await context.Acorns.ToListAsync();

            Assert.Equal(TestDataFactory.AcornTestData, result, Comparer);
        }
예제 #6
0
        public void CanFindWithCustomId()
        {
            var guid   = new Guid("7C45F3DF-60B4-4E7D-A6EF-E76DFBA9E9B3");
            var energy = 10000000;

            ContextFaker.AddIdGetterForType((Photon photon) => photon.WavePacketIdentifier);
            ContextFaker.ContextReturnsDbSet(() => context.Photons,
                                             new List <Photon>(new[] { new Photon(guid, energy), new Photon(new Guid(), 13215516451) }));

            var result = context.Photons.Find(guid);

            Assert.Equal(energy, result.Energy);
        }
        public ContextAddTests()
        {
            context = ContextFaker.CreateContext <TestContext>();
            acorns  = TestDataFactory.AcornTestData.ToList();

            ContextFaker.ContextReturnsDbSet(() => context.Acorns, acorns);

            acorn1 = new Acorn
            {
                Id             = 3,
                NutritionValue = 5
            };

            acorn2 = new Acorn
            {
                Id             = 4,
                NutritionValue = 7
            };
        }
예제 #8
0
 public FindTests()
 {
     context = ContextFaker.CreateContext <TestContext>();
     ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());
 }
        public void SingleNotPresentThrowsCorrectException()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            Assert.Throws <InvalidOperationException>(() => context.Acorns.Single(a => a.Id == int.MaxValue));
        }
        public void PassNullListTreatsAsEmptyList()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, null);

            Assert.Empty(context.Acorns);
        }
        public void CanQueryDbSetWithObjects()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, TestDataFactory.AcornTestData.ToList());

            Assert.Equal(TestDataFactory.AcornTestData, context.Acorns.ToArray(), Comparer);
        }
        public void CanCreateATestContext()
        {
            var createdContext = ContextFaker.CreateContext <TestContext>();

            Assert.NotNull(createdContext);
        }
 public QueryContextTests()
 {
     context = ContextFaker.CreateContext <TestContext>();
 }
예제 #14
0
        public async Task CanQueryAnEmptyDbSet()
        {
            ContextFaker.ContextReturnsDbSet(() => context.Acorns, new List <Acorn>());

            Assert.Empty(await context.Acorns.ToListAsync());
        }