Skip to content

Commit

Permalink
Merge pull request #23 from shahabfar/Development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
shahabfar authored Nov 26, 2024
2 parents cde2a72 + 34869a1 commit b174723
Show file tree
Hide file tree
Showing 21 changed files with 666 additions and 500 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,34 @@
name: Publish to NuGet

on:
push:
branches: [ "master" ]
tags:
- '*'
release:
types: [published]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Check out repository
uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'
dotnet-version: |
6.0.x
7.0.x
8.0.x
9.0.x
- name: Restore dependencies
run: dotnet restore
run: dotnet restore src/Persia.Net/Persia.Net.csproj

- name: Build
run: dotnet build --configuration Release --no-restore
run: dotnet build src/Persia.Net/Persia.Net.csproj --configuration Release --no-restore

- name: Restore test project dependencies
run: dotnet restore tests/Persia.Net.Test/Persia.Net.Test.csproj

- name: Test
run: dotnet test --no-restore --verbosity normal
Expand All @@ -36,8 +44,8 @@ jobs:
echo "::set-output name=version::$VERSION"
- name: Pack
run: dotnet pack --no-build --configuration Release /p:PackageVersion=${{ steps.version.outputs.version }} --output out
run: dotnet pack src/Persia.Net/Persia.Net.csproj --no-build --configuration Release /p:PackageVersion=${{ steps.version.outputs.version }} --output nupkg

- name: Push
run: dotnet nuget push "out/*.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json
run: dotnet nuget push "nupkg/*.nupkg" --skip-duplicate --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json

12 changes: 6 additions & 6 deletions src/Persia.Net.Test/IslamicDateTimeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ public void Parse_ValidDate_ReturnsCorrectIslamicDateTime()

Assert.Throws<FormatException>(() => IslamicDateTime.Parse("invalid date"));
Assert.True(success);
Assert.Equal(1445, result.Year);
Assert.Equal(09, result.Month);
Assert.Equal(17, result.Day);
Assert.Equal(1445, result?.Year);
Assert.Equal(09, result?.Month);
Assert.Equal(17, result?.Day);
Assert.False(failure);
Assert.Null(result2);
}
Expand All @@ -115,14 +115,14 @@ public void Parse_ValidDate_ReturnsCorrectIslamicDateTime()
public void Test_ConvertIslamicToPersianDate_ReturnCorrectDate()
{
// Arrange
var dtIslamic = new IslamicDateTime(1445, 09, 18);
var dtIslamic = new IslamicDateTime(1446, 05, 23);

// Act
var convertedDate = dtIslamic.ToPersianDateOnly();

// Assert
Assert.Equal(09, convertedDate.Day);
Assert.Equal(01, convertedDate.Month);
Assert.Equal(05, convertedDate.Day);
Assert.Equal(09, convertedDate.Month);
Assert.Equal(1403, convertedDate.Year);
}
}
46 changes: 26 additions & 20 deletions src/Persia.Net.Test/Persia.Net.Test.csproj
Original file line number Diff line number Diff line change
@@ -1,27 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="coverlet.collector" Version="6.0.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
<PackageReference Include="xunit" Version="2.9.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Persia.Net\Persia.Net.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Persia.Net\Persia.Net.csproj" />
</ItemGroup>

<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
</ItemGroup>

</Project>
73 changes: 20 additions & 53 deletions src/Persia.Net.Test/PersianDateOnlyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,33 @@

public class PersianDateOnlyTests
{
[Fact]
public void Test_ConvertToPersianDate_ReturnCorrectDate()
[Theory]
[InlineData(2025, 03, 21, 1, 1, 1404)]
[InlineData(2025, 03, 20, 30, 12, 1403)]
[InlineData(2025, 03, 19, 29, 12, 1403)]
[InlineData(1977, 02, 08, 19, 11, 1355)]
[InlineData(2000, 01, 01, 11, 10, 1378)]
[InlineData(2010, 05, 15, 25, 2, 1389)]
[InlineData(1995, 12, 31, 10, 10, 1374)]
[InlineData(1980, 07, 20, 29, 4, 1359)]
[InlineData(2022, 09, 23, 1, 7, 1401)]
public void Test_ConvertToPersianDate_ReturnCorrectDate(int year, int month, int day, int expectedDay, int expectedMonth, int expectedYear)
{
// Arrange
DateOnly? nullableDate = new DateOnly(2024, 03, 29);
DateOnly nonNullableDate = new DateOnly(2024, 03, 29);
DateOnly? nullableDate = new DateOnly(year, month, day);
DateOnly nonNullableDate = new DateOnly(year, month, day);

// Act
var convertedNullableDate = nullableDate.ToPersianDateTime();
var convertedNonNullableDate = nonNullableDate.ToPersianDateTime();

// Assert
Assert.Equal(10, convertedNullableDate.Day);
Assert.Equal(1, convertedNullableDate.Month);
Assert.Equal(1403, convertedNullableDate.Year);
Assert.Equal(expectedDay, convertedNullableDate.Day);
Assert.Equal(expectedMonth, convertedNullableDate.Month);
Assert.Equal(expectedYear, convertedNullableDate.Year);

Assert.Equal(10, convertedNonNullableDate.Day);
Assert.Equal(01, convertedNonNullableDate.Month);
Assert.Equal(1403, convertedNonNullableDate.Year);
Assert.Equal(expectedDay, convertedNonNullableDate.Day);
Assert.Equal(expectedMonth, convertedNonNullableDate.Month);
Assert.Equal(expectedYear, convertedNonNullableDate.Year);
}

//[Fact]
//public void Test_HumanizePersianDateTimePassed_ReturnCorrectText()
//{
// // Arrange
// var date = new DateOnly(2022, 03, 25);

// // Act
// //var humanizedPersian = date.HumanizePassedPersianDateTime();
// var humanizedPersian = date.HumanizePassedPersianDateTime(TimeUnit.Days);

// // Assert
// Assert.Equal("‫۱۱ ماه و ۳۶۲ روز و ۲ ساعت پیش‬", humanizedPersian);
//}

[Fact]
public void Test_GetNextCurrentPreviousDayWeekMonth_ReturnCorrectDate()
{
// Arrange
var date = new DateOnly(2024, 03, 19);
DateOnly? nullableDate = new DateOnly(2024, 03, 19);

// Act
var nextDay = nullableDate.NextPersianDay();
var prevDay = date.PreviousPersianDay();
var currentWeek = date.CurrentPersianWeek();
var nextWeek = date.NextPersianWeek();
var previousWeek = date.PreviousPersianWeek();
var currentMonth = date.CurrentPersianMonth();
var nextMonth = date.NextPersianMonth();
var previousMonth = date.PreviousPersianMonth();

// Assert
Assert.Equal(new PersianDateTime(1403, 01, 01), nextDay);
Assert.Equal(new PersianDateTime(1402, 12, 28), prevDay);
Assert.Equal(new PersianDateTime(1403, 01, 01), currentWeek[4]);
Assert.Equal(new PersianDateTime(1403, 01, 04), nextWeek[0]);
Assert.Equal(new PersianDateTime(1402, 12, 25), previousWeek[6]);
Assert.Equal(new PersianDateTime(1402, 12, 26), currentMonth[25]);
Assert.Equal(new PersianDateTime(1403, 01, 03), nextMonth[2]);
Assert.Equal(new PersianDateTime(1402, 11, 30), previousMonth[29]);
}
}
}
Loading

0 comments on commit b174723

Please sign in to comment.