public void TestBatchExceptionCreatedFromBatchErrorWithNoBody()
        {
            Protocol.Models.BatchErrorException batchErrorException = new Protocol.Models.BatchErrorException()
            {
                Body     = null, //Body is null
                Response = new HttpResponseMessageWrapper(new HttpResponseMessage(HttpStatusCode.Accepted), string.Empty)
            };
            BatchException batchException = new BatchException(batchErrorException);

            Assert.Null(batchException.RequestInformation.BatchError);
        }
        public void TestBatchExceptionCreatedWithRetryAfterDuration()
        {
            Protocol.Models.BatchErrorException batchErrorException = new Protocol.Models.BatchErrorException()
            {
                Body     = null, //Body is null
                Response = new HttpResponseMessageWrapper(new HttpResponseMessage(HttpStatusCode.Accepted), string.Empty)
            };
            batchErrorException.Response.Headers.Add(InternalConstants.RetryAfterHeader, new List <string> {
                "10"
            });
            BatchException batchException = new BatchException(batchErrorException);

            Assert.Equal(TimeSpan.FromSeconds(10), batchException.RequestInformation.RetryAfter);
        }
        public void TestBatchExceptionCreatedWithRetryAfterDateTime()
        {
            DateTime retryAfter       = DateTime.UtcNow.Add(TimeSpan.FromSeconds(10));
            string   retryAfterString = retryAfter.ToString("r");

            Protocol.Models.BatchErrorException batchErrorException = new Protocol.Models.BatchErrorException()
            {
                Body     = null, //Body is null
                Response = new HttpResponseMessageWrapper(new HttpResponseMessage(HttpStatusCode.Accepted), string.Empty)
            };
            batchErrorException.Response.Headers.Add(InternalConstants.RetryAfterHeader, new List <string> {
                retryAfterString
            });
            BatchException batchException = new BatchException(batchErrorException);

            Assert.True(TimeSpan.FromSeconds(9) <= batchException.RequestInformation.RetryAfter && batchException.RequestInformation.RetryAfter <= TimeSpan.FromSeconds(10));
        }
        public void TestBatchExceptionCreatedWithRetryAfterDateTime()
        {
            DateTime retryAfter       = DateTime.UtcNow.Add(TimeSpan.FromSeconds(10));
            string   retryAfterString = retryAfter.ToString("r");

            Protocol.Models.BatchErrorException batchErrorException = new Protocol.Models.BatchErrorException()
            {
                Body     = null, //Body is null
                Response = new HttpResponseMessageWrapper(new HttpResponseMessage(HttpStatusCode.Accepted), string.Empty)
            };
            batchErrorException.Response.Headers.Add(InternalConstants.RetryAfterHeader, new List <string> {
                retryAfterString
            });
            BatchException batchException = new BatchException(batchErrorException);

            this.testOutputHelper.WriteLine($"RetryAfter: {batchException.RequestInformation.RetryAfter}");
            // Give some wiggle room in case tests are running slow
            Assert.True(batchException.RequestInformation.RetryAfter <= TimeSpan.FromSeconds(10));
        }