|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Segment.Model; |
| 4 | + |
| 5 | +namespace Segment.Test |
| 6 | +{ |
| 7 | + public class Actions |
| 8 | + { |
| 9 | + private static Random random = new Random(); |
| 10 | + |
| 11 | + public static Properties Properties() |
| 12 | + { |
| 13 | + return new Properties() { |
| 14 | + { "Success", true }, |
| 15 | + { "When", DateTime.Now } |
| 16 | + }; |
| 17 | + } |
| 18 | + |
| 19 | + public static Traits Traits() |
| 20 | + { |
| 21 | + return new Traits() { |
| 22 | + { "Subscription Plan", "Free" }, |
| 23 | + { "Friends", 30 }, |
| 24 | + { "Joined", DateTime.Now }, |
| 25 | + { "Cool", true }, |
| 26 | + { "Company", new Dict () { { "name", "Initech, Inc " } } }, |
| 27 | + { "Revenue", 40.32 }, |
| 28 | + { "Don't Submit This, Kids", new UnauthorizedAccessException () } |
| 29 | + }; |
| 30 | + } |
| 31 | + |
| 32 | + public static Options Options() |
| 33 | + { |
| 34 | + return new Options() |
| 35 | + .SetTimestamp(DateTime.Now) |
| 36 | + .SetAnonymousId(Guid.NewGuid().ToString()) |
| 37 | + .SetIntegration("all", false) |
| 38 | + .SetIntegration("Mixpanel", true) |
| 39 | + .SetIntegration("Salesforce", true) |
| 40 | + .SetContext(new Context() |
| 41 | + .Add("ip", "12.212.12.49") |
| 42 | + .Add("language", "en-us") |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + public static void Identify(Client client) |
| 47 | + { |
| 48 | + client.Identify("user", Traits(), Options()); |
| 49 | + Analytics.Client.Flush(); |
| 50 | + } |
| 51 | + |
| 52 | + public static void Group(Client client) |
| 53 | + { |
| 54 | + client.Group("user", "group", Traits(), Options()); |
| 55 | + Analytics.Client.Flush(); |
| 56 | + } |
| 57 | + |
| 58 | + public static void Track(Client client) |
| 59 | + { |
| 60 | + client.Track("user", "Ran .NET test", Properties(), Options()); |
| 61 | + } |
| 62 | + |
| 63 | + public static void Alias(Client client) |
| 64 | + { |
| 65 | + client.Alias("previousId", "to"); |
| 66 | + } |
| 67 | + |
| 68 | + public static void Page(Client client) |
| 69 | + { |
| 70 | + client.Page("user", "name", "category", Properties(), Options()); |
| 71 | + } |
| 72 | + |
| 73 | + public static void Screen(Client client) |
| 74 | + { |
| 75 | + client.Screen("user", "name", "category", Properties(), Options()); |
| 76 | + } |
| 77 | + |
| 78 | + public static void Random(Client client) |
| 79 | + { |
| 80 | + switch (random.Next(0, 6)) |
| 81 | + { |
| 82 | + case 0: |
| 83 | + Identify(client); |
| 84 | + return; |
| 85 | + case 1: |
| 86 | + Track(client); |
| 87 | + return; |
| 88 | + case 2: |
| 89 | + Alias(client); |
| 90 | + return; |
| 91 | + case 3: |
| 92 | + Group(client); |
| 93 | + return; |
| 94 | + case 4: |
| 95 | + Page(client); |
| 96 | + return; |
| 97 | + case 5: |
| 98 | + Screen(client); |
| 99 | + return; |
| 100 | + } |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments