File tree Expand file tree Collapse file tree 2 files changed +31
-0
lines changed
Analytics-CSharp/Segment/Analytics Expand file tree Collapse file tree 2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 11using global ::System ;
22using Segment . Serialization ;
33
4+ #if NETSTANDARD2_0
5+ using System . Text . Json . Serialization ;
6+ #else
7+ using Newtonsoft . Json ;
8+ #endif
9+
410namespace Segment . Analytics
511{
612 public class DestinationMetadata
@@ -18,6 +24,7 @@ public abstract class RawEvent
1824 public virtual string UserId { get ; set ; }
1925 public virtual string Timestamp { get ; set ; }
2026
27+ [ JsonIgnore ]
2128 public Func < RawEvent , RawEvent > Enrichment { get ; set ; }
2229
2330 // JSON types
Original file line number Diff line number Diff line change @@ -254,6 +254,30 @@ public async Task TestStoreEvent()
254254 Assert . Null ( exception ) ;
255255 }
256256
257+ [ Fact ]
258+ public async Task TestStoreEventWithEnrichment ( )
259+ {
260+ TrackEvent trackEvent = new TrackEvent ( "clicked" , new JsonObject { [ "foo" ] = "bar" } ) ;
261+ trackEvent . Enrichment = @event =>
262+ {
263+ return @event ;
264+ } ;
265+ string payloadWithEnrichment = JsonUtility . ToJson ( trackEvent ) ;
266+ await _storage . Write ( StorageConstants . Events , payloadWithEnrichment ) ;
267+ await _storage . Rollover ( ) ;
268+
269+ string path = _dir + Path . DirectorySeparatorChar + _writeKey + "-0.json" ;
270+ string actual = File . ReadAllText ( path ) ;
271+ Exception exception = Record . Exception ( ( ) =>
272+ {
273+ JsonUtility . FromJson < JsonObject > ( actual ) ;
274+ } ) ;
275+
276+ Assert . True ( File . Exists ( path ) ) ;
277+ Assert . Contains ( _payload , actual ) ;
278+ Assert . Null ( exception ) ;
279+ }
280+
257281 [ Fact ]
258282 public async Task TestRead ( )
259283 {
You can’t perform that action at this time.
0 commit comments