Implement TimeProvider Tests#7
Open
DotNet-Ninja wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implement some basic tests of SystemTimeProvider
Greptile Summary
This PR implements unit tests for the
SystemTimeProviderclass, adding comprehensive test coverage for a previously untested time provider service that implements theITimeProviderinterface. TheSystemTimeProvideris a foundational service in the Garage application that provides current time functionality through itsNowproperty and captures immutable request instantiation time via itsRequestTimeproperty.The changes include three main components:
SystemTimeProviderTests.cswith three critical test scenarios that validate the service's core contracts - ensuringNowreturns current time within expected bounds, verifyingRequestTimeis properly captured at instantiation, and confirmingRequestTimeremains immutable after creationUnitTest1.csas part of proper test project setupThe
SystemTimeProviderservice appears to be used throughout the Garage application for request tracking, logging, and time-based operations. These tests follow standard arrange-act-assert patterns and use modern C# testing practices, ensuring the service maintains its reliability for time-sensitive functionality in the web application.Important Files Changed
Files Modified in this PR
Confidence score: 4/5
Thread.Sleep(100)usage in the immutability test, which could potentially introduce test flakiness in very fast execution environments or CI/CD systemsThread.SleepSequence Diagram
sequenceDiagram participant TestRunner participant SystemTimeProviderTests participant SystemTimeProvider participant DateTimeOffset participant Thread Note over TestRunner, Thread: Test 1: Now_ShouldReturnCurrentTime() TestRunner->>SystemTimeProviderTests: Execute Now_ShouldReturnCurrentTime() SystemTimeProviderTests->>DateTimeOffset: Get before = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProviderTests: before timestamp SystemTimeProviderTests->>SystemTimeProvider: new SystemTimeProvider() SystemTimeProvider->>DateTimeOffset: RequestTime = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProvider: request timestamp SystemTimeProvider-->>SystemTimeProviderTests: timeProvider instance SystemTimeProviderTests->>SystemTimeProvider: timeProvider.Now SystemTimeProvider->>DateTimeOffset: DateTimeOffset.Now DateTimeOffset-->>SystemTimeProvider: current timestamp SystemTimeProvider-->>SystemTimeProviderTests: now timestamp SystemTimeProviderTests->>DateTimeOffset: Get after = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProviderTests: after timestamp SystemTimeProviderTests->>SystemTimeProviderTests: Assert now >= before && now <= after Note over TestRunner, Thread: Test 2: RequestTime_ShouldBeSetAtInstantiation() TestRunner->>SystemTimeProviderTests: Execute RequestTime_ShouldBeSetAtInstantiation() SystemTimeProviderTests->>DateTimeOffset: Get before = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProviderTests: before timestamp SystemTimeProviderTests->>SystemTimeProvider: new SystemTimeProvider() SystemTimeProvider->>DateTimeOffset: RequestTime = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProvider: request timestamp SystemTimeProvider-->>SystemTimeProviderTests: timeProvider instance SystemTimeProviderTests->>DateTimeOffset: Get after = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProviderTests: after timestamp SystemTimeProviderTests->>SystemTimeProvider: timeProvider.RequestTime SystemTimeProvider-->>SystemTimeProviderTests: requestTime SystemTimeProviderTests->>SystemTimeProviderTests: Assert requestTime >= before && requestTime <= after Note over TestRunner, Thread: Test 3: RequestTime_ShouldNotChangeAfterInstantiation() TestRunner->>SystemTimeProviderTests: Execute RequestTime_ShouldNotChangeAfterInstantiation() SystemTimeProviderTests->>SystemTimeProvider: new SystemTimeProvider() SystemTimeProvider->>DateTimeOffset: RequestTime = DateTimeOffset.Now DateTimeOffset-->>SystemTimeProvider: initial timestamp SystemTimeProvider-->>SystemTimeProviderTests: timeProvider instance SystemTimeProviderTests->>SystemTimeProvider: timeProvider.RequestTime SystemTimeProvider-->>SystemTimeProviderTests: initialRequestTime SystemTimeProviderTests->>Thread: Thread.Sleep(100) Thread-->>SystemTimeProviderTests: sleep complete SystemTimeProviderTests->>SystemTimeProvider: timeProvider.RequestTime SystemTimeProvider-->>SystemTimeProviderTests: laterRequestTime SystemTimeProviderTests->>SystemTimeProviderTests: Assert initialRequestTime == laterRequestTime