Files
Anatolii Grynchuk 85b362e8cd chore: add hrynco common library solution
- add the standalone HrynCo.Common solution and projects
- include the shared common library source and tests
- add package metadata and a repo gitignore
2026-05-01 00:17:34 +03:00

45 lines
1.4 KiB
C#

namespace HrynCo.Common.Tests;
using HrynCo.Common;
using FluentAssertions;
using Xunit;
public sealed class ClockTests
{
[Fact]
public void Clock_ShouldExposeUtcAndLocalTimeCloseToConstructionTime()
{
DateTimeOffset initialUtcNow = new(2026, 04, 30, 12, 0, 0, TimeSpan.Zero);
var clock = new Clock(initialUtcNow);
clock.UtcNow.Should().BeCloseTo(initialUtcNow, TimeSpan.FromSeconds(1));
clock.Now.Should().BeCloseTo(initialUtcNow.ToLocalTime(), TimeSpan.FromSeconds(1));
}
[Fact]
public void GetNextDayOfWeek_ShouldReturnNextMatchingDay()
{
var clock = new Clock(new DateTimeOffset(2026, 04, 30, 12, 0, 0, TimeSpan.Zero));
clock.GetNextDayOfWeek(DayOfWeek.Friday).Should().Be(new DateOnly(2026, 5, 1));
clock.GetNextDayOfWeek(DayOfWeek.Thursday).Should().Be(new DateOnly(2026, 5, 7));
}
[Fact]
public void GetLastDayOfMonth_ShouldReturnMonthEnd()
{
var clock = new Clock(new DateTimeOffset(2026, 02, 10, 8, 0, 0, TimeSpan.Zero));
clock.GetLastDayOfMonth().Should().Be(new DateOnly(2026, 2, 28));
}
[Fact]
public void GetNextMonthStart_ShouldReturnFirstDayOfNextMonth()
{
var clock = new Clock(new DateTimeOffset(2026, 12, 15, 8, 0, 0, TimeSpan.Zero));
clock.GetNextMonthStart().Should().Be(new DateOnly(2027, 1, 1));
}
}