private void CheckIdentifyEvent(object e, User u) { IdentifyEvent ie = Assert.IsType <IdentifyEvent>(e); Assert.Equal(u.Key, ie.User.Key); Assert.NotEqual(0, ie.Timestamp.Value); }
private void TestInlineUserSerialization(User user, LdValue expectedJsonValue, EventsConfiguration config) { config.InlineUsersInEvents = true; var f = new EventOutputFormatter(config); var evalEvent = new EvaluationEvent { FlagKey = "flag", User = user }; var outputEvent = SerializeOneEvent(f, evalEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.Equal(user.Anonymous ? LdValue.Of("anonymousUser") : LdValue.Null, outputEvent.Get("contextKind")); var identifyEvent = new IdentifyEvent { User = user }; outputEvent = SerializeOneEvent(f, identifyEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.False(outputEvent.Dictionary.ContainsKey("contextKind")); var customEvent = new CustomEvent { EventKey = "customkey", User = user }; outputEvent = SerializeOneEvent(f, customEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.Equal(user.Anonymous ? LdValue.Of("anonymousUser") : LdValue.Null, outputEvent.Get("contextKind")); var indexEvent = new IndexEvent { User = user }; outputEvent = SerializeOneEvent(f, indexEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(expectedJsonValue, outputEvent.Get("user")); Assert.False(outputEvent.Dictionary.ContainsKey("contextKind")); }
public void UserKeyIsSetInsteadOfUserWhenNotInlined() { var user = User.Builder("userkey") .Name("me") .Build(); var userJson = LdValue.Parse(@"{""key"":""userkey"",""name"":""me""}"); var f = new EventOutputFormatter(new EventsConfiguration()); var evalEvent = new EvaluationEvent { FlagKey = "flag", User = user }; var outputEvent = SerializeOneEvent(f, evalEvent); Assert.Equal(LdValue.Null, outputEvent.Get("user")); Assert.Equal(user.Key, outputEvent.Get("userKey").AsString); // user is always inlined in identify event var identifyEvent = new IdentifyEvent { User = user }; outputEvent = SerializeOneEvent(f, identifyEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(userJson, outputEvent.Get("user")); var customEvent = new CustomEvent { EventKey = "customkey", User = user }; outputEvent = SerializeOneEvent(f, customEvent); Assert.Equal(LdValue.Null, outputEvent.Get("user")); Assert.Equal(user.Key, outputEvent.Get("userKey").AsString); // user is always inlined in index event var indexEvent = new IndexEvent { Timestamp = _fixedTimestamp, User = user }; outputEvent = SerializeOneEvent(f, indexEvent); Assert.Equal(LdValue.Null, outputEvent.Get("userKey")); Assert.Equal(userJson, outputEvent.Get("user")); }
private void CheckIdentifyEvent(Event e, User user) { IdentifyEvent ie = Assert.IsType <IdentifyEvent>(e); Assert.Equal(user.Key, ie.Key); Assert.Equal(user, ie.User); }
private void CheckIdentifyEvent(JToken t, IdentifyEvent ie, JToken userJson) { JObject o = t as JObject; Assert.Equal("identify", (string)o["kind"]); Assert.Equal(ie.CreationDate, (long)o["creationDate"]); TestUtil.AssertJsonEquals(userJson, o["user"]); }
public void IdentifyEventIsSerialized() { var user = User.Builder("userkey").Name("me").Build(); var ie = new IdentifyEvent { Timestamp = _fixedTimestamp, User = user }; TestEventSerialization(ie, LdValue.Parse(@"{ ""kind"":""identify"", ""creationDate"":100000, ""key"":""userkey"", ""user"":{""key"":""userkey"",""name"":""me""} }")); }
public void IdentifyEventCanHaveNullUser() { _ep = MakeProcessor(_config); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(null); _ep.SendEvent(e); JArray output = FlushAndGetEvents(OkResponse()); Assert.Collection(output, item => CheckIdentifyEvent(item, e, null)); }
public void IdentifyEventIsQueued() { _ep = MakeProcessor(_config); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(_user); _ep.SendEvent(e); JArray output = FlushAndGetEvents(OkResponse()); Assert.Collection(output, item => CheckIdentifyEvent(item, e, _userJson)); }
public void UserDetailsAreScrubbedInIdentifyEvent() { _config.AllAttributesPrivate = true; _ep = MakeProcessor(_config); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(_user); _ep.SendEvent(e); JArray output = FlushAndGetEvents(OkResponse()); Assert.Collection(output, item => CheckIdentifyEvent(item, e, _scrubbedUserJson)); }
public void FinalFlushIsDoneOnDispose() { _ep = MakeProcessor(_config); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(_user); _ep.SendEvent(e); PrepareResponse(OkResponse()); _ep.Dispose(); JArray output = GetLastRequest().BodyAsJson as JArray; Assert.Collection(output, item => CheckIdentifyEvent(item, e, _userJson)); }
public void FinalFlushIsDoneOnDispose() { _ep = MakeProcessor(_config); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(_user); _ep.SendEvent(e); PrepareResponse(OkResponse()); _ep.Dispose(); var bodyStr = JsonConvert.SerializeObject(GetLastRequest().BodyAsJson); var output = LdValue.Parse(bodyStr).AsList(LdValue.Convert.Json); Assert.Collection(output, item => CheckIdentifyEvent(item, e, _userJson)); }
public void FlushDoesNothingWhenOffline() { using (var ep = MakeProcessor(_config)) { ep.SetOffline(true); IdentifyEvent e = EventFactory.Default.NewIdentifyEvent(_user); ep.SendEvent(e); ep.Flush(); // We can't prove a negative - there's no way to know when the event processor has definitely // decided *not* to do a flush, it is asynchronous, so this is just a best-guess delay. Thread.Sleep(TimeSpan.FromMilliseconds(500)); Assert.Equal(0, _server.LogEntries.Count()); // We should have still held on to that event, so if we go online again and flush, it is sent. ep.SetOffline(false); var output = FlushAndGetEvents(OkResponse(), ep); Assert.Collection(output, item => CheckIdentifyEvent(item, e, _userJson)); } }
private void CheckIdentifyEvent(LdValue t, IdentifyEvent ie, LdValue userJson) { Assert.Equal(LdValue.Of("identify"), t.Get("kind")); Assert.Equal(LdValue.Of(ie.CreationDate), t.Get("creationDate")); Assert.Equal(userJson, t.Get("user")); }
public void RecordIdentifyEvent(IdentifyEvent e) => SubmitMessage(new EventProcessorInternal.EventMessage(e));