Skip to content
Open
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
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.10.1" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PackageReference Include="coverlet.collector" Version="10.0.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,48 @@
using System.Linq;
using Xunit;

namespace CommaSeparatedStringUnitTest
namespace CommaSeparatedStringUnitTest;

public class CreateCommaSeparatedStringFromListOfStringUnitTest
{
public class CreateCommaSeparatedStringFromListOfStringUnitTest
private readonly List<string> _fruitList =
[
"apple",
"orange",
"pineapple",
"grape",
"coconut"
];

[Fact]
public void GivenStringJoin_WhenListOfStringIsPassed_ThenReturnCommaSeparatedString()
{
Assert.Equal("apple,orange,pineapple,grape,coconut", string.Join(",", _fruitList));
}

[Fact]
public void GivenStringJoin_WhenListOfStringIsPassedAndFiltered_ThenReturnCommaSeparatedStringOfFilteredOutcome()
{
Assert.Equal("apple,pineapple", string.Join(",", _fruitList.Where(fruit => fruit.Contains("apple"))));
}

[Fact]
public void GivenStringJoin_WhenArrayOfStringIsPassedWithIndexSpecified_ThenReturnCommaSeparatedStringOfIndicatedIndexes()
{
Assert.Equal("pineapple,grape,coconut", string.Join(",", _fruitList.ToArray(), 2, 3));
}

[Fact]
public void GivenStringJoin_WhenListOfIntIsPassed_ThenReturnCommaSeparatedString()
{
var numbers = new List<int> { 1, 2, 3 };

Assert.Equal("1,2,3", string.Join(",", numbers));
}

[Fact]
public void GivenStringJoin_WhenCharSeparatorIsUsed_ThenReturnCommaSeparatedString()
{
private readonly List<string> _fruitList = new List<string>()
{
"apple",
"orange",
"pineapple",
"grape",
"coconut"
};

[Fact]
public void GivenStringJoin_WhenListOfStringIsPassed_ThenReturnCommaSeparatedString()
{
Assert.Equal("apple,orange,pineapple,grape,coconut", string.Join(",", _fruitList));
}

[Fact]
public void GivenStringJoin_WhenListOfStringIsPassedAndFiltered_ThenReturnCommaSeparatedStringOfFilteredOutcome()
{
Assert.Equal("apple,pineapple", string.Join(",", _fruitList.Where(fruit => fruit.Contains("apple"))));
}

[Fact]
public void GivenStringJoin_WhenArrayOfStringIsPassedWithIndexSpecified_ThenReturnCommaSeparatedStringOfIndicatedIndexes()
{
Assert.Equal("pineapple,grape,coconut", string.Join(",", _fruitList.ToArray(), 2, 3));
}
Assert.Equal("apple,orange,pineapple,grape,coconut", string.Join(',', _fruitList));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// See https://aka.ms/new-console-template for more information

var fruitList = new List<string>
{
"apple",
Expand All @@ -15,8 +13,17 @@

var trimmedFruits = string.Join(",", fruitList.ToArray(), 2, 3);

var numbers = new List<int> { 1, 2, 3 };
var numberList = string.Join(",", numbers);

var fruitsWithCharSeparator = string.Join(',', fruitList);

Console.WriteLine($"Fruits: {fruits}");

Console.WriteLine($"Filtered Fruit: {filterFruit}");

Console.WriteLine($"Trimmed Fruits: {trimmedFruits}");
Console.WriteLine($"Trimmed Fruits: {trimmedFruits}");

Console.WriteLine($"Numbers: {numberList}");

Console.WriteLine($"Fruits With Char Separator: {fruitsWithCharSeparator}");
Loading