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

Replace home grown logic of ToSpaceSeparatedString with String.Join #734

Merged
merged 2 commits into from
Feb 21, 2022
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
9 changes: 1 addition & 8 deletions src/EntityFramework.Storage/Extensions/StringsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ public static string ToSpaceSeparatedString(this IEnumerable<string> list)
return string.Empty;
}

var sb = new StringBuilder(100);

foreach (var element in list)
{
sb.Append(element + " ");
}

return sb.ToString().Trim();
return String.Join(' ', list);
}

[DebuggerStepThrough]
Expand Down
10 changes: 1 addition & 9 deletions src/IdentityServer/Extensions/StringsExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace Duende.IdentityServer.Extensions;

internal static class StringExtensions
{
// todo: use string.Join instead!
[DebuggerStepThrough]
public static string ToSpaceSeparatedString(this IEnumerable<string> list)
{
Expand All @@ -24,14 +23,7 @@ public static string ToSpaceSeparatedString(this IEnumerable<string> list)
return string.Empty;
}

var sb = new StringBuilder(100);

foreach (var element in list)
{
sb.Append(element + " ");
}

return sb.ToString().Trim();
return String.Join(' ', list);
}

[DebuggerStepThrough]
Expand Down
35 changes: 35 additions & 0 deletions test/IdentityServer.UnitTests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Xunit;
using Duende.IdentityServer.Extensions;
using FluentAssertions;
using System.Linq;

namespace UnitTests.Extensions;

Expand Down Expand Up @@ -76,6 +77,40 @@ public void TestGetOrigin()
CheckOrigin("test://localhost:8080/test/resource", "test://localhost:8080");
}

[Fact]
[Trait("Category", Category)]
public void ToSpaceSeparatedString_should_return_correct_value()
{
var value = new[] { "foo", "bar", "baz", "baz", "foo", "bar" }.ToSpaceSeparatedString();
value.Should().Be("foo bar baz baz foo bar");
}

[Fact]
[Trait("Category", Category)]
public void FromSpaceSeparatedString_should_return_correct_values()
{
var values = "foo bar baz baz foo bar".FromSpaceSeparatedString().ToArray();
values.Length.Should().Be(6);
values[0].Should().Be("foo");
values[1].Should().Be("bar");
values[2].Should().Be("baz");
values[3].Should().Be("baz");
values[4].Should().Be("foo");
values[5].Should().Be("bar");
}

[Fact]
[Trait("Category", Category)]
public void FromSpaceSeparatedString_should_only_process_spaces()
{
var values = "foo bar\tbaz baz\rfoo bar\r\nbar".FromSpaceSeparatedString().ToArray();
values.Length.Should().Be(4);
values[0].Should().Be("foo");
values[1].Should().Be("bar\tbaz");
values[2].Should().Be("baz\rfoo");
values[3].Should().Be("bar\r\nbar");
}


// scope parsing

Expand Down