Skip to content
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
39 changes: 39 additions & 0 deletions OptimizelySDK.Tests/OptimizelyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>() { { "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()
{
Expand All @@ -6193,6 +6203,7 @@ public void TestSendOdpEventEmptyStringAction()

optly.Dispose();
}

[Test]
public void TestSendOdpEventNullType()
{
Expand Down Expand Up @@ -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
}
}
24 changes: 24 additions & 0 deletions OptimizelySDK/Optimizely.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1339,6 +1339,14 @@ internal string[] FetchQualifiedSegments(string userId,
List<OdpSegmentOption> 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);
}

Expand All @@ -1348,6 +1356,14 @@ List<OdpSegmentOption> segmentOptions
/// <param name="userId">FS User ID to send</param>
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);
}

Expand All @@ -1373,6 +1389,14 @@ public void SendOdpEvent(string action, Dictionary<string, string> 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
Expand Down