Пример #1
0
        internal static T DeleteAsync <T>(ServiceContext context, T entity) where T : IEntity
        {
            //Initializing the Dataservice object with ServiceContext
            DataService.DataService service = new DataService.DataService(context);

            bool isDeleted = false;

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

            IdsException exp = null;
            // Async callback events are anonomous and are in the same scope as the test code,
            // and therefore have access to the manualEvent variable.
            T returnedEntity = entity;

            service.OnDeleteAsyncCompleted += (sender, e) =>
            {
                isDeleted = true;
                manualEvent.Set();
                if (e.Error != null)
                {
                    exp = e.Error;
                }
                else
                {
                    if (e.Entity != null)
                    {
                        returnedEntity = (T)e.Entity;
                    }
                }
            };

            // Call the service method
            service.DeleteAsync(entity);

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

            if (exp != null)
            {
                throw exp;
            }
            // Check if we completed the async call, or fail the test if we timed out.
            if (!isDeleted)
            {
                Assert.Fail("Delete Failed");
            }

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

            return(returnedEntity);
        }