private void CheckAliasEvent(LdValue t, AliasEvent ae)
 {
     Assert.Equal(LdValue.Of("alias"), t.Get("kind"));
     Assert.Equal(LdValue.Of(ae.Key), t.Get("key"));
     Assert.Equal(LdValue.Of(ae.PreviousKey), t.Get("previousKey"));
     Assert.Equal(LdValue.Of(ae.ContextKind.ToIdentifier()), t.Get("contextKind"));
     Assert.Equal(LdValue.Of(ae.PreviousContextKind.ToIdentifier()), t.Get("previousContextKind"));
 }
Пример #2
0
        public void AliasSendsAliasEvent()
        {
            User oldUser = User.Builder("anon-key").Anonymous(true).Build();
            User newUser = User.WithKey("real-key");

            using (LdClient client = MakeClient(user))
            {
                client.Alias(user, oldUser);
                Assert.Collection(eventProcessor.Events,
                                  e => CheckIdentifyEvent(e, user),
                                  e => {
                    AliasEvent ae = Assert.IsType <AliasEvent>(e);
                    Assert.Equal(user, ae.User);
                    Assert.Equal(oldUser, ae.PreviousUser);
                    Assert.NotEqual(0, ae.Timestamp.Value);
                });
            }
        }
 public void AliasEventIsSerialized()
 {
     var ae = new AliasEvent
     {
         Timestamp = _fixedTimestamp,
         Key = "newkey",
         PreviousKey = "oldkey",
         ContextKind = ContextKind.User,
         PreviousContextKind = ContextKind.AnonymousUser
     };
     TestEventSerialization(ae, LdValue.Parse(@"{
         ""kind"":""alias"",
         ""creationDate"":100000,
         ""key"":""newkey"",
         ""previousKey"":""oldkey"",
         ""contextKind"":""user"",
         ""previousContextKind"":""anonymousUser""
         }"));
 }
Пример #4
0
        public void IdentifySendsAliasEventFromAnonUserToNonAnonUserIfNotOptedOut()
        {
            User oldUser = User.Builder("anon-key").Anonymous(true).Build();
            User newUser = User.WithKey("real-key");

            using (LdClient client = MakeClient(oldUser))
            {
                User actualOldUser = client.User; // so we can get any automatic properties that the client added
                client.Identify(newUser, TimeSpan.FromSeconds(1));

                Assert.Collection(eventProcessor.Events,
                                  e => CheckIdentifyEvent(e, actualOldUser),
                                  e => CheckIdentifyEvent(e, newUser),
                                  e => {
                    AliasEvent ae = Assert.IsType <AliasEvent>(e);
                    Assert.Equal(newUser, ae.User);
                    Assert.Equal(actualOldUser, ae.PreviousUser);
                    Assert.NotEqual(0, ae.Timestamp.Value);
                });
            }
        }
        public void AliasEventIsQueued()
        {
            var mockSender = MakeMockSender();
            var captured   = EventCapture.From(mockSender);

            using (var ep = MakeProcessor(_config, mockSender))
            {
                var ae = new AliasEvent
                {
                    Timestamp           = _fixedTimestamp,
                    Key                 = "newkey",
                    PreviousKey         = "oldkey",
                    ContextKind         = ContextKind.User,
                    PreviousContextKind = ContextKind.AnonymousUser
                };
                ep.RecordAliasEvent(ae);
                FlushAndWait(ep);

                Assert.Collection(captured.Events,
                                  item => CheckAliasEvent(item, ae));
            }
        }
Пример #6
0
        public void Play()
        {
            AliasEvent.Invoke("We are playing alias...");

            List <string> cardsSet   = new List <string>(100);
            int           teamsCount = _playersCount % 2 == 0 ? (_playersCount / 2) : (_playersCount / 2 - 1);

            int[]  players = new int[teamsCount];
            Random rand    = new Random(DateTime.Now.Millisecond);

            foreach (string el in (File.ReadAllText("words.txt").Split(' ')))
            {
                cardsSet.Add(el);
            }

            AliasEvent.Invoke($"Teams count - {teamsCount}");

            while (players.Max() != 50)
            {
                for (int i = 0; i < teamsCount; i++)
                {
                    AliasEvent.Invoke($"Team {i} is moving. The word is {cardsSet.ElementAt(rand.Next(0, cardsSet.Count - 1))}");
                    if (rand.Next(-5, 10) < 0)
                    {
                        AliasEvent.Invoke($"Player didn't guess the word");
                        players[i]--;
                    }
                    else
                    {
                        AliasEvent.Invoke($"Player guess the word");
                        players[i]++;
                    }
                }
            }

            AliasEvent.Invoke($"Game ends. Team {players.ToList().IndexOf(players.Max())} is winner!");
        }
 public void RecordAliasEvent(AliasEvent e) =>
 SubmitMessage(new EventProcessorInternal.EventMessage(e));