Example #1
0
        public void Fetch_Lazy()
        {
            Table <Author> table = new Table <Author>(_session, new MappingConfiguration());

            table.Create();

            var           mapper          = new Mapper(_session, new MappingConfiguration().Define(new FluentUserMapping()));
            List <Author> expectedAuthors = Author.GetRandomList(100);

            foreach (Author expectedAuthor in expectedAuthors)
            {
                mapper.Insert(expectedAuthor);
            }

            // wait until all records are available to be fetched:
            List <Author> authors        = mapper.Fetch <Author>("SELECT * from " + table.Name).ToList();
            DateTime      futureDateTime = DateTime.Now.AddSeconds(10);

            while (authors.Count < expectedAuthors.Count && DateTime.Now < futureDateTime)
            {
                authors = mapper.Fetch <Author>("SELECT * from " + table.Name).ToList();
            }
            Assert.AreEqual(expectedAuthors.Count, authors.Count, "Setup FAIL: Less than expected number of authors uploaded");

            Cql           cql = new Cql("SELECT * from " + table.Name).WithOptions(o => o.SetConsistencyLevel(ConsistencyLevel.Quorum));
            List <Author> authorsFetchedAndSaved = new List <Author>();
            var           authorsFetched         = mapper.Fetch <Author>(cql).GetEnumerator();

            while (authorsFetched.MoveNext())
            {
                authorsFetchedAndSaved.Add(authorsFetched.Current);
            }

            Assert.AreEqual(expectedAuthors.Count, authorsFetchedAndSaved.Count);
            foreach (var authorFetched in authorsFetchedAndSaved)
            {
                Author.AssertListContains(expectedAuthors, authorFetched);
            }
        }