public void ActionProgress()
        {
            var a1 = AsyncAction <int> .CreateCompleted();

            var a2 = AsyncAction <int> .CreateCompleted();

            Assert.AreEqual(AsyncStatus.Completed, a1.Status);
            Assert.AreSame(a2, a1);
            a1 = AsyncAction <int> .CreateCanceled();

            a2 = AsyncAction <int> .CreateCanceled();

            Assert.ThrowsException <OperationCanceledException>(() => a1.GetResults());
            Assert.AreEqual(AsyncStatus.Canceled, a1.Status);
            Assert.AreSame(a2, a1);
            a1 = AsyncAction <int> .CreateFault();

            a2 = AsyncAction <int> .CreateFault();

            Assert.AreEqual(AsyncStatus.Error, a1.Status);
            Assert.ThrowsException <Exception>(() => a1.GetResults());
            Assert.IsNotNull(a1.ErrorCode);
            Assert.AreSame(a2, a1);
            a1 = AsyncAction <int> .CreateFault(new InvalidOperationException("text"));

            Assert.AreEqual(AsyncStatus.Error, a1.Status);
            Assert.ThrowsException <InvalidOperationException>(() => a1.GetResults());
            Assert.IsNotNull(a1.ErrorCode);
            Assert.AreEqual("text", a1.ErrorCode.Message);
            a1.Close();
            Assert.IsNotNull(a1.ErrorCode);
            Assert.AreEqual("text", a1.ErrorCode.Message);
        }
        public IAsyncAction AddToCategoryAsync(IReadOnlyList <ItemIndexRange> items, FavoriteCategory categoty)
        {
            if (categoty is null)
            {
                throw new ArgumentNullException(nameof(categoty));
            }

            if (items is null || items.Count == 0)
            {
                return(AsyncAction.CreateCompleted());
            }

            return(AsyncInfo.Run(async token =>
            {
                var ddact = default(string);
                if (categoty.Index < 0)
                {
                    ddact = "delete";
                }
                else
                {
                    ddact = $"fav{categoty.Index}";
                }

                var post = Client.Current.HttpClient.PostAsync(this.SearchUri, getParameters());
                token.Register(post.Cancel);
                var r = await post;
                if (categoty.Index < 0)
                {
                    this.Reset();
                }
                else
                {
                    foreach (var range in items)
                    {
                        for (var i = range.FirstIndex; i <= range.LastIndex; i++)
                        {
                            this[i].FavoriteCategory = categoty;
                        }
                    }
                }
                IEnumerable <KeyValuePair <string, string> > getParameters()
                {
                    yield return new KeyValuePair <string, string>("apply", "Apply");

                    yield return new KeyValuePair <string, string>("ddact", ddact);

                    foreach (var range in items)
                    {
                        for (var i = range.FirstIndex; i <= range.LastIndex; i++)
                        {
                            yield return new KeyValuePair <string, string>("modifygids[]", this[i].ID.ToString());
                        }
                    }
                }
            }));
        }