8000 feat: Added ODPManager implementation by mikechu-optimizely · Pull Request #322 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Added ODPManager implementation #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact it 8000 s 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 18 commits into from
Dec 7, 2022
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
118 changes: 118 additions & 0 deletions OptimizelySDK.Tests/OdpTests/OdpConfigTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*
* Copyright 2022 Optimizely
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using NUnit.Framework;
using OptimizelySDK.Odp;
using System.Collections.Generic;

namespace OptimizelySDK.Tests.OdpTests
{
[TestFixture]
public class OdpConfigTest
{
private const string API_KEY = "UrAp1k3Y";
private const string API_HOST = "https://not-real-odp-host.example.com";

private static readonly List<string> segmentsToCheck = new List<string>
{
"UPPER-CASE-AUDIENCE",
"lower-case-audience",
};

private readonly OdpConfig _goodOdpConfig =
new OdpConfig(API_KEY, API_HOST, segmentsToCheck);

[Test]
public void ShouldNotEqualWithNullInApiKey()
{
var nullKeyConfig =
new OdpConfig(null, API_HOST, segmentsToCheck);

Assert.IsFalse(_goodOdpConfig.Equals(nullKeyConfig));
Assert.IsFalse(nullKeyConfig.Equals(_goodOdpConfig));
}

[Test]
public void ShouldNotEqualWithNullInApiHost()
{
var nullHostConfig =
new OdpConfig(API_KEY, null, segmentsToCheck);

Assert.IsFalse(_goodOdpConfig.Equals(nullHostConfig));
Assert.IsFalse(nullHostConfig.Equals(_goodOdpConfig));
}

[Test]
public void ShouldNotEqualWithNullSegmentsCollection()
{
var nullSegmentsConfig =
new OdpConfig(API_KEY, API_HOST, null);

Assert.IsFalse(_goodOdpConfig.Equals(nullSegmentsConfig));
Assert.IsFalse(nullSegmentsConfig.Equals(_goodOdpConfig));
}

[Test]
public void ShouldNotEqualWithSegmentsWithNull()
{
var segmentsWithANullValue =
new OdpConfig(API_KEY, API_HOST, new List<string>
{
"good-value",
null,
});

Assert.IsFalse(_goodOdpConfig.Equals(segmentsWithANullValue));
Assert.IsFalse(segmentsWithANullValue.Equals(_goodOdpConfig));
}

[Test]
public void ShouldNotEqualIfCaseDifferenceInApiKey()
{
const string CASE_DIFFERENCE_IN_FIRST_LETTER_OF_API_KEY = "urAp1k3Y";
var apiKeyCaseDifferentConfig =
new OdpConfig(CASE_DIFFERENCE_IN_FIRST_LETTER_OF_API_KEY, API_HOST,
segmentsToCheck);

Assert.IsFalse(_goodOdpConfig.Equals(apiKeyCaseDifferentConfig));
Assert.IsFalse(apiKeyCaseDifferentConfig.Equals(_goodOdpConfig));
}

[Test]
public void ShouldEqualDespiteCaseDifferenceInApiHost()
{
var apiHostUpperCasedConfig =
new OdpConfig(API_KEY, API_HOST.ToUpper(), segmentsToCheck);

Assert.IsTrue(_goodOdpConfig.Equals(apiHostUpperCasedConfig));
Assert.IsTrue(apiHostUpperCasedConfig.Equals(_goodOdpConfig));
}

[Test]
public void ShouldEqualDespiteCaseDifferenceInSegments()
{
var wrongCaseSegmentsToCheck = new List<string>
{
"upper-case-audience",
"LOWER-CASE-AUDIENCE",
};
var wrongCaseConfig = new OdpConfig(API_KEY, API_HOST, wrongCaseSegmentsToCheck);

Assert.IsTrue(_goodOdpConfig.Equals(wrongCaseConfig));
Assert.IsTrue(wrongCaseConfig.Equals(_goodOdpConfig));
}
}
}
12 changes: 2 additions & 10 deletions OptimizelySDK.Tests/OdpTests/OdpEventManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,30 +480,22 @@ public void ShouldPrepareCorrectPayloadForIdentifyUser()
[Test]
public void ShouldApplyUpdatedOdpConfigurationWhenAvailable()
{
var apiKeyCollector = new List<string>();
var apiHostCollector = new List<string>();
var segmentsToCheckCollector = new List<List<string>>();
var apiKey = "testing-api-key";
var apiHost = "https://some.other.example.com";
var segmentsToCheck = new List<string>
{
"empty-cart",
"1-item-cart",
};
var mockOdpConfig = new Mock<OdpConfig>(API_KEY, API_HOST, segmentsToCheck);
mockOdpConfig.Setup(m => m.Update(Capture.In(apiKeyCollector),
Capture.In(apiHostCollector), Capture.In(segmentsToCheckCollector)));
var differentOdpConfig = new OdpConfig(apiKey, apiHost, segmentsToCheck);
var eventManager = new OdpEventManager.Builder().WithOdpConfig(mockOdpConfig.Object).
var eventManager = new OdpEventManager.Builder().WithOdpConfig(_odpConfig).
WithOdpEventApiManager(_mockApiManager.Object).
WithLogger(_mockLogger.Object).
Build();

eventManager.UpdateSettings(differentOdpConfig);

Assert.AreEqual(apiKey, apiKeyCollector[0]);
Assert.AreEqual(apiHost, apiHostCollector[0]);
Assert.AreEqual(segmentsToCheck, segmentsToCheckCollector[0]);
Assert.IsFalse(_odpConfig.Equals(eventManager._readOdpConfigForTesting()));
}

private static OdpEvent MakeEvent(int id) =>
Expand Down
Loading
0