Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overwrite previous key if RegisterKey is called twice #565

Merged
merged 1 commit into from
Jan 7, 2025
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 @@ -42,5 +42,5 @@ public IEqualityComparer<string> KeyComparer
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="key"></param>
public void RegisterKey<T>(string key) => KnownKeys.Add(key, typeof(T));
public void RegisterKey<T>(string key) => KnownKeys[key] = typeof(T);
}
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,37 @@ public void ChangeSessionKeysComparer()
Assert.True(result2);
}

[Fact]
public void RegisterKey()
{
// Arrange
var options = new JsonSessionSerializerOptions();

// Act
options.RegisterKey<int>("key");

// Assert
var item = Assert.Single(options.KnownKeys);
Assert.Equal(typeof(int), item.Value);
Assert.Equal("key", item.Key);
}

[Fact]
public void RegisterKeySameName()
{
// Arrange
var options = new JsonSessionSerializerOptions();

// Act
options.RegisterKey<int>("key");
options.RegisterKey<int>("key");

// Assert
var item = Assert.Single(options.KnownKeys);
Assert.Equal(typeof(int), item.Value);
Assert.Equal("key", item.Key);
}

private sealed class Type1
{
}
Expand Down