Skip to content
This repository has been archived by the owner on Apr 12, 2023. It is now read-only.

IDateTimeUtility をサービス化 #224

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Covid19Radar/Covid19Radar/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */

Expand Down Expand Up @@ -179,6 +179,9 @@ private static void RegisterCommonTypes(IContainer container)
container.Register<IStorageService, StorageService>(Reuse.Singleton);
#endif
container.Register<ISecureStorageService, SecureStorageService>(Reuse.Singleton);

// Utilities
container.Register<IDateTimeUtility, DateTimeUtility>(Reuse.Singleton);
}

protected override void OnStart()
Expand Down
16 changes: 8 additions & 8 deletions Covid19Radar/Covid19Radar/Common/DateTimeUtility.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using System;
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

あれ? ライセンス表記ありませんね。
ありがとうございます:+1:

やっぱり自動でライセンスを付けたりチェックしたりする仕組みが欲しいですね……

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ブランチ tools/header にて自動的にライセンス通知を追加してくれるツールを作りました。(#80)


using System;

namespace Covid19Radar.Common
{
public interface IDateTimeUtility
{
DateTime UtcNow { get; }
public DateTime UtcNow { get; }
}

public class DateTimeUtility : IDateTimeUtility
{
public static IDateTimeUtility Instance = new DateTimeUtility();

public DateTimeUtility()
{
}

public DateTime UtcNow => DateTime.UtcNow;
}
}
12 changes: 10 additions & 2 deletions Covid19Radar/Covid19Radar/Services/ExposureNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,25 @@ public class ExposureNotificationService : IExposureNotificationService
private readonly ISecureStorageService secureStorageService;
private readonly IPreferencesService preferencesService;
private readonly IApplicationPropertyService applicationPropertyService;
private readonly IDateTimeUtility dateTimeUtility;

public string CurrentStatusMessage { get; set; } = "初期状態";
public Status ExposureNotificationStatus { get; set; }

public ExposureNotificationService(ILoggerService loggerService, IHttpClientService httpClientService, ISecureStorageService secureStorageService, IPreferencesService preferencesService, IApplicationPropertyService applicationPropertyService)
public ExposureNotificationService(
ILoggerService loggerService,
IHttpClientService httpClientService,
ISecureStorageService secureStorageService,
IPreferencesService preferencesService,
IApplicationPropertyService applicationPropertyService,
IDateTimeUtility dateTimeUtility)
{
this.loggerService = loggerService;
this.httpClientService = httpClientService;
this.secureStorageService = secureStorageService;
this.preferencesService = preferencesService;
this.applicationPropertyService = applicationPropertyService;
this.dateTimeUtility = dateTimeUtility;

_ = GetExposureNotificationConfig();
}
Expand Down Expand Up @@ -246,7 +254,7 @@ public List<UserExposureInfo> GetExposureInformationListToDisplay()
{
loggerService.StartMethod();
var list = GetExposureInformationList()?
.Where(x => x.Timestamp.CompareTo(DateTimeUtility.Instance.UtcNow.AddDays(AppConstants.DaysOfExposureInformationToDisplay)) >= 0)
.Where(x => x.Timestamp.CompareTo(dateTimeUtility.UtcNow.AddDays(AppConstants.DaysOfExposureInformationToDisplay)) >= 0)
.ToList();
loggerService.EndMethod();
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public ExposureNotificationServiceTests()
mockPreferencesService = mockRepository.Create<IPreferencesService>();
mockApplicationPropertyService = mockRepository.Create<IApplicationPropertyService>();
mockDateTimeUtility = mockRepository.Create<IDateTimeUtility>();
DateTimeUtility.Instance = mockDateTimeUtility.Object;
}

private ExposureNotificationService CreateService()
Expand All @@ -48,7 +47,8 @@ private ExposureNotificationService CreateService()
mockHttpClientService.Object,
mockSecureStorageService.Object,
mockPreferencesService.Object,
mockApplicationPropertyService.Object);
mockApplicationPropertyService.Object,
mockDateTimeUtility.Object);
}

[Theory]
Expand Down