Skip to content

Commit

Permalink
- Make some public OData service tests skippable (sometimes the OData…
Browse files Browse the repository at this point in the history
….org services may be down).
  • Loading branch information
robertmclaws committed Apr 16, 2024
1 parent 13bdf38 commit c772206
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/Simple.OData.Tests.Client.Integration/FindNorthwindTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using FluentAssertions;
using Simple.OData.Client;
using Xunit;
using Xunit.Sdk;
using Entry = System.Collections.Generic.Dictionary<string, object>;

namespace Simple.OData.Tests.Client;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -100,7 +111,7 @@ public async Task FilterStringExpression()
Assert.Equal("Chai", (products as IEnumerable<dynamic>).Single().ProductName);
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task Get()
{
var category = await _client
Expand All @@ -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
Expand All @@ -121,7 +132,7 @@ public async Task SkipOneTopOne()
Assert.Single(products);
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task OrderBy()
{
var product = (await _client
Expand All @@ -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
Expand All @@ -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
Expand All @@ -153,7 +164,7 @@ public async Task ExpandOne()
Assert.Equal("Confections", (product["Category"] as IDictionary<string, object>)["CategoryName"]);
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task ExpandMany()
{
var category = await _client
Expand All @@ -164,7 +175,7 @@ public async Task ExpandMany()
Assert.Equal(12, (category["Products"] as IEnumerable<object>).Count());
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task ExpandSecondLevel()
{
var product = (await _client
Expand All @@ -175,7 +186,7 @@ public async Task ExpandSecondLevel()
Assert.Equal(13, ((product["Category"] as IDictionary<string, object>)["Products"] as IEnumerable<object>).Count());
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task ExpandProductsOrderByCategoryName()
{
var product = (await _client
Expand All @@ -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)
Expand All @@ -201,7 +212,7 @@ public async Task ExpandCategoryOrderByProductName()
}
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task Count()
{
var count = await _client
Expand All @@ -211,7 +222,7 @@ public async Task Count()
Assert.Equal(77, count);
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task TotalCount()
{
var annotations = new ODataFeedAnnotations();
Expand All @@ -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
Expand All @@ -236,7 +247,7 @@ public async Task CombineAll()
Assert.Equal("Seafood", (product["Category"] as IDictionary<string, object>)["CategoryName"]);
}

[Fact]
[SkippableFact(typeof(WebRequestException))]
public async Task NavigateToSingle()
{
var category = await _client
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<None Include="app.config" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Xunit.SkippableFact" Version="1.4.13" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Simple.OData.Client.V3.Adapter\Simple.OData.Client.V3.Adapter.csproj" />
<ProjectReference Include="..\Simple.OData.Client.V4.Adapter\Simple.OData.Client.V4.Adapter.csproj" />
Expand Down

0 comments on commit c772206

Please sign in to comment.