Adopt TimeProvider instead of DateTime.UtcNow for testable time handling

Đang mở
#1,601 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
48/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp
Lĩnh vực
backend

Hướng nghiên cứu

Start by searching the codebase for DateTime.UtcNow and DateTimeOffset.UtcNow, then trace each call site and its existing dependency injection and tests. Register TimeProvider.System, inject TimeProvider where time is read, and use FakeTimeProvider in time dependent tests; done when those reads are covered by the provider and relevant behavior can be tested deterministically.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

The codebase reads DateTime.UtcNow / DateTimeOffset.UtcNow directly in several places, which makes time-dependent behavior (expiry, retention, timestamps) hard to test deterministically.

Proposal: register TimeProvider.System in DI, inject TimeProvider where time is read, and use FakeTimeProvider (Microsoft.Extensions.TimeProvider.Testing) in tests.

Surfaced while reviewing #1267 (reading time tracker).

Ngôn ngữ chính
HTML
Star
8
Fork
8
Merge trung bình
3 giờ 24 phút
Pull request đã merge (30 ngày)
91

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của IntelliTect/EssentialCSharp.Web

Tất cả issue của IntelliTect/EssentialCSharp.Web

Issue tương tự

Thêm issue về Backend & API Design

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.