示例#1
0
        internal static List <T> FindAllAsync <T>(ServiceContext context, T entity, int startPosition = 1, int maxResults = 500) where T : IEntity
        {
            //Initializing the Dataservice object with ServiceContext
            DataService.DataService service = new DataService.DataService(context);

            bool isFindAll = false;

            IdsException exp = null;

            // Used to signal the waiting test thread that a async operation have completed.
            ManualResetEvent manualEvent = new ManualResetEvent(false);

            List <T> entities = new List <T>();

            // Async callback events are anonomous and are in the same scope as the test code,
            // and therefore have access to the manualEvent variable.
            service.OnFindAllAsyncCompleted += (sender, e) =>
            {
                isFindAll = true;
                manualEvent.Set();
                if (e.Error != null)
                {
                    exp = e.Error;
                }
                if (exp == null)
                {
                    if (e.Entities != null)
                    {
                        foreach (IEntity en in e.Entities)
                        {
                            entities.Add((T)en);
                        }
                    }
                }
            };

            // Call the service method
            service.FindAllAsync <T>(entity, 1, 10);

            manualEvent.WaitOne(60000, false); Thread.Sleep(10000);


            // Check if we completed the async call, or fail the test if we timed out.
            if (!isFindAll)
            {
                Assert.Fail("Find All Failed");
            }

            if (exp != null)
            {
                throw exp;
            }

            if (entities != null)
            {
                Assert.IsTrue(entities.Count >= 0);
            }

            // Set the event to non-signaled before making next async call.
            manualEvent.Reset();
            return(entities);
        }