From af55f6a28245af5e47eb61199869b26e93577c52 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Tue, 25 Sep 2018 15:07:02 +0100 Subject: [PATCH] Add tests for NumberOf*Opens counters Expect to fail on this commit. --- src/GitHub.Exports/Models/UsageModel.cs | 2 ++ .../Services/RepositoryCloneServiceTests.cs | 23 ++++++++++++------- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/GitHub.Exports/Models/UsageModel.cs b/src/GitHub.Exports/Models/UsageModel.cs index 153ae29ff..c31d9ecbd 100644 --- a/src/GitHub.Exports/Models/UsageModel.cs +++ b/src/GitHub.Exports/Models/UsageModel.cs @@ -91,6 +91,8 @@ namespace GitHub.Models public int NumberOfCloneViewUrlTab { get; set; } public int NumberOfGitHubClones { get; set; } public int NumberOfEnterpriseClones { get; set; } + public int NumberOfGitHubOpens { get; set; } + public int NumberOfEnterpriseOpens { get; set; } } } } diff --git a/test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs b/test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs index 96dd9fcdf..a06bd79a5 100644 --- a/test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs +++ b/test/GitHub.App.UnitTests/Services/RepositoryCloneServiceTests.cs @@ -51,17 +51,24 @@ public class RepositoryCloneServiceTests ((MemberExpression)x.Body).Member.Name == counterName)); } - [TestCase("https://github.com/foo/bar", 1, nameof(UsageModel.MeasuresModel.NumberOfClones))] - [TestCase("https://github.com/foo/bar", 1, nameof(UsageModel.MeasuresModel.NumberOfGitHubClones))] - [TestCase("https://github.com/foo/bar", 0, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseClones))] - [TestCase("https://enterprise.com/foo/bar", 1, nameof(UsageModel.MeasuresModel.NumberOfClones))] - [TestCase("https://enterprise.com/foo/bar", 1, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseClones))] - [TestCase("https://enterprise.com/foo/bar", 0, nameof(UsageModel.MeasuresModel.NumberOfGitHubClones))] - public async Task UpdatesMetricsWhenCloneOrOpenRepositoryAsync(string cloneUrl, int numberOfCalls, string counterName) + [TestCase("https://github.com/foo/bar", false, 1, nameof(UsageModel.MeasuresModel.NumberOfClones))] + [TestCase("https://github.com/foo/bar", false, 1, nameof(UsageModel.MeasuresModel.NumberOfGitHubClones))] + [TestCase("https://github.com/foo/bar", false, 0, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseClones))] + [TestCase("https://enterprise.com/foo/bar", false, 1, nameof(UsageModel.MeasuresModel.NumberOfClones))] + [TestCase("https://enterprise.com/foo/bar", false, 1, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseClones))] + [TestCase("https://enterprise.com/foo/bar", false, 0, nameof(UsageModel.MeasuresModel.NumberOfGitHubClones))] + + [TestCase("https://github.com/foo/bar", true, 1, nameof(UsageModel.MeasuresModel.NumberOfGitHubOpens))] + [TestCase("https://github.com/foo/bar", true, 0, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseOpens))] + [TestCase("https://enterprise.com/foo/bar", true, 1, nameof(UsageModel.MeasuresModel.NumberOfEnterpriseOpens))] + [TestCase("https://enterprise.com/foo/bar", true, 0, nameof(UsageModel.MeasuresModel.NumberOfGitHubOpens))] + public async Task UpdatesMetricsWhenCloneOrOpenRepositoryAsync(string cloneUrl, bool dirExists, int numberOfCalls, string counterName) { - var cloneDialogResult = new CloneDialogResult(@"c:\dev\bar", cloneUrl); + var repositoryPath = @"c:\dev\bar"; + var cloneDialogResult = new CloneDialogResult(repositoryPath, cloneUrl); var serviceProvider = Substitutes.ServiceProvider; var operatingSystem = serviceProvider.GetOperatingSystem(); + operatingSystem.Directory.DirectoryExists(repositoryPath).Returns(dirExists); var vsGitServices = serviceProvider.GetVSGitServices(); var teamExplorerServices = Substitute.For(); var graphqlFactory = Substitute.For();