From c7722064c4b2963de39fc6567221315d04afa401 Mon Sep 17 00:00:00 2001 From: Robert McLaws <1657085+robertmclaws@users.noreply.github.com> Date: Tue, 16 Apr 2024 18:29:33 -0400 Subject: [PATCH] - Make some public OData service tests skippable (sometimes the OData.org services may be down). --- .../FindNorthwindTests.cs | 77 +++++++++++-------- ...mple.OData.Tests.Client.Integration.csproj | 4 + 2 files changed, 48 insertions(+), 33 deletions(-) diff --git a/src/Simple.OData.Tests.Client.Integration/FindNorthwindTests.cs b/src/Simple.OData.Tests.Client.Integration/FindNorthwindTests.cs index 62ceded8..31975bdb 100644 --- a/src/Simple.OData.Tests.Client.Integration/FindNorthwindTests.cs +++ b/src/Simple.OData.Tests.Client.Integration/FindNorthwindTests.cs @@ -1,6 +1,7 @@ using FluentAssertions; using Simple.OData.Client; using Xunit; +using Xunit.Sdk; using Entry = System.Collections.Generic.Dictionary; namespace Simple.OData.Tests.Client; @@ -51,35 +52,45 @@ public abstract class FindNorthwindTests(string serviceUri, ODataPayloadFormat p { protected async override Task DeleteTestData() { - var products = await _client.For("Products").Select("ProductID", "ProductName").FindEntriesAsync(); - foreach (var product in products) + try { - if (product["ProductName"].ToString().StartsWith("Test")) + var products = await _client.For("Products").Select("ProductID", "ProductName").FindEntriesAsync(); + foreach (var product in products) { - await _client.DeleteEntryAsync("Products", product); + if (product["ProductName"].ToString().StartsWith("Test")) + { + await _client.DeleteEntryAsync("Products", product); + } } - } - var categories = await _client.For("Categories").Select("CategoryID", "CategoryName").FindEntriesAsync(); - foreach (var category in categories) - { - if (category["CategoryName"].ToString().StartsWith("Test")) + var categories = await _client.For("Categories").Select("CategoryID", "CategoryName").FindEntriesAsync(); + foreach (var category in categories) { - await _client.DeleteEntryAsync("Categories", category); + if (category["CategoryName"].ToString().StartsWith("Test")) + { + await _client.DeleteEntryAsync("Categories", category); + } } - } - var employees = await _client.For("Employees").Select("EmployeeID", "LastName").FindEntriesAsync(); - foreach (var employee in employees) + var employees = await _client.For("Employees").Select("EmployeeID", "LastName").FindEntriesAsync(); + foreach (var employee in employees) + { + if (employee["LastName"].ToString().StartsWith("Test")) + { + await _client.DeleteEntryAsync("Employees", employee); + } + } + } + catch (WebRequestException ex) { - if (employee["LastName"].ToString().StartsWith("Test")) + if (ex.Code == System.Net.HttpStatusCode.InternalServerError) { - await _client.DeleteEntryAsync("Employees", employee); + Console.WriteLine(ex.Message); } } } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task Filter() { var products = await _client @@ -89,7 +100,7 @@ public async Task Filter() products.Single()["ProductName"].Should().Be("Chai"); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task FilterStringExpression() { var x = ODataDynamic.Expression; @@ -100,7 +111,7 @@ public async Task FilterStringExpression() Assert.Equal("Chai", (products as IEnumerable).Single().ProductName); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task Get() { var category = await _client @@ -110,7 +121,7 @@ public async Task Get() category["CategoryID"].Should().Be(1); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task SkipOneTopOne() { var products = await _client @@ -121,7 +132,7 @@ public async Task SkipOneTopOne() Assert.Single(products); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task OrderBy() { var product = (await _client @@ -131,7 +142,7 @@ public async Task OrderBy() Assert.Equal("Alice Mutton", product["ProductName"]); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task SelectMultiple() { var product = await _client @@ -142,7 +153,7 @@ public async Task SelectMultiple() Assert.Contains("ProductID", product.Keys); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task ExpandOne() { var product = (await _client @@ -153,7 +164,7 @@ public async Task ExpandOne() Assert.Equal("Confections", (product["Category"] as IDictionary)["CategoryName"]); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task ExpandMany() { var category = await _client @@ -164,7 +175,7 @@ public async Task ExpandMany() Assert.Equal(12, (category["Products"] as IEnumerable).Count()); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task ExpandSecondLevel() { var product = (await _client @@ -175,7 +186,7 @@ public async Task ExpandSecondLevel() Assert.Equal(13, ((product["Category"] as IDictionary)["Products"] as IEnumerable).Count()); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task ExpandProductsOrderByCategoryName() { var product = (await _client @@ -187,7 +198,7 @@ public async Task ExpandProductsOrderByCategoryName() Assert.Equal("Condiments", product.Category.CategoryName); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task ExpandCategoryOrderByProductName() { if (_serviceUri.AbsoluteUri == ODataV4ReadWriteUri) @@ -201,7 +212,7 @@ public async Task ExpandCategoryOrderByProductName() } } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task Count() { var count = await _client @@ -211,7 +222,7 @@ public async Task Count() Assert.Equal(77, count); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task TotalCount() { var annotations = new ODataFeedAnnotations(); @@ -222,7 +233,7 @@ public async Task TotalCount() Assert.Equal(20, products.Count()); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task CombineAll() { var product = (await _client @@ -236,7 +247,7 @@ public async Task CombineAll() Assert.Equal("Seafood", (product["Category"] as IDictionary)["CategoryName"]); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task NavigateToSingle() { var category = await _client @@ -247,7 +258,7 @@ public async Task NavigateToSingle() Assert.Equal("Beverages", category["CategoryName"]); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task NavigateToMultiple() { var products = await _client @@ -258,7 +269,7 @@ public async Task NavigateToMultiple() Assert.Equal(12, products.Count()); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task NavigateToRecursive() { var employee = await _client @@ -272,7 +283,7 @@ public async Task NavigateToRecursive() Assert.Equal("Steven", employee["FirstName"]); } - [Fact] + [SkippableFact(typeof(WebRequestException))] public async Task NavigateToRecursiveSingleClause() { var employee = await _client diff --git a/src/Simple.OData.Tests.Client.Integration/Simple.OData.Tests.Client.Integration.csproj b/src/Simple.OData.Tests.Client.Integration/Simple.OData.Tests.Client.Integration.csproj index 972b2783..ed1856df 100644 --- a/src/Simple.OData.Tests.Client.Integration/Simple.OData.Tests.Client.Integration.csproj +++ b/src/Simple.OData.Tests.Client.Integration/Simple.OData.Tests.Client.Integration.csproj @@ -14,6 +14,10 @@ + + + +