Ejemplo n.º 1
0
        public void ToFutureWithCollection()
        {
            using (var dataContext = new SimpleDataContext())
            using (var futureCollection = dataContext.CreateFutureCollection())
            {
                var people = dataContext.Persons
                    .Where(a => a.FirstName == "Tom" || a.FirstName == "Cat")
                    .ToFuture(futureCollection);

                Assert.NotNull(people);
                Assert.Equal(1, futureCollection.Count);

                var pets = dataContext.Pets
                    .Where(a => a.Name == "Taboo")
                    .ToFuture(futureCollection);

                Assert.NotNull(pets);
                Assert.Equal(2, futureCollection.Count);

                var peopleValues = people.Value;

                Assert.NotNull(peopleValues);
                Assert.True(people.IsValueCreated);
                Assert.False(pets.IsValueCreated);
                Assert.Equal(2, peopleValues.Count);
                Assert.Equal(0, futureCollection.Count);
            }
        }
Ejemplo n.º 2
0
 public void ToFuture()
 {
     using (var dataContext = new SimpleDataContext())
     {
         Assert.Throws<InvalidCastException>(() =>
         {
             dataContext.Persons
                 .Where(a => a.FirstName == "Tom" || a.FirstName == "Cat")
                 .ToFuture();
         });
     }
 }
        public void NonDataQueryWithCollection()
        {
            var list = new List<int> { 1, 2, 3 };
            var query = list.AsQueryable();

            using (var dataContext = new SimpleDataContext())
            using (var futureCollection = dataContext.CreateFutureCollection())
            {
                var lazy = query.ToFuture(futureCollection);

                Assert.NotNull(lazy);
                Assert.False(lazy.IsValueCreated);
                Assert.Equal(0, futureCollection.Count);

                var value = lazy.Value;

                Assert.NotNull(value);
                Assert.True(lazy.IsValueCreated);
                Assert.Equal(3, value.Count);
                Assert.Equal(0, futureCollection.Count);
            }
        }