Skip to content

Commit

Permalink
Add additional tests for assertor.
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun committed Oct 22, 2024
1 parent 3065e84 commit 9495cef
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions tests/CoreEx.Test/Framework/UnitTesting/AgentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using CoreEx.Http;
using CoreEx.TestFunction.Models;
using UnitTestEx.Expectations;
using UnitTestEx.Assertors;

namespace CoreEx.Test.Framework.UnitTesting
{
Expand All @@ -35,30 +36,39 @@ public void Get()
public void Update_Error()
{
var test = ApiTester.Create<Startup>();
test.Agent().With<ProductAgent, Product>()
var result = test.Agent().With<ProductAgent, Product>()
.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<Startup>();
test.Agent().With<ProductAgent>()
var res = test.Agent().With<ProductAgent>()
.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<Startup>();
var x = test.Agent().With<ProductAgent>()
var res = test.Agent().With<ProductAgent>()
.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<ProductAgent>(client, jsonSerializer, executionContext)
Expand Down

0 comments on commit 9495cef

Please sign in to comment.