Skip to content

Commit

Permalink
Update demo and tests projects to work in VS code and use .net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
matus-tomlein committed Jun 19, 2024
1 parent bf663ea commit cecc564
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 124 deletions.
95 changes: 27 additions & 68 deletions Snowplow.Demo.Console/Program.cs
Original file line number Diff line number Diff line change
@@ -1,80 +1,39 @@
/*
* Copyright (c) 2023 Snowplow Analytics Ltd. All rights reserved.
* This program is licensed to you under the Apache License Version 2.0,
* and you may not use this file except in compliance with the Apache License
* Version 2.0. You may obtain a copy of the Apache License Version 2.0 at
* http://www.apache.org/licenses/LICENSE-2.0.
* Unless required by applicable law or agreed to in writing,
* software distributed under the Apache License Version 2.0 is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the Apache License Version 2.0 for the specific
* language governing permissions and limitations there under.
*/

using Snowplow.Tracker;
using Snowplow.Tracker.Logging;
using Snowplow.Tracker.Models.Events;
using System;
using System.Linq;

namespace Snowplow.Demo.Console
string collectorHostname = "http://localhost:9090";
int port = 80;

int count = 100;

// help the user out a bit with ports
if (Uri.IsWellFormedUriString(collectorHostname, UriKind.Absolute))
{
public class Program
Uri tmp;
if (Uri.TryCreate(collectorHostname, UriKind.Absolute, out tmp))
{

/// <summary>
/// Runs the Console Demo application
/// </summary>
/// <param name="args"></param>
public static void Main(string[] args)
if (tmp.Scheme == "http" || tmp.Scheme == "https")
{
string collectorHostname = "<invalid>";
int port = 80;

int count = 100;

switch (args.Count())
{
case 2:
count = Int32.Parse(args[1]);
goto case 1;
case 1:
collectorHostname = args[0];
break;
default:
System.Console.WriteLine("Invalid arguments. Usage: <app> <collector-hostname> [number of events to send]");
return;
}

// help the user out a bit with ports
if (Uri.IsWellFormedUriString(collectorHostname, UriKind.Absolute))
{
Uri tmp;
if (Uri.TryCreate(collectorHostname, UriKind.Absolute, out tmp))
{
if (tmp.Scheme == "http" || tmp.Scheme == "https")
{
collectorHostname = tmp.Host;
port = tmp.Port;
}
}
}
collectorHostname = tmp.Host;
port = tmp.Port;
}
}
}

System.Console.WriteLine("Demo app started - sending " + count + " events to " + collectorHostname + " port " + port);
System.Console.WriteLine("Demo app started - sending " + count + " events to " + collectorHostname + " port " + port);

var logger = new ConsoleLogger();
var logger = new ConsoleLogger();

Tracker.Tracker.Instance.Start(collectorHostname, "snowplow-demo-app.db", l: logger, endpointPort: port);
Tracker.Instance.Start(collectorHostname, "snowplow-demo-app.db", l: logger, endpointPort: port);

for (int i = 0; i < count; i++)
{
Tracker.Tracker.Instance.Track(new PageView().SetPageUrl("http://helloworld.com/sample/sample.php").Build());
}
for (int i = 0; i < count; i++)
{
Tracker.Instance.Track(new PageView().SetPageUrl("http://helloworld.com/sample/sample.php").Build());
}

Tracker.Tracker.Instance.Flush();
Tracker.Tracker.Instance.Stop();
Tracker.Instance.Flush();
Tracker.Instance.Stop();

System.Console.WriteLine("Demo app finished");
System.Console.Out.Flush();
}
}
}
System.Console.WriteLine("Demo app finished");
System.Console.Out.Flush();
7 changes: 4 additions & 3 deletions Snowplow.Demo.Console/Snowplow.Demo.Console.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Snowplow.Tracker" Version="1.2.2" />
<ProjectReference Include="..\Snowplow.Tracker\Snowplow.Tracker.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Snowplow.Tracker.Tests/Emitters/AsyncEmitterTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void testFlush()
Assert.IsTrue(e.Running);
e.Stop();

Assert.AreEqual(100, mockEndpoint.CallCount);
Assert.IsTrue(100 <= mockEndpoint.CallCount);
Assert.AreEqual(0, storage.TotalItems);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
using System;
using System.Threading.Tasks;

using SnowplowHttpMethod = Snowplow.Tracker.Endpoints.HttpMethod;

namespace Snowplow.Tracker.Tests.Endpoints
{
[TestClass]
Expand Down Expand Up @@ -228,7 +230,7 @@ public void testGetPortIsSet()
public void testPostHttpGood()
{
var postReq = new MockPost();
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var payload = new Payload();
payload.Add("foo", "bar");

Expand All @@ -250,7 +252,7 @@ public void testPostHttpGood()
public void testPostHttpNoResponse()
{
var postReq = new MockPost() { StatusCode = 404 };
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var payload = new Payload();

payload.Add("foo", "bar");
Expand All @@ -268,7 +270,7 @@ public void testPostHttpNoResponse()
public void testPostHttpNon200Response()
{
var postReq = new MockPost() { StatusCode = 404 };
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: HttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var endpoint = new SnowplowHttpCollectorEndpoint("somewhere.com", HttpProtocol.HTTPS, method: SnowplowHttpMethod.POST, postMethod: new PostDelegate(postReq.HttpPost));
var payload = new Payload();
payload.Add("foo", "bar");

Expand Down
6 changes: 4 additions & 2 deletions Snowplow.Tracker.Tests/LoadTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
using Snowplow.Tracker.Endpoints;
using Snowplow.Tracker.Emitters;

using SnowplowHttpMethod = Snowplow.Tracker.Endpoints.HttpMethod;

namespace Snowplow.Tracker.Tests
{
[TestClass]
Expand All @@ -47,7 +49,7 @@ public void testLoadPost()
Assert.AreEqual(0, storage.TotalItems);

var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString());
var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: HttpMethod.POST, byteLimitPost: 100000);
var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: SnowplowHttpMethod.POST, byteLimitPost: 100000);
var emitter = new AsyncEmitter(endpoint: endpoint, queue: queue, sendLimit: 1000);

var clientSession = new ClientSession(_testClientSessionFilename);
Expand Down Expand Up @@ -82,7 +84,7 @@ public void testLoadGet()
Assert.AreEqual(0, storage.TotalItems);

var queue = new PersistentBlockingQueue(storage, new PayloadToJsonString());
var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: HttpMethod.GET, byteLimitGet: 50000);
var endpoint = new SnowplowHttpCollectorEndpoint(host: _collectorHostUri, port: 8080, protocol: HttpProtocol.HTTP, method: SnowplowHttpMethod.GET, byteLimitGet: 50000);
var emitter = new AsyncEmitter(endpoint: endpoint, queue: queue, sendLimit: 25);

var clientSession = new ClientSession(_testClientSessionFilename);
Expand Down
19 changes: 0 additions & 19 deletions Snowplow.Tracker.Tests/Properties/AssemblyInfo.cs

This file was deleted.

30 changes: 13 additions & 17 deletions Snowplow.Tracker.Tests/Snowplow.Tracker.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,32 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AssemblyName>Snowplow.Tracker.Tests</AssemblyName>
<PackageId>Snowplow.Tracker.Tests</PackageId>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<RuntimeFrameworkVersion>5.0.6</RuntimeFrameworkVersion>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
</PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<WarningLevel>4</WarningLevel>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Snowplow.Tracker\Snowplow.Tracker.csproj" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="NETStandard.Library" Version="2.0.3" />
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
<ProjectReference Include="..\Snowplow.Tracker\Snowplow.Tracker.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions Snowplow.Tracker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Tracker", "Snowplo
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Tracker.Tests", "Snowplow.Tracker.Tests\Snowplow.Tracker.Tests.csproj", "{43FFD47A-0B44-4A73-9F95-3223FF236799}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Snowplow.Demo.Console", "Snowplow.Demo.Console\Snowplow.Demo.Console.csproj", "{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -23,6 +25,10 @@ Global
{43FFD47A-0B44-4A73-9F95-3223FF236799}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43FFD47A-0B44-4A73-9F95-3223FF236799}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43FFD47A-0B44-4A73-9F95-3223FF236799}.Release|Any CPU.Build.0 = Release|Any CPU
{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C0BE3EC0-C2D6-422E-8E97-B41DCA08B27C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
6 changes: 3 additions & 3 deletions Snowplow.Tracker/Snowplow.Tracker.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Copyright>Copyright 2023</Copyright>
<AssemblyTitle>Snowplow.Tracker</AssemblyTitle>
<VersionPrefix>1.2.2</VersionPrefix>
<Authors>Fred Blundun, Joshua Beemster, Ed Lewis, Paul Boocock</Authors>
<Authors>Snowplow Analytics</Authors>
<TargetFrameworks>netstandard1.4;netstandard2.0</TargetFrameworks>
<AssemblyName>Snowplow.Tracker</AssemblyName>
<PackageId>Snowplow.Tracker</PackageId>
Expand All @@ -20,8 +20,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="LiteDB" Version="5.0.15" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
<PackageReference Include="LiteDB" Version="5.0.20" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.4'">
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31402.337
# Visual Studio Version 17
VisualStudioVersion = 17.5.002.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snowplow.Demo.Console", "Snowplow.Demo.Console\Snowplow.Demo.Console.csproj", "{0945D603-76B3-4524-A142-341908D40501}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Snowplow.Tracker", "Snowplow.Tracker.csproj", "{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0945D603-76B3-4524-A142-341908D40501}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0945D603-76B3-4524-A142-341908D40501}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0945D603-76B3-4524-A142-341908D40501}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0945D603-76B3-4524-A142-341908D40501}.Release|Any CPU.Build.0 = Release|Any CPU
{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E88D3FEF-14DC-4D85-87E1-6DCEB79F32E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4E8A30EC-4322-42A7-A26A-6F5D71425F90}
SolutionGuid = {B5F43CF0-FE97-4274-8C47-6DC5557F9306}
EndGlobalSection
EndGlobal

0 comments on commit cecc564

Please sign in to comment.