tests: cover null responses
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class CanceledMessageBatchResultTests : SerializationTest
|
||||
{
|
||||
private const string SampleJson = @"{
|
||||
""type"": ""canceled""
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var result = new CanceledMessageBatchResult();
|
||||
|
||||
result.Type.Should().Be(MessageBatchResultType.Canceled);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var result = new CanceledMessageBatchResult();
|
||||
|
||||
var json = Serialize(result);
|
||||
|
||||
JsonAssert.Equal(SampleJson, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedProperties()
|
||||
{
|
||||
var result = Deserialize<CanceledMessageBatchResult>(SampleJson);
|
||||
|
||||
result!.Type.Should().Be(MessageBatchResultType.Canceled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ErroredMessageBatchResultTests : SerializationTest
|
||||
{
|
||||
private const string SampleJson = @"{
|
||||
""type"": ""errored"",
|
||||
""error"": {
|
||||
""type"": ""error"",
|
||||
""error"": {
|
||||
""type"": ""api_error"",
|
||||
""message"": ""An error occurred.""
|
||||
}
|
||||
}
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var result = new ErroredMessageBatchResult();
|
||||
|
||||
result.Type.Should().Be(MessageBatchResultType.Errored);
|
||||
result.Error.Error.Should().BeOfType<ApiError>();
|
||||
result.Error.Error.Message.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var result = new ErroredMessageBatchResult
|
||||
{
|
||||
Error = new(new ApiError("An error occurred."))
|
||||
};
|
||||
|
||||
var json = Serialize(result);
|
||||
|
||||
JsonAssert.Equal(SampleJson, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedProperties()
|
||||
{
|
||||
var result = Deserialize<ErroredMessageBatchResult>(SampleJson);
|
||||
|
||||
result!.Type.Should().Be(MessageBatchResultType.Errored);
|
||||
result.Error.Error.Should().BeOfType<ApiError>();
|
||||
result.Error.Error.Message.Should().Be("An error occurred.");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ExpiredMessageBatchResultTests : SerializationTest
|
||||
{
|
||||
private const string SampleJson = @"{
|
||||
""type"": ""expired""
|
||||
}";
|
||||
|
||||
[Fact]
|
||||
public void Constructor_WhenCalled_ItShouldReturnAnInstanceWithPropertiesSet()
|
||||
{
|
||||
var result = new ExpiredMessageBatchResult();
|
||||
|
||||
result.Type.Should().Be(MessageBatchResultType.Expired);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var result = new ExpiredMessageBatchResult();
|
||||
|
||||
var json = Serialize(result);
|
||||
|
||||
JsonAssert.Equal(SampleJson, json);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenDeserialized_ItShouldHaveExpectedProperties()
|
||||
{
|
||||
var result = Deserialize<ExpiredMessageBatchResult>(SampleJson);
|
||||
|
||||
result!.Type.Should().Be(MessageBatchResultType.Expired);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class MessageBatchResultTests : SerializationTest
|
||||
{
|
||||
[Fact]
|
||||
public void JsonDeserialization_WhenHasUnknownType_ItShouldThrowException()
|
||||
{
|
||||
var json = @"{""type"":""unknown""}";
|
||||
|
||||
var action = () => Deserialize<MessageBatchResult>(json);
|
||||
|
||||
action.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WhenSerialized_ItShouldHaveExpectedShape()
|
||||
{
|
||||
var expectedJson = @"{""type"":""expired""}";
|
||||
var messageBatchResult = new ExpiredMessageBatchResult();
|
||||
|
||||
var json = Serialize<MessageBatchResult>(messageBatchResult);
|
||||
|
||||
JsonAssert.Equal(expectedJson, json);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace AnthropicClient.Tests.Unit.Models;
|
||||
|
||||
public class ToolCallTests : SerializationTest
|
||||
|
||||
Reference in New Issue
Block a user