8000 feat: Fix NotificationCenter Issue for ODPManager by mikechu-optimizely · Pull Request #324 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Fix NotificationCenter Issue for ODPManager #324

New issue < 8000 details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast overflow-auto" aria-label="Sign up for GitHub">

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
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix OdpEventManager & tests
  • Loading branch information
mikechu-optimizely committed Jan 12, 2023
commit 1f094220d59dbb03eda65d151f9bf9f7832ff32c
27 changes: 15 additions & 12 deletions OptimizelySDK.Tests/OdpTests/OdpEventManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ public void ShouldLogAndDiscardEventsWhenEventManagerNotRunning()
var eventManager = new OdpEventManager.Builder().
WithOdpEventApiManager(_mockApiManager.Object).
WithLogger(_mockLogger.Object).
Build(startImmediately: false);
WithAutoStart(false).
Build();
eventManager.UpdateSettings(_odpConfig);

// since we've not called Start() then...
Expand All @@ -178,33 +179,34 @@ public void ShouldLogAndDiscardEventsWhenEventManagerConfigNotReady()
var eventManager = new OdpEventManager.Builder().
WithOdpEventApiManager(_mockApiManager.Object).
WithLogger(_mockLogger.Object).
Build(startImmediately: false); // start manually in Act; Log once here
WithAutoStart(false). // start manually in Act
Build();
eventManager.UpdateSettings(mockOdpConfig.Object);

eventManager.Start(); // Log when Start() called
eventManager.SendEvent(_testEvents[0]); // Log when enqueue attempted

_mockLogger.Verify(
l => l.Log(LogLevel.WARN, Constants.ODP_NOT_INTEGRATED_MESSAGE),
Times.Exactly(3));
Times.Exactly(2));
}

[Test]
public void ShouldLogWhenOdpNotIntegratedAndIdentifyUserCalled()
{
var mockOdpConfig = new Mock<OdpConfig>(API_KEY, API_HOST, _emptySegmentsToCheck);
mockOdpConfig.Setup(o => o.IsReady()).Returns(false);
mockOdpConfig.Setup(o => o.IsReady()).Returns(false); // never ready
var eventManager = new OdpEventManager.Builder().
WithOdpEventApiManager(_mockApiManager.Object).
WithLogger(_mockLogger.Object).
Build();
eventManager.UpdateSettings(mockOdpConfig.Object);
Build(); // assumed AutoStart true; Logs 1x here
eventManager.UpdateSettings(mockOdpConfig.Object); // auto-start after update; Logs 1x here

eventManager.IdentifyUser(FS_USER_ID);
eventManager.IdentifyUser(FS_USER_ID); // Logs 1x here too

_mockLogger.Verify(
l => l.Log(LogLevel.WARN, Constants.ODP_NOT_INTEGRATED_MESSAGE),
Times.Exactly(2)); // during Start() and SendEvent()
Times.Exactly(3)); // during Start() and SendEvent()
}

[Test]
Expand All @@ -215,13 +217,14 @@ public void ShouldLogWhenOdpNotIntegratedAndStartCalled()
var eventManager = new OdpEventManager.Builder().
WithOdpEventApiManager(_mockApiManager.Object).
WithLogger(_mockLogger.Object).
Build(startImmediately: false); // doing it manually in Act next; Log once
eventManager.UpdateSettings(mockOdpConfig.Object);
WithAutoStart(false). // doing it manually in Act next
Build();
eventManager.UpdateSettings(mockOdpConfig.Object);

eventManager.Start(); // Log again
eventManager.Start(); // Log 1x here too

_mockLogger.Verify(l => l.Log(LogLevel.WARN, Constants.ODP_NOT_INTEGRATED_MESSAGE),
Times.Exactly(2));
Times.Once);
}

[Test]
Expand Down
10 changes: 3 additions & 7 deletions OptimizelySDK/Odp/OdpEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -359,15 +359,11 @@ public void UpdateSettings(OdpConfig odpConfig)
return;
}

if (_odpConfig == null)
{
_odpConfig = odpConfig;
_odpConfig = odpConfig;

Start();
}
else
if (_autoStart)
{
_odpConfig = odpConfig;
Start();
}
}

Expand Down
0