File tree 2 files changed +31
-0
lines changed
Analytics-CSharp/Segment/Analytics
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 1
1
using global ::System ;
2
2
using Segment . Serialization ;
3
3
4
+ #if NETSTANDARD2_0
5
+ using System . Text . Json . Serialization ;
6
+ #else
7
+ using Newtonsoft . Json ;
8
+ #endif
9
+
4
10
namespace Segment . Analytics
5
11
{
6
12
public class DestinationMetadata
@@ -18,6 +24,7 @@ public abstract class RawEvent
18
24
public virtual string UserId { get ; set ; }
19
25
public virtual string Timestamp { get ; set ; }
20
26
27
+ [ JsonIgnore ]
21
28
public Func < RawEvent , RawEvent > Enrichment { get ; set ; }
22
29
23
30
// JSON types
Original file line number Diff line number Diff line change @@ -254,6 +254,30 @@ public async Task TestStoreEvent()
254
254
Assert . Null ( exception ) ;
255
255
}
256
256
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
+
257
281
[ Fact ]
258
282
public async Task TestRead ( )
259
283
{
You can’t perform that action at this time.
0 commit comments