Skip to content

Commit

Permalink
Use BinaryHttpDomainClient in AspNetCore Test (#471)
Browse files Browse the repository at this point in the history
* Use BinaryHttpDomainClientFactory instead of obsolete WebDomainClientFactory for AspNetCore tests.

---------

Co-authored-by: Daniel Svensson <[email protected]>
  • Loading branch information
SandstromErik and Daniel-Svensson authored Dec 22, 2023
1 parent c259c78 commit f786760
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,5 +260,12 @@ public static WebException ExpectWebException(GenericDelegate del, string messag
Assert.AreEqual(webExceptionStatus, e.Status);
return e;
}

public static InvalidCastException ExpectInvalidCastException(GenericDelegate del, string message)
{
InvalidCastException e = ExpectExceptionHelper<InvalidCastException>(del);
Assert.AreEqual(message, e.Message);
return e;
}
}
}
8 changes: 0 additions & 8 deletions src/Test/OpenRiaservices.EndToEnd.AspNetCore.Test/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ public static void AssemblyInit(TestContext context)
UseCookies = true,
AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip,
});
#if NETFRAMEWORK
#pragma warning disable CS0618 // Type or member is obsolete
DomainContext.DomainClientFactory = new Web.WebDomainClientFactory()
{
ServerBaseUri = TestURIs.RootURI,
};
#pragma warning restore CS0618 // Type or member is obsolete
#endif

// Note: Below gives errors when running (at least BinaryHttpDomainClientFactory) against AspNetCore
// It seems to cache results even with "private, no-store"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,9 @@ public void TestInvalidProviderName()
/// Verify that if an invalid DomainOperationEntry name is specified, that the Load
/// operation finishes with the expected WebResponse.StatusCode.
/// </summary>
#if ASPNETCORE
[Ignore("BinaryHttpDomainClientFactory does not validate if method exists, and since name is always specified by code generation it is not important to validate it")]
#endif
[TestMethod]
public void TestInvalidMethodName()
{
Expand Down
15 changes: 13 additions & 2 deletions src/Test/OpenRiaservices.EndToEnd.Wcf.Test/Data/QueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,12 +1952,19 @@ public void TestDomainOperationEntry_IncorrectParameterType()
paramValues["subCategoryID"] = "Foobar";
paramValues["minListPrice"] = 50;
paramValues["color"] = "Yellow";

#if ASPNETCORE
ExceptionHelper.ExpectInvalidCastException(delegate
{
var query = ctxt.CreateQuery<Product>("GetProductsMultipleParams", paramValues, false, true);
ctxt.Load(query, false);
}, "Specified cast is not valid.");
#else
ExceptionHelper.ExpectArgumentException(delegate
{
var query = ctxt.CreateQuery<Product>("GetProductsMultipleParams", paramValues, false, true);
ctxt.Load(query, false);
}, "Object of type 'System.String' cannot be converted to type 'System.Int32'.");
#endif
}

/// <summary>
Expand Down Expand Up @@ -1999,14 +2006,18 @@ await ValidateQueryException(ctxt, query, ex =>
});
}

#if ASPNETCORE
[Ignore("BinaryHttpDomainClientFactory does not validate if method exists, and since name is always specified by code generation it is not important to validate it")]
#endif
[TestMethod]
public async Task TestServerExceptions_QueryOnNonExistentMethod()
{
TestDataContext ctxt = new TestDataContext(new Uri(TestURIs.RootURI, "TestDomainServices-TestCatalog1.svc"));
var query = ctxt.CreateQuery<Product>("NonExistentMethod", null, false, true);
await ValidateQueryException(ctxt, query, ex =>
{
// REVIEW: Assert the error message.
Assert.IsTrue(ex.Message.StartsWith("Load operation failed for query 'NonExistentMethod'. An error occurred while receiving the HTTP response to"));
Assert.IsTrue(ex.Message.EndsWith("This could be due to the service endpoint binding not using the HTTP protocol. This could also be due to an HTTP request context being aborted by the server (possibly due to the service shutting down). See server logs for more details."));
Assert.IsNotNull(ex.InnerException as CommunicationException, "Expected CommunicationException");
Assert.IsNotNull(ex.InnerException.InnerException as WebException, "Expected WebException");
});
Expand Down

0 comments on commit f786760

Please sign in to comment.