Exemple #1
0
        public async Task ExecuteAndIgnoreStatusCode_Ignores_SpecifiedStatusCode()
        {
            // Arrange
            string testString = "Method called!";
            string s          = null;
            var    ex         = DocumentDBTestUtility.CreateDocumentClientException(HttpStatusCode.Conflict);

            // Act
            await DocumentDBUtility.ExecuteAndIgnoreStatusCodeAsync(HttpStatusCode.Conflict, () =>
            {
                s = testString;
                throw ex;
            });

            // Assert
            Assert.Equal(testString, s);
            // The fact that it doesn't throw proves that it was ignored
        }
Exemple #2
0
        public async Task ExecuteAndIgnoreStatusCode_DoesNotIgnore_OtherStatusCodes()
        {
            // Arrange
            string testString = "Method called!";
            string s          = null;
            var    ex         = DocumentDBTestUtility.CreateDocumentClientException(HttpStatusCode.ServiceUnavailable);

            // Act
            var thrownEx = await Assert.ThrowsAsync <DocumentClientException>(() =>
            {
                return(DocumentDBUtility.ExecuteAndIgnoreStatusCodeAsync(HttpStatusCode.Conflict, () =>
                {
                    s = testString;
                    throw ex;
                }));
            });

            // Assert
            Assert.Equal(testString, s);
            Assert.Equal(HttpStatusCode.ServiceUnavailable, thrownEx.StatusCode);
        }