зеркало из https://github.com/dotnet/extensions.git
Fix M.E.AI argument tests to validate argument names (#5653)
This commit is contained in:
Родитель
e0f354a386
Коммит
f085689eb2
|
@ -18,7 +18,7 @@ public class EmbeddingGenerationOptions
|
|||
{
|
||||
if (value is not null)
|
||||
{
|
||||
_ = Throw.IfLessThan(value.Value, 1);
|
||||
_ = Throw.IfLessThan(value.Value, 1, nameof(value));
|
||||
}
|
||||
|
||||
_dimensions = value;
|
||||
|
|
|
@ -18,8 +18,8 @@ public class ChatFinishReasonTests
|
|||
[Fact]
|
||||
public void Constructor_NullOrWhiteSpace_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ChatFinishReason(null!));
|
||||
Assert.Throws<ArgumentException>(() => new ChatFinishReason(" "));
|
||||
Assert.Throws<ArgumentNullException>("value", () => new ChatFinishReason(null!));
|
||||
Assert.Throws<ArgumentException>("value", () => new ChatFinishReason(" "));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -19,9 +19,9 @@ public class ChatResponseFormatTests
|
|||
[Fact]
|
||||
public void Constructor_InvalidArgs_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => new ChatResponseFormatJson(null, "name"));
|
||||
Assert.Throws<ArgumentException>(() => new ChatResponseFormatJson(null, null, "description"));
|
||||
Assert.Throws<ArgumentException>(() => new ChatResponseFormatJson(null, "name", "description"));
|
||||
Assert.Throws<ArgumentException>("schemaName", () => new ChatResponseFormatJson(null, "name"));
|
||||
Assert.Throws<ArgumentException>("schemaDescription", () => new ChatResponseFormatJson(null, null, "description"));
|
||||
Assert.Throws<ArgumentException>("schemaName", () => new ChatResponseFormatJson(null, "name", "description"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -18,8 +18,8 @@ public class ChatRoleTests
|
|||
[Fact]
|
||||
public void Constructor_NullOrWhiteSpace_Throws()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ChatRole(null!));
|
||||
Assert.Throws<ArgumentException>(() => new ChatRole(" "));
|
||||
Assert.Throws<ArgumentNullException>("value", () => new ChatRole(null!));
|
||||
Assert.Throws<ArgumentException>("value", () => new ChatRole(" "));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -14,7 +14,7 @@ public class DelegatingChatClientTests
|
|||
[Fact]
|
||||
public void RequiresInnerChatClient()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new NoOpDelegatingChatClient(null!));
|
||||
Assert.Throws<ArgumentNullException>("innerClient", () => new NoOpDelegatingChatClient(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -68,9 +68,9 @@ public abstract class DataContentTests<T>
|
|||
[InlineData("type/subtype;key=")]
|
||||
[InlineData("type/subtype;=value")]
|
||||
[InlineData("type/subtype;key=value;another=")]
|
||||
public void Ctor_InvalidMediaType_Throws(string mediaType)
|
||||
public void Ctor_InvalidMediaType_Throws(string type)
|
||||
{
|
||||
Assert.Throws<ArgumentException>(() => CreateDataContent("http://localhost/test", mediaType));
|
||||
Assert.Throws<ArgumentException>("mediaType", () => CreateDataContent("http://localhost/test", type));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
@ -151,7 +151,7 @@ public abstract class DataContentTests<T>
|
|||
[InlineData("""{ "mediaType":"text/plain" }""")]
|
||||
public void Deserialize_MissingUriString_Throws(string json)
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => JsonSerializer.Deserialize<DataContent>(json, TestJsonSerializerContext.Default.Options)!);
|
||||
Assert.Throws<ArgumentNullException>("uri", () => JsonSerializer.Deserialize<DataContent>(json, TestJsonSerializerContext.Default.Options)!);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -331,9 +331,9 @@ public class FunctionCallContentTests
|
|||
[Fact]
|
||||
public static void CreateFromParsedArguments_NullInput_ThrowsArgumentNullException()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => FunctionCallContent.CreateFromParsedArguments((string)null!, "callId", "functionName", _ => null));
|
||||
Assert.Throws<ArgumentNullException>(() => FunctionCallContent.CreateFromParsedArguments("{}", null!, "functionName", _ => null));
|
||||
Assert.Throws<ArgumentNullException>(() => FunctionCallContent.CreateFromParsedArguments("{}", "callId", null!, _ => null));
|
||||
Assert.Throws<ArgumentNullException>(() => FunctionCallContent.CreateFromParsedArguments("{}", "callId", "functionName", null!));
|
||||
Assert.Throws<ArgumentNullException>("encodedArguments", () => FunctionCallContent.CreateFromParsedArguments((string)null!, "callId", "functionName", _ => null));
|
||||
Assert.Throws<ArgumentNullException>("callId", () => FunctionCallContent.CreateFromParsedArguments("{}", null!, "functionName", _ => null));
|
||||
Assert.Throws<ArgumentNullException>("name", () => FunctionCallContent.CreateFromParsedArguments("{}", "callId", null!, _ => null));
|
||||
Assert.Throws<ArgumentNullException>("argumentParser", () => FunctionCallContent.CreateFromParsedArguments("{}", "callId", "functionName", null!));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,7 +14,7 @@ public class DelegatingEmbeddingGeneratorTests
|
|||
[Fact]
|
||||
public void RequiresInnerService()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new NoOpDelegatingEmbeddingGenerator(null!));
|
||||
Assert.Throws<ArgumentNullException>("innerGenerator", () => new NoOpDelegatingEmbeddingGenerator(null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -27,8 +27,8 @@ public class EmbeddingGenerationOptionsTests
|
|||
public void InvalidArgs_Throws()
|
||||
{
|
||||
EmbeddingGenerationOptions options = new();
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => options.Dimensions = 0);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => options.Dimensions = -1);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => options.Dimensions = 0);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("value", () => options.Dimensions = -1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -46,8 +46,8 @@ public class GeneratedEmbeddingsTests
|
|||
|
||||
instance.CopyTo(Array.Empty<Embedding<float>>(), 0);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => instance[0]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => instance[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => instance[0]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => instance[-1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -77,8 +77,8 @@ public class GeneratedEmbeddingsTests
|
|||
Assert.False(generatedEmbeddings.Contains(null!));
|
||||
Assert.Equal(-1, generatedEmbeddings.IndexOf(null!));
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => generatedEmbeddings[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => generatedEmbeddings[2]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => generatedEmbeddings[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => generatedEmbeddings[2]);
|
||||
|
||||
Assert.True(embeddings.SequenceEqual(generatedEmbeddings));
|
||||
|
||||
|
@ -240,7 +240,7 @@ public class GeneratedEmbeddingsTests
|
|||
embeddings.AddRange(new[] { e1, e2 });
|
||||
Assert.Equal(2, embeddings.Count);
|
||||
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => embeddings[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>(() => embeddings[2]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => embeddings[-1]);
|
||||
Assert.Throws<ArgumentOutOfRangeException>("index", () => embeddings[2]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ public class ChatClientBuilderTest
|
|||
[Fact]
|
||||
public void DoesNotAcceptNullInnerService()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ChatClientBuilder((IChatClient)null!));
|
||||
Assert.Throws<ArgumentNullException>("innerClient", () => new ChatClientBuilder((IChatClient)null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotAcceptNullFactories()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new ChatClientBuilder((Func<IServiceProvider, IChatClient>)null!));
|
||||
Assert.Throws<ArgumentNullException>("innerClientFactory", () => new ChatClientBuilder((Func<IServiceProvider, IChatClient>)null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -57,13 +57,14 @@ public class EmbeddingGeneratorBuilderTests
|
|||
[Fact]
|
||||
public void DoesNotAcceptNullInnerService()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new EmbeddingGeneratorBuilder<string, Embedding<float>>((IEmbeddingGenerator<string, Embedding<float>>)null!));
|
||||
Assert.Throws<ArgumentNullException>("innerGenerator", () => new EmbeddingGeneratorBuilder<string, Embedding<float>>((IEmbeddingGenerator<string, Embedding<float>>)null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DoesNotAcceptNullFactories()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new EmbeddingGeneratorBuilder<string, Embedding<float>>((Func<IServiceProvider, IEmbeddingGenerator<string, Embedding<float>>>)null!));
|
||||
Assert.Throws<ArgumentNullException>("innerGeneratorFactory",
|
||||
() => new EmbeddingGeneratorBuilder<string, Embedding<float>>((Func<IServiceProvider, IEmbeddingGenerator<string, Embedding<float>>>)null!));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -15,11 +15,11 @@ public class AIFunctionFactoryTest
|
|||
[Fact]
|
||||
public void InvalidArguments_Throw()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!));
|
||||
Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!, target: new object()));
|
||||
Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk"));
|
||||
Assert.Throws<ArgumentNullException>(() => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, null));
|
||||
Assert.Throws<ArgumentException>(() => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>()));
|
||||
Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!));
|
||||
Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object()));
|
||||
Assert.Throws<ArgumentNullException>("method", () => AIFunctionFactory.Create(method: null!, target: new object(), name: "myAiFunk"));
|
||||
Assert.Throws<ArgumentNullException>("target", () => AIFunctionFactory.Create(typeof(AIFunctionFactoryTest).GetMethod(nameof(InvalidArguments_Throw))!, null));
|
||||
Assert.Throws<ArgumentException>("method", () => AIFunctionFactory.Create(typeof(List<>).GetMethod("Add")!, new List<int>()));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
Загрузка…
Ссылка в новой задаче