Skip to content

Commit 4dd55e2

Browse files
msohailhussainMichael Ng
andauthored
fix: error handler not raise exception while using optimizelyfactory (#241)
* error handler not raise exception while using optimizelyfactory * nit fix Co-authored-by: Michael Ng <[email protected]>
1 parent 38e82b2 commit 4dd55e2

File tree

5 files changed

+39
-5
lines changed

5 files changed

+39
-5
lines changed

OptimizelySDK.Tests/OptimizelyFactoryTest.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ public void TestEventProcessorWithBatchEventProcessorObj()
193193
Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps);
194194
optimizely.Dispose();
195195
}
196-
}
197196

197+
[Test]
198+
public void TestGetFeatureVariableJSONEmptyDatafileTest()
199+
{
200+
var httpClientMock = new Mock<HttpProjectConfigManager.HttpClient>();
201+
var task = TestHttpProjectConfigManagerUtil.MockSendAsync(httpClientMock, TestData.EmptyDatafile, TimeSpan.Zero, System.Net.HttpStatusCode.OK);
202+
TestHttpProjectConfigManagerUtil.SetClientFieldValue(httpClientMock.Object);
203+
204+
var optimizely = OptimizelyFactory.NewDefaultInstance("sdk-key");
205+
Assert.Null(optimizely.GetFeatureVariableJSON("no-feature-variable", "no-variable-key", "userId"));
206+
optimizely.Dispose();
207+
}
208+
}
198209
}

OptimizelySDK.Tests/OptimizelySDK.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<EmbeddedResource Include="TestData.json" />
121121
<EmbeddedResource Include="simple_ab_experiments.json" />
122122
<EmbeddedResource Include="EmptyRolloutRule.json" />
123+
<EmbeddedResource Include="emptydatafile.json" />
123124
</ItemGroup>
124125
<ItemGroup>
125126
<ProjectReference Include="..\OptimizelySDK\OptimizelySDK.csproj">

OptimizelySDK.Tests/Utils/TestData.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2019, Optimizely
2+
* Copyright 2017-2020, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@ public class TestData
2828
private static string unsupportedVersionDatafile = null;
2929
private static string typedAudienceDatafile = null;
3030
private static string emptyRolloutDatafile = null;
31+
private static string emptyDatafile = null;
3132

3233
public static string Datafile
3334
{
@@ -59,6 +60,12 @@ public static string EmptyRolloutDatafile {
5960
}
6061
}
6162

63+
public static string EmptyDatafile {
64+
get {
65+
return emptyDatafile ?? (emptyDatafile = LoadJsonData("emptydatafile.json"));
66+
}
67+
}
68+
6269
public static string TypedAudienceDatafile
6370
{
6471
get
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"version": "4",
3+
"rollouts": [],
4+
"anonymizeIP": true,
5+
"projectId": "10431130345",
6+
"variables": [],
7+
"featureFlags": [],
8+
"experiments": [],
9+
"audiences": [],
10+
"groups": [],
11+
"attributes": [],
12+
"accountId": "10367498574",
13+
"events": [],
14+
"revision": "241"
15+
}

OptimizelySDK/OptimizelyFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static Optimizely NewDefaultInstance()
7272

7373
if (httpProjectConfigElement == null) return null;
7474

75-
var errorHandler = new DefaultErrorHandler();
75+
var errorHandler = new DefaultErrorHandler(logger, false);
7676
var eventDispatcher = new DefaultEventDispatcher(logger);
7777
var builder = new HttpProjectConfigManager.Builder();
7878
var notificationCenter = new NotificationCenter();
@@ -119,7 +119,7 @@ public static Optimizely NewDefaultInstance(string sdkKey)
119119
public static Optimizely NewDefaultInstance(string sdkKey, string fallback, string datafileAuthToken)
120120
{
121121
var logger = OptimizelyLogger ?? new DefaultLogger();
122-
var errorHandler = new DefaultErrorHandler();
122+
var errorHandler = new DefaultErrorHandler(logger, false);
123123
var eventDispatcher = new DefaultEventDispatcher(logger);
124124
var builder = new HttpProjectConfigManager.Builder();
125125
var notificationCenter = new NotificationCenter();
@@ -151,7 +151,7 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback, stri
151151
public static Optimizely NewDefaultInstance(string sdkKey, string fallback)
152152
{
153153
var logger = OptimizelyLogger ?? new DefaultLogger();
154-
var errorHandler = new DefaultErrorHandler();
154+
var errorHandler = new DefaultErrorHandler(logger, false);
155155
var eventDispatcher = new DefaultEventDispatcher(logger);
156156
var builder = new HttpProjectConfigManager.Builder();
157157
var notificationCenter = new NotificationCenter();

0 commit comments

Comments
 (0)