forked from segmentio/Analytics.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathActionTests.cs
More file actions
85 lines (72 loc) · 1.59 KB
/
ActionTests.cs
File metadata and controls
85 lines (72 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using NUnit.Framework;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Segment.Test
{
[TestFixture()]
public class ActionTests
{
[SetUp]
public void Init()
{
Analytics.Dispose();
Logger.Handlers += LoggingHandler;
Analytics.Initialize(Constants.WRITE_KEY, new Config().SetAsync(false));
}
[Test ()]
public void IdentifyTestNet35()
{
Actions.Identify(Analytics.Client);
FlushAndCheck(1);
}
[Test()]
public void TrackTestNet35()
{
Actions.Track(Analytics.Client);
FlushAndCheck(1);
}
[Test()]
public void AliasTestNet35()
{
Actions.Alias(Analytics.Client);
FlushAndCheck(1);
}
[Test()]
public void GroupTestNet35()
{
Actions.Group(Analytics.Client);
FlushAndCheck(1);
}
[Test()]
public void PageTestNet35()
{
Actions.Page(Analytics.Client);
FlushAndCheck(1);
}
[Test()]
public void ScreenTestNet35()
{
Actions.Screen(Analytics.Client);
FlushAndCheck(1);
}
private void FlushAndCheck(int messages)
{
Analytics.Client.Flush();
Assert.AreEqual(messages, Analytics.Client.Statistics.Submitted);
Assert.AreEqual(messages, Analytics.Client.Statistics.Succeeded);
Assert.AreEqual(0, Analytics.Client.Statistics.Failed);
}
static void LoggingHandler(Logger.Level level, string message, IDictionary<string, object> args)
{
if (args != null)
{
foreach (string key in args.Keys)
{
message += String.Format(" {0}: {1},", "" + key, "" + args[key]);
}
}
Console.WriteLine(String.Format("[ActionTests] [{0}] {1}", level, message));
}
}
}