Skip to content

Commit bb71af2

Browse files
authored
Merge pull request #47 from NavneetHegde/release/3.2
Release/3.2
2 parents d9b8137 + 36694ba commit bb71af2

32 files changed

+2273
-351
lines changed

.github/workflows/nuget-publish.yml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,46 @@ on:
88
- 'v*'
99

1010
jobs:
11-
build-and-publish:
12-
runs-on: ubuntu-latest
11+
build-and-test:
12+
runs-on: ubuntu-22.04 # or ubuntu-latest if using include-runtime
1313
permissions:
1414
id-token: write # enable GitHub OIDC token issuance for this job
15+
strategy:
16+
matrix:
17+
dotnet-version: [8.x, 9.x] # test all supported versions
1518
steps:
1619
- name: Checkout code
1720
uses: actions/checkout@v4
1821

19-
- name: Setup .NET
22+
- name: Setup .NET SDK and runtime
2023
uses: actions/setup-dotnet@v4
2124
with:
22-
dotnet-version: '9.0.x'
25+
dotnet-version: ${{ matrix.dotnet-version }}
2326

2427
- name: Restore dependencies
2528
run: dotnet restore
2629

2730
- name: Build
2831
run: dotnet build --configuration Release --no-restore
2932

30-
- name: Test
31-
run: dotnet test --configuration Release --no-build --verbosity normal
33+
- name: Run Tests
34+
run: dotnet test --configuration Release --no-build --verbosity normal -maxcpucount:1
3235

3336
- name: Pack
37+
if: matrix.dotnet-version == '9.x'
3438
run: dotnet pack --configuration Release --no-build --output ./nupkg
3539

3640
- name: Nuget Login (OIDC + temp API Key)
41+
if: matrix.dotnet-version == '9.x'
3742
uses: Nuget/login@v1
3843
id: login
3944
with:
4045
user: ${{secrets.NUGET_USER}}
4146

4247
- name: Nuget push
48+
if: matrix.dotnet-version == '9.x'
4349
run: dotnet nuget push nupkg/*.nupkg --api-key ${{steps.login.outputs.NUGET_API_KEY}} --source https://api.nuget.org/v3/index.json
4450

45-
51+
- name: Done
52+
run: echo "Package published successfully!"
4653

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Xunit;
2+
3+
namespace OpenCode.Tests;
4+
5+
public class BoolExtensionTests
6+
{
7+
[Theory]
8+
[InlineData(true, "Yes")]
9+
[InlineData(false, "No")]
10+
public void ToYesNo_ReturnsExpectedString(bool input, string expected)
11+
{
12+
var result = input.ToYesNo();
13+
Assert.Equal(expected, result);
14+
}
15+
16+
[Theory]
17+
[InlineData(true, "True")]
18+
[InlineData(false, "False")]
19+
public void ToTitleCase_ReturnsExpectedString(bool input, string expected)
20+
{
21+
var result = input.ToTitleCase();
22+
Assert.Equal(expected, result);
23+
}
24+
25+
[Theory]
26+
[InlineData(true, 1)]
27+
[InlineData(false, 0)]
28+
public void ToInt_ReturnsExpectedInteger(bool input, int expected)
29+
{
30+
var result = input.ToInt();
31+
Assert.Equal(expected, result);
32+
}
33+
34+
[Theory]
35+
[InlineData(true, "true")]
36+
[InlineData(false, "false")]
37+
public void ToLowerString_ReturnsExpectedString(bool input, string expected)
38+
{
39+
var result = input.ToLowerString();
40+
Assert.Equal(expected, result);
41+
}
42+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace OpenCode.Tests;
5+
6+
public class DateTimeExtensionTests
7+
{
8+
[Theory]
9+
[InlineData("2025-10-21 15:30:00", "yyyy-MM-dd HH:mm:ss", "2025-10-21 15:30:00")]
10+
[InlineData("2025-10-21 15:30:00", "MM/dd/yyyy", "10/21/2025")]
11+
public void ToFormat_ReturnsExpectedString(string dateStr, string format, string expected)
12+
{
13+
var date = DateTime.Parse(dateStr);
14+
var result = date.ToFormat(format);
15+
Assert.Equal(expected, result);
16+
}
17+
18+
[Theory]
19+
[InlineData(DayOfWeek.Monday, false)]
20+
[InlineData(DayOfWeek.Tuesday, false)]
21+
[InlineData(DayOfWeek.Wednesday, false)]
22+
[InlineData(DayOfWeek.Thursday, false)]
23+
[InlineData(DayOfWeek.Friday, false)]
24+
[InlineData(DayOfWeek.Saturday, true)]
25+
[InlineData(DayOfWeek.Sunday, true)]
26+
public void IsWeekend_ReturnsCorrectResult(DayOfWeek dayOfWeek, bool expected)
27+
{
28+
var date = new DateTime(2025, 10, 20).AddDays((int)dayOfWeek - (int)DayOfWeek.Monday);
29+
var result = date.IsWeekend();
30+
Assert.Equal(expected, result);
31+
}
32+
33+
[Fact]
34+
public void IsToday_ReturnsTrueForToday()
35+
{
36+
var today = DateTime.Today.AddHours(10);
37+
Assert.True(today.IsToday());
38+
}
39+
40+
[Fact]
41+
public void IsToday_ReturnsFalseForOtherDate()
42+
{
43+
var yesterday = DateTime.Today.AddDays(-1);
44+
Assert.False(yesterday.IsToday());
45+
}
46+
47+
[Fact]
48+
public void StartOfDay_ReturnsMidnight()
49+
{
50+
var date = new DateTime(2025, 10, 21, 15, 30, 45);
51+
var start = date.StartOfDay();
52+
Assert.Equal(new DateTime(2025, 10, 21, 0, 0, 0), start);
53+
}
54+
55+
[Fact]
56+
public void EndOfDay_ReturnsEndOfDay()
57+
{
58+
var date = new DateTime(2025, 10, 21, 15, 30, 45);
59+
var end = date.EndOfDay();
60+
Assert.Equal(new DateTime(2025, 10, 21, 23, 59, 59, 999), end);
61+
}
62+
63+
[Theory]
64+
[InlineData("2000-10-21", 25)] // assuming test is run in 2025
65+
[InlineData("2020-10-21", 5)]
66+
[InlineData("2025-10-21", 0)]
67+
public void ToAge_ReturnsExpectedAge(string birthDateStr, int expectedAge)
68+
{
69+
var birthDate = DateTime.Parse(birthDateStr);
70+
var result = birthDate.ToAge();
71+
Assert.Equal(expectedAge, result);
72+
}
73+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System.Globalization;
2+
using Xunit;
3+
4+
namespace OpenCode.Tests;
5+
6+
public class DecimalExtensionTests
7+
{
8+
[Theory]
9+
[InlineData(12.3456, 2, 12.35)]
10+
[InlineData(12.344, 2, 12.34)]
11+
[InlineData(-12.345, 1, -12.3)]
12+
public void RoundTo_ReturnsExpectedDecimal(decimal value, int decimals, decimal expected)
13+
{
14+
var result = value.RoundTo(decimals);
15+
Assert.Equal(expected, result);
16+
}
17+
18+
[Theory]
19+
[InlineData(12345.678, "N2", "12,345.68")]
20+
[InlineData(12345.678, "N0", "12,346")]
21+
[InlineData(12345.678, "C", "$12,345.68")] // using InvariantCulture will prefix with "¤"
22+
public void ToMoneyFormat_ReturnsExpectedString(decimal value, string format, string expected)
23+
{
24+
var result = value.ToMoneyFormat(format, CultureInfo.GetCultureInfo("en-US"));
25+
Assert.Equal(expected, result);
26+
}
27+
28+
[Theory]
29+
[InlineData(1.0000, 1.00005, true)]
30+
[InlineData(1.0000, 1.0002, false)]
31+
[InlineData(-1.0000, -1.00009, true)]
32+
public void AlmostEquals_ReturnsExpectedResult(decimal a, decimal b, bool expected)
33+
{
34+
var result = a.AlmostEquals(b);
35+
Assert.Equal(expected, result);
36+
}
37+
38+
[Theory]
39+
[InlineData(0.25, 0, "25%")]
40+
[InlineData(0.2567, 1, "25.7%")]
41+
[InlineData(1, 0, "100%")]
42+
public void ToPercentage_ReturnsExpectedString(decimal value, int decimals, string expected)
43+
{
44+
var result = value.ToPercentage(decimals);
45+
Assert.Equal(expected, result);
46+
}
47+
48+
[Theory]
49+
[InlineData(12.34, "en-US", "$12.34")]
50+
[InlineData(12.34, "fr-FR", "12,34 €")]
51+
[InlineData(12.34, "ja-JP", "¥12")]
52+
public void ToCurrency_ReturnsExpectedString(decimal value, string cultureName, string expected)
53+
{
54+
var culture = CultureInfo.GetCultureInfo(cultureName);
55+
var result = value.ToCurrency(culture);
56+
Assert.Equal(expected, result);
57+
}
58+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System;
2+
using Xunit;
3+
4+
namespace OpenCode.Tests;
5+
6+
public class GuidExtensionTests
7+
{
8+
[Fact]
9+
public void IsNotEmpty_ReturnsTrueForNonEmptyGuid()
10+
{
11+
var guid = Guid.NewGuid();
12+
Assert.True(guid.IsNotEmpty());
13+
}
14+
15+
[Fact]
16+
public void IsNotEmpty_ReturnsFalseForEmptyGuid()
17+
{
18+
var guid = Guid.Empty;
19+
Assert.False(guid.IsNotEmpty());
20+
}
21+
22+
[Fact]
23+
public void IsEmpty_ReturnsTrueForEmptyGuid()
24+
{
25+
var guid = Guid.Empty;
26+
Assert.True(guid.IsEmpty());
27+
}
28+
29+
[Fact]
30+
public void IsEmpty_ReturnsFalseForNonEmptyGuid()
31+
{
32+
var guid = Guid.NewGuid();
33+
Assert.False(guid.IsEmpty());
34+
}
35+
36+
[Fact]
37+
public void ToCompactString_RemovesHyphens()
38+
{
39+
var guid = Guid.Parse("12345678-1234-1234-1234-1234567890ab");
40+
var result = guid.ToCompactString();
41+
Assert.Equal("123456781234123412341234567890ab", result);
42+
}
43+
44+
[Fact]
45+
public void ToShortGuid_Returns22CharacterString()
46+
{
47+
var guid = Guid.NewGuid();
48+
var result = guid.ToShortGuid();
49+
50+
Assert.Equal(22, result.Length);
51+
// Ensure no '/' or '+' characters
52+
Assert.DoesNotContain("/", result);
53+
Assert.DoesNotContain("+", result);
54+
}
55+
56+
[Fact]
57+
public void ToShortGuid_UniqueForDifferentGuids()
58+
{
59+
var guid1 = Guid.NewGuid();
60+
var guid2 = Guid.NewGuid();
61+
62+
var short1 = guid1.ToShortGuid();
63+
var short2 = guid2.ToShortGuid();
64+
65+
Assert.NotEqual(short1, short2);
66+
}
67+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Xunit;
2+
3+
namespace OpenCode.Tests;
4+
5+
public class IntegerExtensionTests
6+
{
7+
[Theory]
8+
[InlineData(2, true)]
9+
[InlineData(4, true)]
10+
[InlineData(1, false)]
11+
[InlineData(-2, true)]
12+
[InlineData(-3, false)]
13+
public void IsEven_ReturnsExpectedResult(int value, bool expected)
14+
{
15+
Assert.Equal(expected, value.IsEven());
16+
}
17+
18+
[Theory]
19+
[InlineData(1, true)]
20+
[InlineData(3, true)]
21+
[InlineData(2, false)]
22+
[InlineData(-1, true)]
23+
[InlineData(-4, false)]
24+
public void IsOdd_ReturnsExpectedResult(int value, bool expected)
25+
{
26+
Assert.Equal(expected, value.IsOdd());
27+
}
28+
29+
[Theory]
30+
[InlineData(1, "1st")]
31+
[InlineData(2, "2nd")]
32+
[InlineData(3, "3rd")]
33+
[InlineData(4, "4th")]
34+
[InlineData(11, "11th")]
35+
[InlineData(12, "12th")]
36+
[InlineData(13, "13th")]
37+
[InlineData(21, "21st")]
38+
[InlineData(22, "22nd")]
39+
[InlineData(23, "23rd")]
40+
[InlineData(101, "101st")]
41+
public void ToOrdinal_ReturnsExpectedString(int number, string expected)
42+
{
43+
Assert.Equal(expected, number.ToOrdinal());
44+
}
45+
46+
[Theory]
47+
[InlineData(5, 1, 10, 5)]
48+
[InlineData(0, 1, 10, 1)]
49+
[InlineData(15, 1, 10, 10)]
50+
[InlineData(-5, -10, 0, -5)]
51+
[InlineData(-15, -10, 0, -10)]
52+
public void Clamp_ReturnsValueWithinRange(int value, int min, int max, int expected)
53+
{
54+
Assert.Equal(expected, value.Clamp(min, max));
55+
}
56+
57+
[Theory]
58+
[InlineData(5, 5)]
59+
[InlineData(-5, 5)]
60+
[InlineData(0, 0)]
61+
[InlineData(-123, 123)]
62+
public void Abs_ReturnsAbsoluteValue(int value, int expected)
63+
{
64+
Assert.Equal(expected, value.Abs());
65+
}
66+
}

OpenCode.Tests/OpenCode.Tests.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>NET9.0</TargetFramework>
5-
<IsPackable>false</IsPackable>
6-
</PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<IsPackable>false</IsPackable>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
78

89
<ItemGroup>
910
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />

0 commit comments

Comments
 (0)