Skip to content

fix: error handler not raise exception while using optimizelyfactory #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion OptimizelySDK.Tests/OptimizelyFactoryTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,17 @@ public void TestEventProcessorWithBatchEventProcessorObj()
Assert.AreEqual(actualEventProcessorProps, expectedEventProcessorProps);
optimizely.Dispose();
}
}

[Test]
public void TestGetFeatureVariableJSONEmptyDatafileTest()
{
var httpClientMock = new Mock<HttpProjectConfigManager.HttpClient>();
var task = TestHttpProjectConfigManagerUtil.MockSendAsync(httpClientMock, TestData.EmptyDatafile, TimeSpan.Zero, System.Net.HttpStatusCode.OK);
TestHttpProjectConfigManagerUtil.SetClientFieldValue(httpClientMock.Object);

var optimizely = OptimizelyFactory.NewDefaultInstance("sdk-key");
Assert.Null(optimizely.GetFeatureVariableJSON("no-feature-variable", "no-variable-key", "userId"));
optimizely.Dispose();
}
}
}
1 change: 1 addition & 0 deletions OptimizelySDK.Tests/OptimizelySDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<EmbeddedResource Include="TestData.json" />
<EmbeddedResource Include="simple_ab_experiments.json" />
<EmbeddedResource Include="EmptyRolloutRule.json" />
<EmbeddedResource Include="emptydatafile.json" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OptimizelySDK\OptimizelySDK.csproj">
Expand Down
9 changes: 8 additions & 1 deletion OptimizelySDK.Tests/Utils/TestData.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2019, Optimizely
* Copyright 2017-2020, Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@ public class TestData
private static string unsupportedVersionDatafile = null;
private static string typedAudienceDatafile = null;
private static string emptyRolloutDatafile = null;
private static string emptyDatafile = null;

public static string Datafile
{
Expand Down Expand Up @@ -59,6 +60,12 @@ public static string EmptyRolloutDatafile {
}
}

public static string EmptyDatafile {
get {
return emptyDatafile ?? (emptyDatafile = LoadJsonData("emptydatafile.json"));
}
}

public static string TypedAudienceDatafile
{
get
Expand Down
15 changes: 15 additions & 0 deletions OptimizelySDK.Tests/emptydatafile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "4",
"rollouts": [],
"anonymizeIP": true,
"projectId": "10431130345",
"variables": [],
"featureFlags": [],
"experiments": [],
"audiences": [],
"groups": [],
"attributes": [],
"accountId": "10367498574",
"events": [],
"revision": "241"
}
6 changes: 3 additions & 3 deletions OptimizelySDK/OptimizelyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public static Optimizely NewDefaultInstance()

if (httpProjectConfigElement == null) return null;

var errorHandler = new DefaultErrorHandler();
var errorHandler = new DefaultErrorHandler(logger, false);
var eventDispatcher = new DefaultEventDispatcher(logger);
var builder = new HttpProjectConfigManager.Builder();
var notificationCenter = new NotificationCenter();
Expand Down Expand Up @@ -119,7 +119,7 @@ public static Optimizely NewDefaultInstance(string sdkKey)
public static Optimizely NewDefaultInstance(string sdkKey, string fallback, string datafileAuthToken)
{
var logger = OptimizelyLogger ?? new DefaultLogger();
var errorHandler = new DefaultErrorHandler();
var errorHandler = new DefaultErrorHandler(logger, false);
var eventDispatcher = new DefaultEventDispatcher(logger);
var builder = new HttpProjectConfigManager.Builder();
var notificationCenter = new NotificationCenter();
Expand Down Expand Up @@ -151,7 +151,7 @@ public static Optimizely NewDefaultInstance(string sdkKey, string fallback, stri
public static Optimizely NewDefaultInstance(string sdkKey, string fallback)
{
var logger = OptimizelyLogger ?? new DefaultLogger();
var errorHandler = new DefaultErrorHandler();
var errorHandler = new DefaultErrorHandler(logger, false);
var eventDispatcher = new DefaultEventDispatcher(logger);
var builder = new HttpProjectConfigManager.Builder();
var notificationCenter = new NotificationCenter();
Expand Down