Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit d7198ba

Browse files
committed
Add metrics tests and move some code around so it's simpler to mock
1 parent bf89a53 commit d7198ba

File tree

15 files changed

+242
-216
lines changed

15 files changed

+242
-216
lines changed

script

src/GitHub.Api/Application/ApplicationManagerBase.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public ITask InitializeRepository()
168168
})
169169
.ThenInUI(() =>
170170
{
171-
TaskManager.Run(UsageTracker.ProjectsInitialized);
171+
TaskManager.Run(UsageTracker.IncrementProjectsInitialized);
172172
InitializeUI();
173173
});
174174
return task;
@@ -191,8 +191,6 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
191191
{
192192
//Logger.Trace("Setup metrics");
193193

194-
var usagePath = Environment.UserCachePath.Combine(Constants.UsageFile);
195-
196194
string userId = null;
197195
if (UserSettings.Exists(Constants.GuidKey))
198196
{
@@ -212,7 +210,7 @@ protected void SetupMetrics(string unityVersion, bool firstRun, Guid instanceId)
212210
Environment.NodeJsExecutablePath,
213211
Environment.OctorunScriptPath);
214212

215-
UsageTracker = new UsageTracker(metricsService, UserSettings, usagePath, userId, unityVersion, instanceId.ToString());
213+
UsageTracker = new UsageTracker(metricsService, UserSettings, Environment, userId, unityVersion, instanceId.ToString());
216214

217215
if (firstRun)
218216
{

src/GitHub.Api/Metrics/IUsageTracker.cs

Lines changed: 13 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,18 @@ public interface IUsageTracker
44
{
55
bool Enabled { get; set; }
66
void IncrementNumberOfStartups();
7-
void ChangesViewButtonCommit();
8-
void HistoryViewToolbarButtonFetch();
9-
void HistoryViewToolbarButtonPush();
10-
void HistoryViewToolbarButtonPull();
11-
void AuthenticationViewButtonAuthentication();
12-
void ProjectsInitialized();
13-
void BranchesViewButtonCreateBranch();
14-
void BranchesViewButtonDeleteBranch();
15-
void BranchesViewButtonCheckoutLocalBranch();
16-
void BranchesViewButtonCheckoutRemoteBranch();
17-
void SettingsViewUnlockButtonLfsUnlock();
18-
void AssetExplorerContextMenuLfsLock();
19-
void AssetExplorerContextMenuLfsUnlock();
20-
}
21-
22-
class NullUsageTracker : IUsageTracker
23-
{
24-
public bool Enabled { get; set; }
25-
public void IncrementNumberOfStartups() { }
26-
public void ChangesViewButtonCommit() { }
27-
public void HistoryViewToolbarButtonFetch() { }
28-
public void HistoryViewToolbarButtonPush() { }
29-
public void HistoryViewToolbarButtonPull() { }
30-
public void AuthenticationViewButtonAuthentication() { }
31-
public void ProjectsInitialized() { }
32-
public void BranchesViewButtonCreateBranch() { }
33-
public void BranchesViewButtonDeleteBranch() { }
34-
public void BranchesViewButtonCheckoutLocalBranch() { }
35-
public void BranchesViewButtonCheckoutRemoteBranch() { }
36-
public void SettingsViewUnlockButtonLfsUnlock() { }
37-
38-
public void AssetExplorerContextMenuLfsLock() { }
39-
40-
public void AssetExplorerContextMenuLfsUnlock() { }
41-
42-
public void SetMetricsService(IMetricsService instance) { }
7+
void IncrementChangesViewButtonCommit();
8+
void IncrementHistoryViewToolbarButtonFetch();
9+
void IncrementHistoryViewToolbarButtonPush();
10+
void IncrementHistoryViewToolbarButtonPull();
11+
void IncrementAuthenticationViewButtonAuthentication();
12+
void IncrementProjectsInitialized();
13+
void IncrementBranchesViewButtonCreateBranch();
14+
void IncrementBranchesViewButtonDeleteBranch();
15+
void IncrementBranchesViewButtonCheckoutLocalBranch();
16+
void IncrementBranchesViewButtonCheckoutRemoteBranch();
17+
void IncrementSettingsViewUnlockButtonLfsUnlock();
18+
void IncrementAssetExplorerContextMenuLfsLock();
19+
void IncrementAssetExplorerContextMenuLfsUnlock();
4320
}
4421
}

src/GitHub.Api/Metrics/UsageModel.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System;
1+
using GitHub.Logging;
2+
using System;
23
using System.Collections.Generic;
34
using System.Globalization;
45
using System.Linq;
6+
using System.Text;
57

68
namespace GitHub.Unity
79
{
@@ -94,5 +96,10 @@ class UsageStore
9496
{
9597
public DateTimeOffset LastUpdated { get; set; } = DateTimeOffset.UtcNow;
9698
public UsageModel Model { get; set; } = new UsageModel();
99+
100+
public Measures GetCurrentMeasures(string appVersion, string unityVersion, string instanceId)
101+
{
102+
return Model.GetCurrentUsage(appVersion, unityVersion, instanceId).Measures;
103+
}
97104
}
98105
}

0 commit comments

Comments
 (0)