public void TestBulkDeletionResultsSerializable()
        {
            var successfulObjects = new[] { "/container/object1", "/container/object2" };
            var failedObjects =
                new[]
                {
                    new BulkDeletionFailedObject("/badContainer/object3", new Status((int)HttpStatusCode.BadRequest, "invalidContainer")),
                    new BulkDeletionFailedObject("/container/badObject", new Status((int)HttpStatusCode.BadRequest, "invalidName"))
                };
            BulkDeletionResults results = new BulkDeletionResults(successfulObjects, failedObjects);
            BinaryFormatter formatter = new BinaryFormatter();
            using (Stream stream = new MemoryStream())
            {
                formatter.Serialize(stream, results);
                stream.Position = 0;
                BulkDeletionResults deserialized = (BulkDeletionResults)formatter.Deserialize(stream);
                Assert.IsNotNull(deserialized);

                Assert.IsNotNull(deserialized.SuccessfulObjects);
                Assert.AreEqual(successfulObjects.Length, deserialized.SuccessfulObjects.Count());
                for (int i = 0; i < successfulObjects.Length; i++)
                    Assert.AreEqual(successfulObjects[i], deserialized.SuccessfulObjects.ElementAt(i));

                Assert.IsNotNull(deserialized.FailedObjects);
                Assert.AreEqual(failedObjects.Length, deserialized.FailedObjects.Count());
                for (int i = 0; i < failedObjects.Length; i++)
                {
                    Assert.IsNotNull(deserialized.FailedObjects.ElementAt(i));
                    Assert.AreEqual(failedObjects[i].Object, deserialized.FailedObjects.ElementAt(i).Object);
                    Assert.IsNotNull(deserialized.FailedObjects.ElementAt(i).Status);
                    Assert.AreEqual(failedObjects[i].Status.Code, deserialized.FailedObjects.ElementAt(i).Status.Code);
                    Assert.AreEqual(failedObjects[i].Status.Description, deserialized.FailedObjects.ElementAt(i).Status.Description);
                }
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="BulkDeletionException"/> class
        /// with the specified status and results.
        /// </summary>
        /// <param name="status">A description of the status of the operation.</param>
        /// <param name="results">The results of the bulk delete operation.</param>
        /// <exception cref="ArgumentNullException">
        /// If <paramref name="status"/> is <c>null</c>.
        /// <para>-or-</para>
        /// <para>If <paramref name="results"/> is <c>null</c>.</para>
        /// </exception>
        /// <exception cref="ArgumentException">
        /// If <paramref name="status"/> is empty.
        /// </exception>
        public BulkDeletionException(string status, BulkDeletionResults results)
            : base(string.Format("The bulk deletion operation did not complete successfully. Status: {0}", status))
        {
            if (status == null)
                throw new ArgumentNullException("status");
            if (results == null)
                throw new ArgumentNullException("results");
            if (string.IsNullOrEmpty(status))
                throw new ArgumentException("status cannot be empty");

            _state.Results = results;
#if !NET35
            SerializeObjectState += (ex, args) => args.AddSerializedState(_state);
#endif
        }
 public BulkDeletionException(string status, BulkDeletionResults results) : base(string.Format("The bulk deletion operation did not complete successfully.  Status code: {0}", status))
 {
     Results = results;
 }