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 @@ -20,7 +20,11 @@ public class ChatMessageContent : KernelContent
/// </summary>
[Experimental("SKEXP0001")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? AuthorName { get; set; }
public string? AuthorName
{
get => this._authorName;
set => this._authorName = string.IsNullOrWhiteSpace(value) ? null : value;
}

/// <summary>
/// Role of the author of the message
Expand Down Expand Up @@ -171,4 +175,5 @@ public override string ToString()

private ChatMessageContentItemCollection? _items;
private Encoding _encoding;
private string? _authorName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ public StreamingKernelContentItemCollection Items
/// </summary>
[Experimental("SKEXP0001")]
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
public string? AuthorName { get; set; }
public string? AuthorName
{
get => this._authorName;
set => this._authorName = string.IsNullOrWhiteSpace(value) ? null : value;
}

/// <summary>
/// Role of the author of the message
Expand Down Expand Up @@ -126,4 +130,5 @@ public StreamingChatMessageContent(AuthorRole? role, string? content, object? in

private StreamingKernelContentItemCollection? _items;
private Encoding _encoding;
private string? _authorName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,25 @@ public void ContentPropertyGetterShouldReturnContentOfTheFirstTextContentItem()
Assert.Equal("fake-content-1", sut.Content);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
[InlineData("\t")]
[InlineData("\n")]
[InlineData("\r\n")]
public void ContentPropertySetterShouldConvertEmptyOrWhitespaceAuthorNameToNull(string? authorName)
{
// Arrange
var message = new ChatMessageContent(AuthorRole.User, content: null)
{
AuthorName = authorName
};

// Assert
Assert.Null(message.AuthorName);
}

[Fact]
public void ItShouldBePossibleToSetAndGetEncodingEvenIfThereAreNoItems()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,25 @@ public void ContentPropertyGetterShouldReturnContentOfTheFirstTextContentItem()
Assert.Equal("fake-content-1", sut.Content);
}

[Theory]
[InlineData(null)]
[InlineData("")]
[InlineData(" ")]
[InlineData("\t")]
[InlineData("\n")]
[InlineData("\r\n")]
public void ContentPropertySetterShouldConvertEmptyOrWhitespaceAuthorNameToNull(string? authorName)
{
// Arrange
var message = new StreamingChatMessageContent(AuthorRole.User, content: null)
{
AuthorName = authorName
};

// Assert
Assert.Null(message.AuthorName);
}

[Fact]
public void ItShouldBePossibleToSetAndGetEncodingEvenIfThereAreNoItems()
{
Expand Down