Skip to content
This repository was archived by the owner on Apr 24, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
test:
working_directory: /test
docker:
- image: microsoft/dotnet:1.1.1-sdk
- image: microsoft/dotnet:2.1-sdk
environment:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
DOTNET_CLI_TELEMETRY_OUTPUT: 1
Expand Down
8 changes: 8 additions & 0 deletions Analytics.Net35/Analytics.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,13 @@
<PackageReference Include="AsyncBridge.Net35" Version="0.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Test.Net35</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
8 changes: 8 additions & 0 deletions Analytics.Net45/Analytics.Net45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,12 @@
<PackageReference Include="System.Net.Http" Version="4.3.3" />
</ItemGroup>

<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Test.Net45</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
3 changes: 3 additions & 0 deletions Analytics.NetStandard20/Analytics.NetStandard20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,8 @@
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Test.NetStandard20</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions Analytics.Portable/Analytics.Portable.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<ItemGroup>
<Compile Include="../Analytics/**/*.cs" Exclude="../Analytics/obj/**/*.cs">
</Compile>
<Compile Include="_AssemblyConfiguration.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
Expand Down
7 changes: 7 additions & 0 deletions Analytics.Portable/_AssemblyConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Test.UniversalApp")]
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")]
namespace Analytics
{
}
15 changes: 11 additions & 4 deletions Analytics/Analytics.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace Segment
{
public class Analytics
Expand Down Expand Up @@ -48,6 +44,17 @@ public static void Initialize(string writeKey, Config config)
}
}

internal static void Initialize(Client client)
{
lock (padlock)
{
if (Client == null)
{
Client = client;
}
}
}

/// <summary>
/// Disposes of the current client and allows the creation of a new one
/// </summary>
Expand Down
8 changes: 8 additions & 0 deletions Analytics/Analytics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,13 @@
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="System.Threading.Thread" Version="4.3.0" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Test</_Parameter1>
</AssemblyAttribute>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>DynamicProxyGenAssembly2</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
11 changes: 8 additions & 3 deletions Analytics/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,22 @@ public class Client : IDisposable
/// </summary>
/// <param name="writeKey"></param>
/// <param name="config"></param>
public Client(string writeKey, Config config)
public Client(string writeKey, Config config) : this(writeKey, config, null)
{
if (String.IsNullOrEmpty(writeKey))
if (string.IsNullOrEmpty(writeKey))
throw new InvalidOperationException("Please supply a valid writeKey to initialize.");

}

internal Client(string writeKey, Config config, IRequestHandler requestHandler)
{

this.Statistics = new Statistics();

this._writeKey = writeKey;
this._config = config;

IRequestHandler requestHandler = new BlockingRequestHandler(this, config.Timeout);
requestHandler = requestHandler ?? new BlockingRequestHandler(this, config.Timeout);
IBatchFactory batchFactory = new SimpleBatchFactory(this._writeKey);

if (config.Async)
Expand Down
16 changes: 15 additions & 1 deletion Test.Net35/ActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,32 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using Segment.Request;
using Moq;
using Segment.Model;

namespace Segment.Test
{
[TestFixture()]
public class ActionTests
{
private Mock<IRequestHandler> _mockRequestHandler;

[SetUp]
public void Init()
{
_mockRequestHandler = new Mock<IRequestHandler>();
_mockRequestHandler
.Setup(x => x.MakeRequest(It.IsAny<Batch>()))
.Returns(async (Batch b) =>
{
Analytics.Client.Statistics.Succeeded += b.batch.Count;
});

Analytics.Dispose();
Logger.Handlers += LoggingHandler;
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false), _mockRequestHandler.Object);
Analytics.Initialize(client);
}

[Test ()]
Expand Down
19 changes: 17 additions & 2 deletions Test.Net35/ConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
using System;
using System.Collections.Generic;
using System.Text;
using Moq;
using NUnit.Framework;
using Segment.Model;
using Segment.Request;

namespace Segment.Test
{
[TestFixture()]
public class ConnectionTests
{
private Mock<IRequestHandler> _mockRequestHandler;

[SetUp]
public void Init()
{
_mockRequestHandler = new Mock<IRequestHandler>();
_mockRequestHandler
.Setup(x => x.MakeRequest(It.IsAny<Batch>()))
.Returns(async (Batch b) =>
{
Analytics.Client.Statistics.Succeeded += b.batch.Count;
});

Analytics.Dispose();
Logger.Handlers += LoggingHandler;
}
Expand All @@ -19,7 +32,8 @@ public void Init()
public void ProxyTestNet35()
{
// Set proxy address, like as "http://localhost:8888"
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false).SetProxy(""));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false).SetProxy(""), _mockRequestHandler.Object);
Analytics.Initialize(client);

Actions.Identify(Analytics.Client);

Expand All @@ -32,7 +46,8 @@ public void ProxyTestNet35()
public void GZipTestNet35()
{
// Set GZip/Deflate on request header
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false).SetRequestCompression(true));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false).SetRequestCompression(true), _mockRequestHandler.Object);
Analytics.Initialize(client);

Actions.Identify(Analytics.Client);

Expand Down
21 changes: 18 additions & 3 deletions Test.Net35/FlushTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,38 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Segment.Model;
using Segment.Request;

namespace Segment.Test
{
[TestFixture()]
public class FlushTests
{
private Mock<IRequestHandler> _mockRequestHandler;

[SetUp]
public void Init()
{
_mockRequestHandler = new Mock<IRequestHandler>();
_mockRequestHandler
.Setup(x => x.MakeRequest(It.IsAny<Batch>()))
.Returns(async (Batch b) =>
{
Analytics.Client.Statistics.Succeeded += b.batch.Count;
});

Analytics.Dispose();
Logger.Handlers += LoggingHandler;
}

[Test()]
public void SynchronousFlushTestNet35()
{
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false), _mockRequestHandler.Object);
Analytics.Initialize(client);
Analytics.Client.Succeeded += Client_Succeeded;
Analytics.Client.Failed += Client_Failed;

Expand All @@ -36,7 +49,8 @@ public void SynchronousFlushTestNet35()
[Test()]
public void AsynchronousFlushTestNet35()
{
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(true));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(true), _mockRequestHandler.Object);
Analytics.Initialize(client);

Analytics.Client.Succeeded += Client_Succeeded;
Analytics.Client.Failed += Client_Failed;
Expand All @@ -55,7 +69,8 @@ public void AsynchronousFlushTestNet35()
[Test()]
public void PerformanceTestNet35()
{
Analytics.Initialize(Constants.WRITE_KEY);
var client = new Client(Constants.WRITE_KEY, new Config(), _mockRequestHandler.Object);
Analytics.Initialize(client);

Analytics.Client.Succeeded += Client_Succeeded;
Analytics.Client.Failed += Client_Failed;
Expand Down
6 changes: 6 additions & 0 deletions Test.Net35/Test.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="AsyncBridge.Net35, Version=0.0.0.0, Culture=neutral, PublicKeyToken=b3b1c0202c0d6a87, processorArchitecture=MSIL">
<HintPath>..\packages\AsyncBridge.Net35.0.2.0\lib\net35-Client\AsyncBridge.Net35.dll</HintPath>
</Reference>
<Reference Include="Moq, Version=4.2.1510.2205, Culture=neutral, PublicKeyToken=69f491c39445e920, processorArchitecture=MSIL">
<HintPath>..\packages\Moq.4.2.1510.2205\lib\net35\Moq.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.8.1.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>../packages/NUnit.3.8.1/lib/net35/nunit.framework.dll</HintPath>
</Reference>
Expand Down
2 changes: 2 additions & 0 deletions Test.Net35/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AsyncBridge.Net35" version="0.2.0" targetFramework="net35" />
<package id="Moq" version="4.2.1510.2205" targetFramework="net35" />
<package id="NUnit" version="3.8.1" targetFramework="net35" />
<package id="NUnit.ConsoleRunner" version="3.7.0" targetFramework="net35" />
<package id="NUnit.Extension.NUnitProjectLoader" version="3.5.0" targetFramework="net35" />
Expand Down
17 changes: 16 additions & 1 deletion Test.Net45/ActionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,33 @@
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
using Segment.Request;
using Moq;
using Segment.Model;

namespace Segment.Test
{
[TestFixture()]
public class ActionTests
{
private Mock<IRequestHandler> _mockRequestHandler;

[SetUp]
public void Init()
{
_mockRequestHandler = new Mock<IRequestHandler>();
_mockRequestHandler
.Setup(x => x.MakeRequest(It.IsAny<Batch>()))
.Returns((Batch b) =>
{
Analytics.Client.Statistics.Succeeded += b.batch.Count;
return Task.FromResult(true);
});

Analytics.Dispose();
Logger.Handlers += LoggingHandler;
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false), _mockRequestHandler.Object);
Analytics.Initialize(client);
}

[Test ()]
Expand Down
23 changes: 20 additions & 3 deletions Test.Net45/ConnectionTests.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Moq;
using NUnit.Framework;
using Segment.Model;
using Segment.Request;

namespace Segment.Test
{
[TestFixture()]
public class ConnectionTests
{
private Mock<IRequestHandler> _mockRequestHandler;

[SetUp]
public void Init()
{
_mockRequestHandler = new Mock<IRequestHandler>();
_mockRequestHandler
.Setup(x => x.MakeRequest(It.IsAny<Batch>()))
.Returns((Batch b) =>
{
Analytics.Client.Statistics.Succeeded += b.batch.Count;
return Task.FromResult(true);
});

Analytics.Dispose();
Logger.Handlers += LoggingHandler;
}
Expand All @@ -19,7 +34,8 @@ public void Init()
public void ProxyTestNet45()
{
// Set proxy address, like as "http://localhost:8888"
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false).SetProxy(""));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false).SetProxy(""), _mockRequestHandler.Object);
Analytics.Initialize(client);

Actions.Identify(Analytics.Client);

Expand All @@ -32,7 +48,8 @@ public void ProxyTestNet45()
public void GZipTestNet45()
{
// Set GZip/Deflate on request header
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false).SetRequestCompression(true));
var client = new Client(Constants.WRITE_KEY, new Config().SetAsync(false).SetRequestCompression(true), _mockRequestHandler.Object);
Analytics.Initialize(client);

Actions.Identify(Analytics.Client);

Expand Down
Loading