Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public sealed class HostedFileContent : AIContent
/// <exception cref="ArgumentException"><paramref name="fileId"/> is empty or composed entirely of whitespace.</exception>
public HostedFileContent(string fileId)
{
FileId = fileId;
FileId = Throw.IfNullOrWhitespace(fileId);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class HostedFileContentTests
[Fact]
public void Constructor_InvalidInput_Throws()
{
Assert.Throws<ArgumentNullException>(() => new HostedFileContent(null!));
Assert.Throws<ArgumentException>(() => new HostedFileContent(string.Empty));
Assert.Throws<ArgumentException>(() => new HostedFileContent(" "));
Assert.Throws<ArgumentNullException>("fileId", () => new HostedFileContent(null!));
Assert.Throws<ArgumentException>("fileId", () => new HostedFileContent(string.Empty));
Assert.Throws<ArgumentException>("fileId", () => new HostedFileContent(" "));
}

[Fact]
Expand All @@ -36,9 +36,9 @@ public void Constructor_PropsRoundtrip()
c.FileId = "id456";
Assert.Equal("id456", c.FileId);

Assert.Throws<ArgumentNullException>(() => c.FileId = null!);
Assert.Throws<ArgumentException>(() => c.FileId = string.Empty);
Assert.Throws<ArgumentException>(() => c.FileId = " ");
Assert.Throws<ArgumentNullException>("value", () => c.FileId = null!);
Assert.Throws<ArgumentException>("value", () => c.FileId = string.Empty);
Assert.Throws<ArgumentException>("value", () => c.FileId = " ");

Assert.Null(c.RawRepresentation);
object raw = new();
Expand Down Expand Up @@ -89,7 +89,7 @@ public void MediaType_Roundtrips()
public void MediaType_InvalidValue_Throws(string invalidMediaType)
{
HostedFileContent c = new("id123");
Assert.Throws<ArgumentException>(() => c.MediaType = invalidMediaType);
Assert.Throws<ArgumentException>("value", () => c.MediaType = invalidMediaType);
}

[Theory]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class HostedVectorStoreContentTests
[Fact]
public void Constructor_InvalidInput_Throws()
{
Assert.Throws<ArgumentNullException>(() => new HostedVectorStoreContent(null!));
Assert.Throws<ArgumentException>(() => new HostedVectorStoreContent(string.Empty));
Assert.Throws<ArgumentException>(() => new HostedVectorStoreContent(" "));
Assert.Throws<ArgumentNullException>("vectorStoreId", () => new HostedVectorStoreContent(null!));
Assert.Throws<ArgumentException>("vectorStoreId", () => new HostedVectorStoreContent(string.Empty));
Assert.Throws<ArgumentException>("vectorStoreId", () => new HostedVectorStoreContent(" "));
}

[Fact]
Expand All @@ -35,9 +35,9 @@ public void Constructor_PropsRoundtrip()
c.VectorStoreId = "id456";
Assert.Equal("id456", c.VectorStoreId);

Assert.Throws<ArgumentNullException>(() => c.VectorStoreId = null!);
Assert.Throws<ArgumentException>(() => c.VectorStoreId = string.Empty);
Assert.Throws<ArgumentException>(() => c.VectorStoreId = " ");
Assert.Throws<ArgumentNullException>("value", () => c.VectorStoreId = null!);
Assert.Throws<ArgumentException>("value", () => c.VectorStoreId = string.Empty);
Assert.Throws<ArgumentException>("value", () => c.VectorStoreId = " ");
Assert.Equal("id456", c.VectorStoreId);

Assert.Null(c.RawRepresentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ public static class AIJsonSchemaTransformCacheTests
[Fact]
public static void NullOptions_ThrowsArgumentNullException()
{
Assert.Throws<ArgumentNullException>(() => new AIJsonSchemaTransformCache(transformOptions: null!));
Assert.Throws<ArgumentNullException>("transformOptions", () => new AIJsonSchemaTransformCache(transformOptions: null!));
}

[Fact]
public static void EmptyOptions_ThrowsArgumentException()
{
Assert.Throws<ArgumentException>(() => new AIJsonSchemaTransformCache(transformOptions: new()));
Assert.Throws<ArgumentException>("transformOptions", () => new AIJsonSchemaTransformCache(transformOptions: new()));
}

[Fact]
Expand All @@ -33,14 +33,14 @@ public static void TransformOptions_ReturnsExpectedValue()
public static void NullFunction_ThrowsArgumentNullException()
{
AIJsonSchemaTransformCache cache = new(new() { ConvertBooleanSchemas = true });
Assert.Throws<ArgumentNullException>(() => cache.GetOrCreateTransformedSchema(function: null!));
Assert.Throws<ArgumentNullException>("function", () => cache.GetOrCreateTransformedSchema(function: null!));
}

[Fact]
public static void NullResponseFormat_ThrowsArgumentNullException()
{
AIJsonSchemaTransformCache cache = new(new() { ConvertBooleanSchemas = true });
Assert.Throws<ArgumentNullException>(() => cache.GetOrCreateTransformedSchema(responseFormat: null!));
Assert.Throws<ArgumentNullException>("responseFormat", () => cache.GetOrCreateTransformedSchema(responseFormat: null!));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1074,8 +1074,8 @@ public static void AddAIContentType_NonAIContent_ThrowsArgumentException()
public static void AddAIContentType_BuiltInAIContent_ThrowsArgumentException()
{
JsonSerializerOptions options = new();
Assert.Throws<ArgumentException>(() => options.AddAIContentType<AIContent>("discriminator"));
Assert.Throws<ArgumentException>(() => options.AddAIContentType<TextContent>("discriminator"));
Assert.Throws<ArgumentException>("contentType", () => options.AddAIContentType<AIContent>("discriminator"));
Assert.Throws<ArgumentException>("contentType", () => options.AddAIContentType<TextContent>("discriminator"));
}

[Fact]
Expand Down Expand Up @@ -1398,8 +1398,8 @@ public static void TransformJsonSchema_ValidateWithTestData(ITestData testData)
public static void TransformJsonSchema_InvalidOptions_ThrowsArgumentException()
{
JsonElement schema = JsonDocument.Parse("{}").RootElement;
Assert.Throws<ArgumentNullException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: null!));
Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions: new()));
Assert.Throws<ArgumentNullException>("transformOptions", () => AIJsonUtilities.TransformSchema(schema, transformOptions: null!));
Assert.Throws<ArgumentException>("transformOptions", () => AIJsonUtilities.TransformSchema(schema, transformOptions: new()));
}

[Theory]
Expand All @@ -1412,7 +1412,7 @@ public static void TransformJsonSchema_InvalidInput_ThrowsArgumentException(stri
{
JsonElement schema = JsonDocument.Parse(invalidSchema).RootElement;
AIJsonSchemaTransformOptions transformOptions = new() { ConvertBooleanSchemas = true };
Assert.Throws<ArgumentException>(() => AIJsonUtilities.TransformSchema(schema, transformOptions));
Assert.Throws<ArgumentException>("schema", () => AIJsonUtilities.TransformSchema(schema, transformOptions));
}

private class DerivedAIContent : AIContent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void Constructor_ValuesAndLength()
[Fact]
public void Constructor_ThrowsOnEmpty()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new NGram<int>(Array.Empty<int>()));
Assert.Throws<ArgumentOutOfRangeException>("values", () => new NGram<int>(Array.Empty<int>()));
}

[Fact]
Expand Down Expand Up @@ -61,7 +61,7 @@ public void NGramBuilder_Create_Works()
[Fact]
public void CreateNGrams()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new int[0].CreateNGrams(-1).ToList());
Assert.Throws<ArgumentOutOfRangeException>("n", () => new int[0].CreateNGrams(-1).ToList());

ReadOnlySpan<int> data = [1, 2, 3];

Expand All @@ -81,11 +81,11 @@ public void CreateNGrams()
[Fact]
public void CreateAllNGrams()
{
Assert.Throws<ArgumentOutOfRangeException>(() => new int[0].CreateAllNGrams(-1).ToList());
Assert.Throws<ArgumentOutOfRangeException>("minN", () => new int[0].CreateAllNGrams(-1).ToList());

Assert.Throws<ArgumentOutOfRangeException>(() => new int[0].CreateAllNGrams(0).ToList());
Assert.Throws<ArgumentOutOfRangeException>("minN", () => new int[0].CreateAllNGrams(0).ToList());

Assert.Throws<ArgumentOutOfRangeException>(() => new int[0].CreateAllNGrams(1, 0).ToList());
Assert.Throws<ArgumentOutOfRangeException>("maxN", () => new int[0].CreateAllNGrams(1, 0).ToList());

ReadOnlySpan<int> arr = [1, 2, 3];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class ToolReductionTests
public void EmbeddingToolReductionStrategy_Constructor_ThrowsWhenToolLimitIsLessThanOrEqualToZero()
{
using var gen = new DeterministicTestEmbeddingGenerator();
Assert.Throws<ArgumentOutOfRangeException>(() => new EmbeddingToolReductionStrategy(gen, toolLimit: 0));
Assert.Throws<ArgumentOutOfRangeException>("toolLimit", () => new EmbeddingToolReductionStrategy(gen, toolLimit: 0));
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MessageCountingChatReducerTests
[InlineData(-10)]
public void Constructor_ThrowsOnInvalidTargetCount(int targetCount)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new MessageCountingChatReducer(targetCount));
Assert.Throws<ArgumentOutOfRangeException>(nameof(targetCount), () => new MessageCountingChatReducer(targetCount));
}

[Fact]
Expand Down Expand Up @@ -126,8 +126,8 @@ public async Task ReduceAsync_IgnoresFunctionCallsAndResults()
[
new ChatMessage(ChatRole.User, "What's the weather?"),
new ChatMessage(ChatRole.Assistant, [new FunctionCallContent("call1", "get_weather", new Dictionary<string, object?> { ["location"] = "Seattle" })]),
new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "Sunny, 72°F")]),
new ChatMessage(ChatRole.Assistant, "The weather in Seattle is sunny and 72°F."),
new ChatMessage(ChatRole.Tool, [new FunctionResultContent("call1", "Sunny, 72°F")]),
new ChatMessage(ChatRole.Assistant, "The weather in Seattle is sunny and 72°F."),
new ChatMessage(ChatRole.User, "Thanks!"),
new ChatMessage(ChatRole.Assistant, "You're welcome!"),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SummarizingChatReducerTests
[Fact]
public void Constructor_ThrowsOnNullChatClient()
{
Assert.Throws<ArgumentNullException>(() => new SummarizingChatReducer(null!, targetCount: 5, threshold: 2));
Assert.Throws<ArgumentNullException>("chatClient", () => new SummarizingChatReducer(null!, targetCount: 5, threshold: 2));
}

[Theory]
Expand All @@ -27,7 +27,7 @@ public void Constructor_ThrowsOnNullChatClient()
public void Constructor_ThrowsOnInvalidTargetCount(int targetCount)
{
using var chatClient = new TestChatClient();
Assert.Throws<ArgumentOutOfRangeException>(() => new SummarizingChatReducer(chatClient, targetCount, threshold: 2));
Assert.Throws<ArgumentOutOfRangeException>(nameof(targetCount), () => new SummarizingChatReducer(chatClient, targetCount, threshold: 2));
}

[Theory]
Expand All @@ -36,7 +36,7 @@ public void Constructor_ThrowsOnInvalidTargetCount(int targetCount)
public void Constructor_ThrowsOnInvalidThresholdCount(int thresholdCount)
{
using var chatClient = new TestChatClient();
Assert.Throws<ArgumentOutOfRangeException>(() => new SummarizingChatReducer(chatClient, targetCount: 5, thresholdCount));
Assert.Throws<ArgumentOutOfRangeException>("threshold", () => new SummarizingChatReducer(chatClient, targetCount: 5, thresholdCount));
}

[Fact]
Expand Down
Loading