Skip to content

Commit

Permalink
.Net: Unit test for KernelJsonSchemaBuilder (#8989)
Browse files Browse the repository at this point in the history
Make sure the `KernelJsonSchemaBuilder` can build schemas for types
having public properties of `object` or/and `KernelJsonSchema` types
that have default values in the constructor. This test verifies that the
fix #8988 works and
prevents future regressions of this scenario.
  • Loading branch information
SergeyMenshykh authored Sep 25, 2024
1 parent 3d0a890 commit dec9126
Showing 1 changed file with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright (c) Microsoft. All rights reserved.

using Microsoft.SemanticKernel;
using Xunit;

namespace SemanticKernel.UnitTests.Utilities;

public class KernelJsonSchemaBuilderTests
{
[Fact]
public void ItShouldBuildJsonSchemaForTypesWithPublicMembersHavingTypesThatCanRepresentOtherTypesWithDefaultValuesInTheConstructor()
{
// Arrange & Act
var schema = KernelJsonSchemaBuilder.Build(null, typeof(ClassWithDefaultValuesInConstructorForTypesThatCanRepresentOtherTypes));

// Assert
Assert.NotNull(schema?.RootElement);
}

#pragma warning disable CA1812 // Instantiated by reflection
private sealed class ClassWithDefaultValuesInConstructorForTypesThatCanRepresentOtherTypes
{
public ClassWithDefaultValuesInConstructorForTypesThatCanRepresentOtherTypes(object? content = null, KernelJsonSchema? schema = null)
{
this.Content = content;
this.Schema = schema;
}

public object? Content { get; set; }

public KernelJsonSchema? Schema { get; set; }
}
#pragma warning restore CA1812 // Instantiated by reflection
}

0 comments on commit dec9126

Please sign in to comment.