Add some working metrics tests

This commit is contained in:
Andreia Gaita 2018-04-16 14:46:12 +02:00
Родитель abcbda90df
Коммит 861a41bae7
17 изменённых файлов: 368 добавлений и 125 удалений

Просмотреть файл

@ -106,6 +106,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.Logging", "src\GitHu
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitHub.Services.Vssdk", "src\GitHub.Services.Vssdk\GitHub.Services.Vssdk.csproj", "{2D3D2834-33BE-45CA-B3CC-12F853557D7B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Metrics", "Metrics", "{C2D88962-BD6B-4F11-B914-535B38377962}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetricsServer", "test\MetricsTests\MetricsServer\MetricsServer.csproj", "{14FDEE91-7301-4247-846C-049647BF8E99}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MetricsTests", "test\MetricsTests\MetricsTests\MetricsTests.csproj", "{09313E65-7ADB-48C1-AD3A-572020C5BDCB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -415,6 +421,26 @@ Global
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.Release|Any CPU.Build.0 = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{2D3D2834-33BE-45CA-B3CC-12F853557D7B}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.DebugCodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.DebugCodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.DebugWithoutVsix|Any CPU.ActiveCfg = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.DebugWithoutVsix|Any CPU.Build.0 = Debug|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.Release|Any CPU.Build.0 = Release|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{14FDEE91-7301-4247-846C-049647BF8E99}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.DebugCodeAnalysis|Any CPU.ActiveCfg = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.DebugCodeAnalysis|Any CPU.Build.0 = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.DebugWithoutVsix|Any CPU.ActiveCfg = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.DebugWithoutVsix|Any CPU.Build.0 = Debug|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.Release|Any CPU.Build.0 = Release|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.ReleaseWithoutVsix|Any CPU.ActiveCfg = Release|Any CPU
{09313E65-7ADB-48C1-AD3A-572020C5BDCB}.ReleaseWithoutVsix|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -438,5 +464,8 @@ Global
{7B835A7D-CF94-45E8-B191-96F5A4FE26A8} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
{110B206F-8554-4B51-BF86-94DAA32F5E26} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
{17EB676B-BB91-48B5-AA59-C67695C647C2} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
{C2D88962-BD6B-4F11-B914-535B38377962} = {8A7DA2E7-262B-4581-807A-1C45CE79CDFD}
{14FDEE91-7301-4247-846C-049647BF8E99} = {C2D88962-BD6B-4F11-B914-535B38377962}
{09313E65-7ADB-48C1-AD3A-572020C5BDCB} = {C2D88962-BD6B-4F11-B914-535B38377962}
EndGlobalSection
EndGlobal

Просмотреть файл

@ -4,8 +4,10 @@ namespace GitHub.Models
{
public class UsageModel
{
public DimensionsModel Dimensions { get; set; }
public MeasuresModel Measures { get; set; }
public DimensionsModel Dimensions { get; set; } = new DimensionsModel();
public MeasuresModel Measures { get; set; } = new MeasuresModel();
protected UsageModel() { }
public static UsageModel Create(Guid guid)
{
@ -14,9 +16,8 @@ namespace GitHub.Models
Dimensions = new DimensionsModel
{
Guid = guid,
Date = DateTime.Now,
},
Measures = new MeasuresModel(),
Date = DateTimeOffset.Now,
}
};
}

Просмотреть файл

@ -1,6 +1,8 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("GitHub.Exports")]
[assembly: AssemblyDescription("GitHub interfaces for mef exports")]
[assembly: Guid("9aea02db-02b5-409c-b0ca-115d05331a6b")]
[assembly: InternalsVisibleTo("MetricsTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c1a49bb6a01873a4e5434cbaa9993f5a75d3ba66fecfff4d85066c7094913d43f6f9bb706d2eb65f4990a7adfe7321e120ba8be5a8367fc5551c0a6eeb4850c5646377d314142abe69a5fb8ec0957a63ba5893901adb5b4cf0eb7f7e5861376e0cb4fd975576094b2fb4843df9c186eb17232365291b93e17f5e2b6cc1cda2c2")]

Просмотреть файл

@ -10,7 +10,7 @@ using GitHub.Services;
using Octokit;
using Octokit.Internal;
namespace GitHub.App
namespace GitHub.Services
{
[Export(typeof(IMetricsService))]
[PartCreationPolicy(CreationPolicy.NonShared)]
@ -99,7 +99,7 @@ namespace GitHub.App
*/
}
static StringContent SerializeRequest(UsageModel model)
internal static StringContent SerializeRequest(UsageModel model)
{
var serializer = new SimpleJsonSerializer();
var dictionary = new Dictionary<string, object>

Просмотреть файл

@ -59,28 +59,34 @@ namespace GitHub.Services
IDisposable StartTimer()
{
return service.StartTimer(TimerTick, TimeSpan.FromMinutes(3), TimeSpan.FromHours(8));
return service.StartTimer(TimerTick, TimeSpan.FromMinutes(3), TimeSpan.FromDays(1));
}
async Task Initialize()
{
if (initialized)
return;
// The services needed by the usage tracker are loaded when they are first needed to
// improve the startup time of the extension.
if (!initialized)
{
await ThreadingHelper.SwitchToMainThreadAsync();
await ThreadingHelper.SwitchToMainThreadAsync();
client = gitHubServiceProvider.TryGetService<IMetricsService>();
connectionManager = gitHubServiceProvider.GetService<IConnectionManager>();
vsservices = gitHubServiceProvider.GetService<IVSServices>();
initialized = true;
}
client = gitHubServiceProvider.TryGetService<IMetricsService>();
connectionManager = gitHubServiceProvider.GetService<IConnectionManager>();
vsservices = gitHubServiceProvider.GetService<IVSServices>();
initialized = true;
}
async Task TimerTick()
{
await Initialize();
if (firstTick)
{
await IncrementCounter(x => x.NumberOfStartups);
firstTick = false;
}
if (client == null || !userSettings.CollectMetrics)
{
timer.Dispose();
@ -89,16 +95,8 @@ namespace GitHub.Services
}
var data = await service.ReadLocalData();
var changed = false;
if (firstTick)
{
var current = await GetCurrentReport(data);
current.Measures.NumberOfStartups++;
changed = true;
firstTick = false;
}
for (var i = data.Reports.Count - 1; i >= 0; --i)
{
if (data.Reports[i].Dimensions.Date.Date != DateTimeOffset.Now.Date)
@ -138,16 +136,8 @@ namespace GitHub.Services
current.Dimensions.AppVersion = AssemblyVersionInformation.Version;
current.Dimensions.VSVersion = vsservices.VSVersion;
if (connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom()))
{
current.Dimensions.IsGitHubUser = true;
}
if (connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom()))
{
current.Dimensions.IsEnterpriseUser = true;
}
current.Dimensions.IsGitHubUser = connectionManager.Connections.Any(x => x.HostAddress.IsGitHubDotCom());
current.Dimensions.IsEnterpriseUser = connectionManager.Connections.Any(x => !x.HostAddress.IsGitHubDotCom());
return current;
}
}

Просмотреть файл

@ -12,6 +12,8 @@
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -22,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoWarn>8002,618</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@ -36,18 +39,19 @@
<StartupObject />
</PropertyGroup>
<PropertyGroup>
<SignAssembly>false</SignAssembly>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="Nancy, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.1.4.4\lib\net40\Nancy.dll</HintPath>
<Reference Include="Nancy, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(SolutionDir)\packages\Nancy.1.4.1\lib\net40\Nancy.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Nancy.Hosting.Self, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
<HintPath>$(SolutionDir)\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
@ -62,19 +66,32 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="..\..\..\src\GitHub.Exports\Models\UsageData.cs">
<None Include="..\..\..\src\GitHub.Exports\Models\UsageData.cs">
<Link>UsageData.cs</Link>
</Compile>
<Compile Include="..\..\..\src\GitHub.Exports\Models\UsageModel.cs">
</None>
<None Include="..\..\..\src\GitHub.Exports\Models\UsageModel.cs">
<Link>UsageModel.cs</Link>
</Compile>
</None>
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="key.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\GitHub.Exports\GitHub.Exports.csproj">
<Project>{9AEA02DB-02B5-409C-B0CA-115D05331A6B}</Project>
<Name>GitHub.Exports</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\..\..\packages\StrongNamer.0.0.6\build\StrongNamer.targets" Condition="Exists('..\..\..\packages\StrongNamer.0.0.6\build\StrongNamer.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\StrongNamer.0.0.6\build\StrongNamer.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\StrongNamer.0.0.6\build\StrongNamer.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

Просмотреть файл

@ -5,10 +5,6 @@ using Nancy.ModelBinding;
using Nancy.Responses.Negotiation;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading;
using Nancy.Extensions;
namespace MetricsServer
{
@ -42,21 +38,25 @@ namespace MetricsServer
{
Post["/api/usage/visualstudio"] = p =>
{
Console.WriteLine(Request.Body.AsString());
var errors = new List<string>();
var usage = this.Bind<UsageModel>();
if (String.IsNullOrEmpty(usage.AppVersion))
if (String.IsNullOrEmpty(usage.Dimensions.AppVersion))
errors.Add("Empty appVersion");
if (String.IsNullOrEmpty(usage.Lang))
Version result = null;
if (!Version.TryParse(usage.Dimensions.AppVersion, out result))
errors.Add("Invalid appVersion");
if (String.IsNullOrEmpty(usage.Dimensions.Lang))
errors.Add("Empty lang");
if (String.IsNullOrEmpty(usage.VSVersion))
if (String.IsNullOrEmpty(usage.Dimensions.VSVersion))
errors.Add("Empty vSVersion");
if (usage.NumberOfStartups == 0)
if (usage.Dimensions.Date == DateTimeOffset.MinValue)
errors.Add("Empty date");
if (usage.Measures.NumberOfStartups == 0)
errors.Add("Startups is 0");
if (errors.Count > 0)
{
return Negotiate
.WithStatusCode(HttpStatusCode.BadRequest)
.WithStatusCode(HttpStatusCode.InternalServerError)
.WithAllowedMediaRange(MediaRange.FromString("application/json"))
.WithMediaRangeModel(
MediaRange.FromString("application/json"),

Просмотреть файл

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Nancy" version="1.4.4" targetFramework="net461" />
<package id="Nancy" version="1.4.1" targetFramework="net461" />
<package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net461" />
<package id="StrongNamer" version="0.0.6" targetFramework="net461" />
</packages>

Просмотреть файл

@ -50,6 +50,10 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\GitHub.Exports\GitHub.Exports.csproj">
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
<Name>GitHub.Exports</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\submodules\octokit.net\Octokit\Octokit.csproj">
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
<Name>Octokit</Name>

Просмотреть файл

@ -42,12 +42,14 @@ namespace MetricsServerApp
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(uri, "/api/usage/visualstudio"));
var model = UsageModel.Create(Guid.NewGuid());
model.Dimensions.AppVersion = "9.9.9";
model.Dimensions.Lang = "en-us";
model.Dimensions.VSVersion = "14";
model.Measures.NumberOfStartups = 1;
var data = new UsageData();
var model = data.Model;
model.AppVersion = "9.9.9";
model.Lang = "en-us";
model.VSVersion = "14";
model.NumberOfStartups = 1;
data.Reports = new List<UsageModel> { model };
request.Content = SerializeRequest(model);
@ -55,7 +57,6 @@ namespace MetricsServerApp
try
{
response = await client.SendAsync(request);
}
catch (Exception ex)
{

Просмотреть файл

@ -0,0 +1,82 @@
using System;
using System.Collections.Generic;
using NUnit.Framework;
using System.Net.Http;
using System.Net.Http.Headers;
using GitHub.Models;
using System.Threading.Tasks;
using System.Net;
namespace MetricsTests
{
[TestFixture]
public class Submissions
{
HttpClient client;
Uri uri;
MetricsServer.Server server;
[OneTimeSetUp]
public void Setup()
{
uri = new Uri("http://localhost:4000");
if (uri.Host == "localhost")
{
server = new MetricsServer.Server(uri.Host, uri.Port);
server.Start();
}
client = new HttpClient();
client.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(uri, "/api/usage/visualstudio"));
}
[OneTimeTearDown]
public void TearDown()
{
server?.Stop();
}
[Test]
public async Task ValidDimensions()
{
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(uri, "/api/usage/visualstudio"));
var data = new UsageData();
data.Reports = new List<UsageModel> { UsageModel.Create(Guid.NewGuid()) };
var model = data.Reports[0];
model.Dimensions.AppVersion = "9.9.9";
model.Dimensions.Lang = "en-us";
model.Dimensions.VSVersion = "14";
model.Measures.NumberOfStartups = 1;
request.Content = GitHub.Services.MetricsService.SerializeRequest(model);
HttpResponseMessage response = null;
Assert.DoesNotThrowAsync(async () => response = await client.SendAsync(request));
var ret = await response.Content.ReadAsStringAsync();
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
}
[Test]
public async Task InvalidAppVersion()
{
var request = new HttpRequestMessage(HttpMethod.Post, new Uri(uri, "/api/usage/visualstudio"));
var data = new UsageData();
data.Reports = new List<UsageModel> { UsageModel.Create(Guid.NewGuid()) };
var model = data.Reports[0];
model.Dimensions.AppVersion = "nope";
model.Dimensions.Lang = "en-us";
model.Dimensions.VSVersion = "14";
model.Measures.NumberOfStartups = 1;
request.Content = GitHub.Services.MetricsService.SerializeRequest(model);
HttpResponseMessage response = null;
Assert.DoesNotThrowAsync(async () => response = await client.SendAsync(request));
var ret = await response.Content.ReadAsStringAsync();
Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
}
}
}

Просмотреть файл

@ -0,0 +1,122 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\..\..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('..\..\..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{09313E65-7ADB-48C1-AD3A-572020C5BDCB}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MetricsTests</RootNamespace>
<AssemblyName>MetricsTests</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\NUnit.3.9.0\lib\net45\nunit.framework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="MetricsTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="key.snk" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\src\GitHub.Exports\GitHub.Exports.csproj">
<Project>{9aea02db-02b5-409c-b0ca-115d05331a6b}</Project>
<Name>GitHub.Exports</Name>
</ProjectReference>
<ProjectReference Include="..\..\..\submodules\octokit.net\Octokit\Octokit.csproj">
<Project>{08DD4305-7787-4823-A53F-4D0F725A07F3}</Project>
<Name>Octokit</Name>
</ProjectReference>
<ProjectReference Include="..\MetricsServer\MetricsServer.csproj">
<Project>{14fdee91-7301-4247-846c-049647bf8e99}</Project>
<Name>MetricsServer</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\..\..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

Просмотреть файл

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("MetricsTests")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MetricsTests")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("09313e65-7adb-48c1-ad3a-572020c5bdcb")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

Двоичные данные
test/MetricsTests/MetricsTests/key.snk Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.9.0" targetFramework="net452" />
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net452" />
<package id="NUnit3TestAdapter" version="3.9.0" targetFramework="net452" />
</packages>

Просмотреть файл

@ -36,7 +36,7 @@ public class RepositoryCloneServiceTests
var cloneService = new RepositoryCloneService(operatingSystem, vsGitServices, usageTracker);
await cloneService.CloneRepository("https://github.com/foo/bar", "bar", @"c:\dev");
var model = new UsageModel();
var model = UsageModel.Create(Guid.NewGuid());
await usageTracker.Received().IncrementCounter(
Arg.Is<Expression<Func<UsageModel.MeasuresModel, int>>>(x =>

Просмотреть файл

@ -31,14 +31,7 @@ namespace MetricsTests
[Test]
public async Task FirstTickShouldIncrementLaunchCount()
{
var service = CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
Date = DateTimeOffset.Now
},
Measures = new UsageModel.MeasuresModel()
});
var service = CreateUsageService(UsageModel.Create(Guid.NewGuid()));
var targetAndTick = CreateTargetAndGetTick(CreateServiceProvider(), service);
await targetAndTick.Item2();
@ -49,14 +42,7 @@ namespace MetricsTests
[Test]
public async Task SubsequentTickShouldNotIncrementLaunchCount()
{
var service = CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
Date = DateTimeOffset.Now
},
Measures = new UsageModel.MeasuresModel()
});
var service = CreateUsageService(UsageModel.Create(Guid.NewGuid()));
var targetAndTick = CreateTargetAndGetTick(CreateServiceProvider(), service);
await targetAndTick.Item2();
@ -69,14 +55,7 @@ namespace MetricsTests
[Test]
public async Task ShouldDisposeTimerIfMetricsServiceNotFound()
{
var service = CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
Date = DateTimeOffset.Now
},
Measures = new UsageModel.MeasuresModel()
});
var service = CreateUsageService(UsageModel.Create(Guid.NewGuid()));
var disposed = false;
var disposable = Disposable.Create(() => disposed = true);
service.StartTimer(null, new TimeSpan(), new TimeSpan()).ReturnsForAnyArgs(disposable);
@ -96,14 +75,7 @@ namespace MetricsTests
var serviceProvider = CreateServiceProvider();
var targetAndTick = CreateTargetAndGetTick(
serviceProvider,
CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
Date = DateTimeOffset.Now
},
Measures = new UsageModel.MeasuresModel()
}));
CreateUsageService(UsageModel.Create(Guid.NewGuid())));
await targetAndTick.Item2();
@ -114,17 +86,13 @@ namespace MetricsTests
[Test]
public async Task TickShouldSendDataIfDifferentDay()
{
var model = UsageModel.Create(Guid.NewGuid());
model.Dimensions.Date = DateTimeOffset.Now.AddDays(-2);
var serviceProvider = CreateServiceProvider();
var targetAndTick = CreateTargetAndGetTick(
serviceProvider,
CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
Date = DateTimeOffset.Now.AddDays(-2)
},
Measures = new UsageModel.MeasuresModel()
}));
CreateUsageService(model));
await targetAndTick.Item2();
@ -135,15 +103,8 @@ namespace MetricsTests
[Test]
public async Task ShouldIncrementCounter()
{
var model = new UsageModel {
Dimensions = new UsageModel.DimensionsModel {
Date = DateTimeOffset.Now
},
Measures = new UsageModel.MeasuresModel
{
NumberOfClones = 4
}
};
var model = UsageModel.Create(Guid.NewGuid());
model.Measures.NumberOfClones = 4;
var usageService = CreateUsageService(model);
var target = new UsageTracker(
CreateServiceProvider(),
@ -180,21 +141,12 @@ namespace MetricsTests
[Test]
public async Task ShouldWriteUpdatedData()
{
var date = DateTimeOffset.Now;
var service = CreateUsageService(new UsageModel
{
Dimensions = new UsageModel.DimensionsModel
{
AppVersion = AssemblyVersionInformation.Version,
Lang = CultureInfo.InstalledUICulture.IetfLanguageTag,
CurrentLang = CultureInfo.CurrentCulture.IetfLanguageTag,
Date = date
},
Measures = new UsageModel.MeasuresModel
{
NumberOfClones = 1
}
});
var model = UsageModel.Create(Guid.NewGuid());
model.Dimensions.AppVersion = AssemblyVersionInformation.Version;
model.Dimensions.Lang = CultureInfo.InstalledUICulture.IetfLanguageTag;
model.Dimensions.CurrentLang = CultureInfo.CurrentCulture.IetfLanguageTag;
model.Measures.NumberOfClones = 1;
var service = CreateUsageService(model);
var target = new UsageTracker(
CreateServiceProvider(),