diff --git a/OptimizelySDK.Tests/OptimizelyTest.cs b/OptimizelySDK.Tests/OptimizelyTest.cs index b4c0a39c..367b1fc9 100644 --- a/OptimizelySDK.Tests/OptimizelyTest.cs +++ b/OptimizelySDK.Tests/OptimizelyTest.cs @@ -6183,6 +6183,16 @@ public void TestSendOdpEventNullAction() optly.Dispose(); } + [Test] + public void TestSendOdpEventInvalidOptimizelyObject() + { + var optly = new Optimizely("Random datafile", null, LoggerMock.Object); + optly.SendOdpEvent("some_action", new Dictionary() { { "some_key", "some_value" } }, "some_event"); + LoggerMock.Verify( + l => l.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'SendOdpEvent'."), + Times.Once); + } + [Test] public void TestSendOdpEventEmptyStringAction() { @@ -6193,6 +6203,7 @@ public void TestSendOdpEventEmptyStringAction() optly.Dispose(); } + [Test] public void TestSendOdpEventNullType() { @@ -6226,5 +6237,33 @@ public void TestSendOdpEventEmptyStringType() } #endregion Test SendOdpEvent + + #region Test FetchQualifiedSegments + + [Test] + public void TestFetchQualifiedSegmentsInvalidOptimizelyObject() + { + var optly = new Optimizely("Random datafile", null, LoggerMock.Object); + optly.FetchQualifiedSegments("some_user", null); + LoggerMock.Verify( + l => l.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'FetchQualifiedSegments'."), + Times.Once); + } + + #endregion Test FetchQualifiedSegments + + #region Test IdentifyUser + + [Test] + public void TestIdentifyUserInvalidOptimizelyObject() + { + var optly = new Optimizely("Random datafile", null, LoggerMock.Object); + optly.IdentifyUser("some_user"); + LoggerMock.Verify( + l => l.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'IdentifyUser'."), + Times.Once); + } + + #endregion Test IdentifyUser } } diff --git a/OptimizelySDK/Optimizely.cs b/OptimizelySDK/Optimizely.cs index 0c5a7070..f705c396 100644 --- a/OptimizelySDK/Optimizely.cs +++ b/OptimizelySDK/Optimizely.cs @@ -1339,6 +1339,14 @@ internal string[] FetchQualifiedSegments(string userId, List segmentOptions ) { + var config = ProjectConfigManager?.GetConfig(); + + if (config == null) + { + Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'FetchQualifiedSegments'."); + return null; + } + return OdpManager?.FetchQualifiedSegments(userId, segmentOptions); } @@ -1348,6 +1356,14 @@ List segmentOptions /// FS User ID to send internal void IdentifyUser(string userId) { + var config = ProjectConfigManager?.GetConfig(); + + if (config == null) + { + Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'IdentifyUser'."); + return; + } + OdpManager?.IdentifyUser(userId); } @@ -1373,6 +1389,14 @@ public void SendOdpEvent(string action, Dictionary identifiers, type = Constants.ODP_EVENT_TYPE; } + var config = ProjectConfigManager?.GetConfig(); + + if (config == null) + { + Logger.Log(LogLevel.ERROR, "Datafile has invalid format. Failing 'SendOdpEvent'."); + return; + } + OdpManager?.SendEvent(type, action, identifiers, data); } #endif