Exemplo n.º 1
0
 public TestLoadMoreDataSource(CliMessagePump pump, int numberOfObjectsToSimulate, TimeSpan maxDelay) : base(pump)
 {
     serverData    = new List <Item>();
     this.MaxDelay = maxDelay;
     for (int i = 0; i < numberOfObjectsToSimulate; i++)
     {
         serverData.Add(new Item(i, "StringValue-" + i));
     }
 }
Exemplo n.º 2
0
        public void LoadMoreBasic()
        {
            int                    expectedNumberOfItems = 95;
            CliMessagePump         pump       = new CliMessagePump(ConsoleProvider.Current, (k) => { });
            TestLoadMoreDataSource dataSource = new TestLoadMoreDataSource(pump, expectedNumberOfItems, TimeSpan.FromMilliseconds(50));

            var           query      = new CollectionQuery(0, 7, null);
            List <object> viewedData = new List <object>();

            pump.Start();

            // the first call to GetDataView should return an empty result that indicates that the view is incomplete
            // because it is still loading data
            var initialDataView = dataSource.GetDataView(query);

            Assert.IsFalse(initialDataView.IsViewComplete);
            Assert.IsFalse(initialDataView.IsViewEndOfData);
            Assert.AreEqual(0, initialDataView.Items.Count);

            // Since we're simulating the server call and we know the max amount of time it can take wait twice that long
            Thread.Sleep(dataSource.MaxDelay + dataSource.MaxDelay);

            // Now there should be a full page of data available to us
            var nextAttemptDataView = dataSource.GetDataView(query);

            Assert.AreEqual(query.Take, nextAttemptDataView.Items.Count);
            Assert.IsTrue(nextAttemptDataView.IsViewComplete);
            Assert.IsFalse(nextAttemptDataView.IsViewEndOfData);

            viewedData.AddRange(nextAttemptDataView.Items);
            query.Skip += query.Take;

            // now ask for data in a tight loop.  Sometimes we will get more data, sometimes we'll get an empty page
            // while more data is being loaded
            while (nextAttemptDataView.IsViewEndOfData == false)
            {
                nextAttemptDataView = dataSource.GetDataView(query);

                Console.WriteLine(nextAttemptDataView.Items.Count + " items, viewComplete == " + nextAttemptDataView.IsViewComplete);

                if (nextAttemptDataView.Items.Count < query.Take && nextAttemptDataView.IsViewEndOfData == false)
                {
                    Thread.Sleep(10);
                    Assert.IsFalse(nextAttemptDataView.IsViewComplete);
                }
                else if (nextAttemptDataView.Items.Count == query.Take)
                {
                    Assert.IsTrue(nextAttemptDataView.IsViewComplete);
                }
                else if (nextAttemptDataView.Items.Count > query.Take)
                {
                    Assert.Fail(nextAttemptDataView.Items.Count + " should never exceed " + query.Take);
                }

                viewedData.AddRange(nextAttemptDataView.Items);
                query.Skip += nextAttemptDataView.Items.Count;
            }

            int nextExpectedId = 0;

            foreach (var item in viewedData)
            {
                Assert.IsNotNull(item);
                Console.WriteLine(item);
                Assert.AreEqual(nextExpectedId++, ((Item)item).Id);
            }

            Assert.AreEqual(expectedNumberOfItems, viewedData.Count);
            console.InputQueue.Enqueue(new ConsoleKeyInfo(' ', ConsoleKey.Escape, false, false, false));
        }
Exemplo n.º 3
0
 public BlobDataSource(CloudBlobContainer container, CliMessagePump pump) : base(pump)
 {
     this.container = container;
 }
Exemplo n.º 4
0
 public TableEntityDataSource(CloudTable table, CliMessagePump pump) : base(pump)
 {
     this.table = table;
 }
Exemplo n.º 5
0
 public ContainerListDataSource(CloudBlobClient client, CliMessagePump pump) : base(pump)
 {
     this.client = client;
 }
 public TableListDataSource(CloudTableClient client, CliMessagePump pump) : base(pump)
 {
     this.client = client;
 }