Skip to content

Commit 8eb6dca

Browse files
committed
Fixing type so custom event pipeline providers can be used and adding test to validate they're getting used
1 parent 534acf2 commit 8eb6dca

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

Analytics-CSharp/Segment/Analytics/Configuration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public Configuration(string writeKey,
8585
IStorageProvider storageProvider = default,
8686
IHTTPClientProvider httpClientProvider = default,
8787
IList<IFlushPolicy> flushPolicies = default,
88-
EventPipelineProvider eventPipelineProvider = default)
88+
IEventPipelineProvider eventPipelineProvider = default)
8989
{
9090
WriteKey = writeKey;
9191
FlushAt = flushAt;

Tests/Utilities/EventPipelineTest.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,69 @@ public async Task TestFlushInterruptedWhenNoFileExist(IEventPipelineProvider pro
205205
_mockHttpClient.Verify(o => o.Upload(_bytes), Times.Exactly(0));
206206
_storage.Verify(o => o.RemoveFile(_file), Times.Exactly(0));
207207
}
208+
209+
[Theory]
210+
[MemberData(nameof(GetPipelineProvider))]
211+
public void TestConfigWithEventPipelineProviders(IEventPipelineProvider provider)
212+
{
213+
// Just validate that the provider is used in the configuration
214+
var config = new Configuration(
215+
writeKey: "123",
216+
autoAddSegmentDestination: false,
217+
useSynchronizeDispatcher: true,
218+
flushInterval: 0,
219+
flushAt: 2,
220+
httpClientProvider: new MockHttpClientProvider(_mockHttpClient),
221+
storageProvider: new MockStorageProvider(_storage),
222+
eventPipelineProvider: provider
223+
);
224+
var analytics = new Analytics(config);
225+
analytics.Track("test");
226+
}
227+
228+
[Fact]
229+
public void TestConfigWithCustomEventPipelineProvider()
230+
{
231+
// Just validate that the provider is used in the configuration
232+
var config = new Configuration(
233+
writeKey: "123",
234+
useSynchronizeDispatcher: true,
235+
flushInterval: 0,
236+
flushAt: 1,
237+
httpClientProvider: new MockHttpClientProvider(_mockHttpClient),
238+
storageProvider: new MockStorageProvider(_storage),
239+
eventPipelineProvider: new CustomEventPipelineProvider()
240+
);
241+
Assert.Throws<NotImplementedException>(() => {
242+
var analytics = new Analytics(config);
243+
analytics.Track("test");
244+
analytics.Flush();
245+
});
246+
}
247+
248+
249+
public class CustomEventPipelineProvider : IEventPipelineProvider
250+
{
251+
public CustomEventPipelineProvider()
252+
{
253+
}
254+
255+
public IEventPipeline Create(Analytics analytics, string key)
256+
{
257+
// Custom implementation
258+
return new CustomEventPipeline(analytics, key);
259+
}
260+
261+
private class CustomEventPipeline : IEventPipeline
262+
{
263+
public CustomEventPipeline(Analytics analytics, string key) {}
264+
public bool Running => throw new NotImplementedException();
265+
public string ApiHost { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
266+
public void Flush() => throw new NotImplementedException();
267+
public void Put(RawEvent @event) => throw new NotImplementedException();
268+
public void Start() => throw new NotImplementedException();
269+
public void Stop() => throw new NotImplementedException();
270+
}
271+
}
208272
}
209273
}

0 commit comments

Comments
 (0)