Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit c249301

Browse files
Correcting functionality that produces an invalid date
If the source usage file is not present the date was equal to the default minimum value
1 parent 79325ff commit c249301

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/GitHub.VisualStudio/Services/UsageService.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ public async Task<UsageData> ReadLocalData()
113113
{
114114
return json != null ?
115115
SimpleJson.DeserializeObject<UsageData>(json) :
116-
new UsageData { Model = new UsageModel() };
116+
new UsageData
117+
{
118+
Model = new UsageModel() ,
119+
LastUpdated = DateTimeOffset.Now.UtcDateTime
120+
};
117121
}
118122
catch(Exception ex)
119123
{

test/UnitTests/GitHub.VisualStudio/Services/MetricsTests.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ public class UsageServiceTests : TestBaseClass
474474
}
475475
}";
476476

477-
private string storeFileName;
477+
private string usageFileName;
478478
private string userFileName;
479479
private string localApplicationDataPath;
480480
private IEnvironment environment;
@@ -496,7 +496,7 @@ public void SetUp()
496496

497497
Directory.CreateDirectory(localApplicationDataPath);
498498

499-
storeFileName = Path.Combine(localApplicationDataPath, "ghfvs.usage");
499+
usageFileName = Path.Combine(localApplicationDataPath, "ghfvs.usage");
500500
userFileName = Path.Combine(localApplicationDataPath, "user.json");
501501

502502
environment = Substitute.For<IEnvironment>();
@@ -509,7 +509,7 @@ public void SetUp()
509509

510510
private void WriteUsageFileContent(string content)
511511
{
512-
File.WriteAllText(storeFileName, content);
512+
File.WriteAllText(usageFileName, content);
513513
}
514514
private void WriteUserFileContent(string content)
515515
{
@@ -524,6 +524,16 @@ public async Task GetUserGuidWorks()
524524
Assert.IsTrue(guid.Equals(UserGuid));
525525
}
526526

527+
[Test]
528+
public async Task ReadLocalDataWorksWhenFileMissing()
529+
{
530+
File.Delete(usageFileName);
531+
532+
var usageService = new UsageService(Substitute.For<IGitHubServiceProvider>(), environment);
533+
var usageData = await usageService.ReadLocalData();
534+
Assert.AreEqual(usageData.LastUpdated.Date, DateTimeOffset.Now.Date);
535+
}
536+
527537
[Test]
528538
public void IsSameDayWorks()
529539
{

0 commit comments

Comments
 (0)