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

Commit abcbda9

Browse files
committed
Metrics tests
1 parent 63fbb61 commit abcbda9

File tree

11 files changed

+469
-0
lines changed

11 files changed

+469
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{14FDEE91-7301-4247-846C-049647BF8E99}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MetricsServer</RootNamespace>
11+
<AssemblyName>MetricsServer</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<PropertyGroup>
36+
<StartupObject />
37+
</PropertyGroup>
38+
<PropertyGroup>
39+
<SignAssembly>false</SignAssembly>
40+
</PropertyGroup>
41+
<PropertyGroup>
42+
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
43+
</PropertyGroup>
44+
<ItemGroup>
45+
<Reference Include="Nancy, Version=1.4.4.0, Culture=neutral, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Nancy.1.4.4\lib\net40\Nancy.dll</HintPath>
47+
<Private>True</Private>
48+
</Reference>
49+
<Reference Include="Nancy.Hosting.Self, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL">
50+
<HintPath>..\packages\Nancy.Hosting.Self.1.4.1\lib\net40\Nancy.Hosting.Self.dll</HintPath>
51+
<Private>True</Private>
52+
</Reference>
53+
<Reference Include="System" />
54+
<Reference Include="System.Core" />
55+
<Reference Include="System.Xml.Linq" />
56+
<Reference Include="System.Data.DataSetExtensions" />
57+
<Reference Include="Microsoft.CSharp" />
58+
<Reference Include="System.Data" />
59+
<Reference Include="System.Net.Http" />
60+
<Reference Include="System.Xml" />
61+
</ItemGroup>
62+
<ItemGroup>
63+
<Compile Include="Program.cs" />
64+
<Compile Include="Properties\AssemblyInfo.cs" />
65+
<Compile Include="..\..\..\src\GitHub.Exports\Models\UsageData.cs">
66+
<Link>UsageData.cs</Link>
67+
</Compile>
68+
<Compile Include="..\..\..\src\GitHub.Exports\Models\UsageModel.cs">
69+
<Link>UsageModel.cs</Link>
70+
</Compile>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<None Include="App.config" />
74+
<None Include="key.snk" />
75+
<None Include="packages.config" />
76+
</ItemGroup>
77+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
78+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
79+
Other similar extension points exist, see Microsoft.Common.targets.
80+
<Target Name="BeforeBuild">
81+
</Target>
82+
<Target Name="AfterBuild">
83+
</Target>
84+
-->
85+
</Project>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
using GitHub.Models;
2+
using Nancy;
3+
using Nancy.Hosting.Self;
4+
using Nancy.ModelBinding;
5+
using Nancy.Responses.Negotiation;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.Diagnostics;
9+
using System.Text;
10+
using System.Threading;
11+
using Nancy.Extensions;
12+
13+
namespace MetricsServer
14+
{
15+
public class Server
16+
{
17+
readonly string host;
18+
readonly int port;
19+
NancyHost server;
20+
public Server(string host, int port)
21+
{
22+
this.host = host;
23+
this.port = port;
24+
}
25+
26+
public void Start()
27+
{
28+
var conf = new HostConfiguration { RewriteLocalhost = false };
29+
server = new NancyHost(conf, new Uri($"http://{host}:{port}"));
30+
server.Start();
31+
}
32+
33+
public void Stop()
34+
{
35+
server.Stop();
36+
}
37+
}
38+
39+
public class UsageModule : NancyModule
40+
{
41+
public UsageModule()
42+
{
43+
Post["/api/usage/visualstudio"] = p =>
44+
{
45+
Console.WriteLine(Request.Body.AsString());
46+
var errors = new List<string>();
47+
var usage = this.Bind<UsageModel>();
48+
if (String.IsNullOrEmpty(usage.AppVersion))
49+
errors.Add("Empty appVersion");
50+
if (String.IsNullOrEmpty(usage.Lang))
51+
errors.Add("Empty lang");
52+
if (String.IsNullOrEmpty(usage.VSVersion))
53+
errors.Add("Empty vSVersion");
54+
if (usage.NumberOfStartups == 0)
55+
errors.Add("Startups is 0");
56+
if (errors.Count > 0)
57+
{
58+
return Negotiate
59+
.WithStatusCode(HttpStatusCode.BadRequest)
60+
.WithAllowedMediaRange(MediaRange.FromString("application/json"))
61+
.WithMediaRangeModel(
62+
MediaRange.FromString("application/json"),
63+
new { result = errors }); // Model for 'application/json';
64+
}
65+
66+
return Negotiate
67+
.WithAllowedMediaRange(MediaRange.FromString("application/json"))
68+
.WithMediaRangeModel(
69+
MediaRange.FromString("application/json"),
70+
new { result = "Cool usage" }); // Model for 'application/json';
71+
};
72+
}
73+
}
74+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("MetricsServer")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("MetricsServer")]
13+
[assembly: AssemblyCopyright("Copyright © 2018")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("14fdee91-7301-4247-846c-049647bf8e99")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
596 Bytes
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Nancy" version="1.4.4" targetFramework="net461" />
4+
<package id="Nancy.Hosting.Self" version="1.4.1" targetFramework="net461" />
5+
</packages>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
5+
</startup>
6+
</configuration>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{A0E20ED2-0C69-469F-BC77-37112000F71D}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>MetricsServerApp</RootNamespace>
11+
<AssemblyName>MetricsServerApp</AssemblyName>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<PlatformTarget>AnyCPU</PlatformTarget>
18+
<DebugSymbols>true</DebugSymbols>
19+
<DebugType>full</DebugType>
20+
<Optimize>false</Optimize>
21+
<OutputPath>bin\Debug\</OutputPath>
22+
<DefineConstants>DEBUG;TRACE</DefineConstants>
23+
<ErrorReport>prompt</ErrorReport>
24+
<WarningLevel>4</WarningLevel>
25+
</PropertyGroup>
26+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
27+
<PlatformTarget>AnyCPU</PlatformTarget>
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
<Reference Include="System.Core" />
38+
<Reference Include="System.Xml.Linq" />
39+
<Reference Include="System.Data.DataSetExtensions" />
40+
<Reference Include="Microsoft.CSharp" />
41+
<Reference Include="System.Data" />
42+
<Reference Include="System.Net.Http" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="Program.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="App.config" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\..\..\submodules\octokit.net\Octokit\Octokit.csproj">
54+
<Project>{08dd4305-7787-4823-a53f-4d0f725a07f3}</Project>
55+
<Name>Octokit</Name>
56+
</ProjectReference>
57+
<ProjectReference Include="..\MetricsServer\MetricsServer.csproj">
58+
<Project>{14fdee91-7301-4247-846c-049647bf8e99}</Project>
59+
<Name>MetricsServer</Name>
60+
</ProjectReference>
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
64+
Other similar extension points exist, see Microsoft.Common.targets.
65+
<Target Name="BeforeBuild">
66+
</Target>
67+
<Target Name="AfterBuild">
68+
</Target>
69+
-->
70+
</Project>

0 commit comments

Comments
 (0)