From 9495cefe0319fe8cfe2f043043866a57b5617f7d Mon Sep 17 00:00:00 2001 From: Eric Sibly Date: Tue, 22 Oct 2024 07:51:25 -0700 Subject: [PATCH] Add additional tests for assertor. --- .../Framework/UnitTesting/AgentTest.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/CoreEx.Test/Framework/UnitTesting/AgentTest.cs b/tests/CoreEx.Test/Framework/UnitTesting/AgentTest.cs index da7311d2..49c2e0be 100644 --- a/tests/CoreEx.Test/Framework/UnitTesting/AgentTest.cs +++ b/tests/CoreEx.Test/Framework/UnitTesting/AgentTest.cs @@ -11,6 +11,7 @@ using CoreEx.Http; using CoreEx.TestFunction.Models; using UnitTestEx.Expectations; +using UnitTestEx.Assertors; namespace CoreEx.Test.Framework.UnitTesting { @@ -35,30 +36,39 @@ public void Get() public void Update_Error() { var test = ApiTester.Create(); - test.Agent().With() + var result = test.Agent().With() .ExpectErrorType(CoreEx.Abstractions.ErrorType.ValidationError) .ExpectError("Zed is dead.") - .Run(a => a.UpdateAsync(new Product { Name = "Apple", Price = 0.79m }, "Zed")); + .Run(a => a.UpdateAsync(new Product { Name = "Apple", Price = 0.79m }, "Zed")) + .Result; + + Assert.That(result.Response.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.BadRequest)); } [Test] public void Delete() { var test = ApiTester.Create(); - test.Agent().With() + var res = test.Agent().With() .Run(a => a.DeleteAsync("abc")) .AssertNoContent(); + + var result = (HttpResultAssertor)res; + Assert.That(result.Response.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.NoContent)); } [Test] public void Catalogue() { var test = ApiTester.Create(); - var x = test.Agent().With() + var res = test.Agent().With() .Run(a => a.CatalogueAsync("abc")) .AssertOK() .AssertContentTypePlainText() .AssertContent("Catalog for 'abc'."); + + var result = (HttpResultAssertor)res; + Assert.That(result.Response.StatusCode, Is.EqualTo(System.Net.HttpStatusCode.OK)); } public class ProductAgent(HttpClient client, IJsonSerializer jsonSerializer, CoreEx.ExecutionContext executionContext) : CoreEx.Http.TypedHttpClientBase(client, jsonSerializer, executionContext)