10000 feat: Integrated ODPManager with UserContext and Optimizely client by mikechu-optimizely · Pull Request #323 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat: Integrated ODPManager with UserContext and Optimizely client #323

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 69 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
57b6927
Include ODP Manager instantiation in Optimizely.cs
mikechu-optimizely Dec 8, 2022
3f27cfe
Add FetchQualifiedSegments to Optimizely.cs
mikechu-optimizely Dec 8, 2022
040138c
Add FetchQualifiedSegments to UserContext
mikechu-optimizely Dec 8, 2022
bf9005a
Add IdentifyUser, fetch segments callback, & docs
mikechu-optimizely Dec 9, 2022
d58a5a9
WIP existing test fixes
mikechu-optimizely Dec 9, 2022
65512ac
Fix legacy test (mock) constructors
mikechu-optimizely Dec 9, 2022
6e498d8
Add SendOdpEvent to Optimizely
mikechu-optimizely Dec 12, 2022
e7579cf
WIP Init OdpManager
mikechu-optimizely Dec 13, 2022
9a487bc
WIP Add OptimizelySdkSettings & fix some legacy tests
mikechu-optimizely Dec 14, 2022
3c8fc1c
WIP fixes
mikechu-optimizely Dec 14, 2022
0a79a42
Remove early UpdateOdpSettings
mikechu-optimizely Dec 15, 2022
0212708
Add internal accessor for ProjectConfig Segments
mikechu-optimizely Dec 15, 2022
d99e2cb
Linter fixes
mikechu-optimizely Dec 15, 2022
3f29686
Preprocessing conditional compilation directives
mikechu-optimizely Dec 15, 2022
002b115
Add Segments array to ProjectConfig
mikechu-optimizely Dec 15, 2022
4edb545
Lint corrections
mikechu-optimizely Dec 15, 2022
e4fbd0d
More linter fixes
mikechu-optimizely Dec 15, 2022
2f15f8d
WIP PR review changes
mikechu-optimizely Dec 15, 2022
19bac38
Lint fix
mikechu-optimizely Dec 15, 2022
8000
bc75c20
Lint fix
mikechu-optimizely Dec 16, 2022
3aa85d5
Add async FetchQualifiedSegments
mikechu-optimizely Dec 16, 2022
6e818b9
WIP parse TypedAudience to ODP Segments
mikechu-optimizely Dec 16, 2022
4a0deea
WIP parsing Segments
mikechu-optimizely Dec 20, 2022
06f4a6a
More ODP test datafile more scenarios
mikechu-optimizely Dec 21, 2022
e7fec76
Revert IMultipleConditions concept
mikechu-optimizely Dec 21, 2022
dd16f7c
Correct Segments from datafile
mikechu-optimizely Dec 21, 2022
de7c5aa
Lint fix
mikechu-optimizely Dec 21, 2022
00260a4
Add segment unit tests
mikechu-optimizely Dec 21, 2022
519ee78
WIP satisfying legacy tests
mikechu-optimizely Dec 21, 2022
516cff2
Remove Ignore from legacy tests
mikechu-optimizely Dec 22, 2022
3b00476
Finalize SetupOdp; add Dispose to OptimizelyUserContext
mikechu-optimizely Dec 27, 2022
3eaf48f
Add missing preprocessing conditions
mikechu-optimizely Dec 27, 2022
e132807
Fix linting
mikechu-optimizely Dec 27, 2022
0aad28c
PR code review updates
mikechu-optimizely Jan 3, 2023
3dde070
Lint fixes
mikechu-optimizely Jan 3, 2023
c68eea9
feat: Fix NotificationCenter Issue for ODPManager (#324)
mikechu-optimizely Jan 18, 2023
5604d6d
Lint fixes + Copyright year updates
mikechu-optimizely Jan 18, 2023
3903532
Lint fix PollingProjectConfigManager
mikechu-optimizely Jan 18, 2023
0d7da83
Trying to fix TestPollingConfigManagerBlocksWhenProjectConfigIsNotPro…
mikechu-optimizely Jan 18, 2023
27d30e5
Another attempt to figure out TestPollingConfigManagerBlocksWhenProje…
mikechu-optimizely Jan 18, 2023
52451ca
Update OptimizelySDK/Config/PollingProjectConfigManager.cs
mikechu-optimizely Jan 20, 2023
9f2db6e
Update OptimizelySDK/Config/HttpProjectConfigManager.cs
mikechu-optimizely Jan 20, 2023
c5a3ead
Update OptimizelySDK/Config/FallbackProjectConfigManager.cs
mikechu-optimizely Jan 20, 2023
c273a4b
Update OptimizelySDK/Config/FallbackProjectConfigManager.cs
mikechu-optimizely Jan 20, 2023
6a4a044
Implement a NoOpOdpManager
mikechu-optimizely Jan 20, 2023
b4ba4b0
Remove configurable batch size for OdpEventManager
mikechu-optimizely Jan 20, 2023
ca207f0
Fix lint (Mike not happy)
mikechu-optimizely Jan 20, 2023
8053e44
OMG Linter needs config
mikechu-optimizely Jan 20, 2023
361511f
Split condition for UpdateSettings & NotificationCenterRegistry add
mikechu-optimizely Jan 20, 2023
4e5b652
Remove optional chaining
mikechu-optimizely Jan 20, 2023
7ea0856
PR review changes
mikechu-optimizely Jan 23, 2023
016680b
Fix InternalsVisibleTo & use internal for testing
mikechu-optimizely Jan 23, 2023
0206a74
PR change requests
mikechu-optimizely Jan 23, 2023
50d1a96
Add unit test for defaults from OdpManager & below
mikechu-optimizely Jan 23, 2023
f61d05b
Remove NoOpOdpManager & default OdpManager instantiation
mikechu-optimizely Jan 23, 2023
47562aa
Lint fixes
mikechu-optimizely Jan 23, 2023
1bb4b1c
Allow signed + assigned friend assemblies
mikechu-optimizely Jan 23, 2023
a05a49c
Use pubkey of OptimizelySDK.Tests
mikechu-optimizely Jan 23, 2023
b540978
Testing InternalsVisibleTo in csproj
mikechu-optimizely Jan 23, 2023
8460538
More testing signed assems
mikechu-optimizely Jan 23, 2023
4e35a66 WIP fix InternalsVisibleTo with Release build
mikechu-optimizely Jan 24, 2023
4653690
Require providing SDK key in HttpProjectConfigManager constructor
mikechu-optimizely Jan 24, 2023
c6c86ae
Fix: Some suggested changes related to ODP (#325)
mnoman09 Jan 25, 2023
97678de
Merge fixes + lint
mikechu-optimizely Jan 25, 2023
5827136
Lint fixes
mikechu-optimizely Jan 25, 2023
90c75e6
Build fix and lint
mikechu-optimizely Jan 25, 2023
d886133
PR change requests
mikechu-optimizely Jan 31, 2023
597cb49
Lint fix
mikechu-optimizely Jan 31, 2023
99a42d8
Fix: ODP Event manager not consistent in triggering events. (#326)
mnoman09 Feb 13, 2023
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
81 changes: 81 additions & 0 deletions OptimizelySDK.NetStandard20/OptimizelySDK.NetStandard20.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,84 @@
<Compile Include="..\OptimizelySDK\IOptimizely.cs">
<Link>IOptimizely.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Notifications\NotificationCenterRegistry.cs">
<Link>Notifications\NotificationCenterRegistry.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Constants.cs">
<Link>Odp\Constants.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Audience.cs">
<Link>Odp\Entity\Audience.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Customer.cs">
<Link>Odp\Entity\Customer.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Data.cs">
<Link>Odp\Entity\Data.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Edge.cs">
<Link>Odp\Entity\Edge.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Error.cs">
<Link>Odp\Entity\Error.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Extension.cs">
<Link>Odp\Entity\Extension.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Location.cs">
<Link>Odp\Entity\Location.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Node.cs">
<Link>Odp\Entity\Node.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\OdpEvent.cs">
<Link>Odp\Entity\OdpEvent.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Entity\Response.cs">
<Link>Odp\Entity\Response.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\Enums.cs">
<Link>Odp\Enums.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\ICache.cs">
<Link>Odp\ICache.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\IOdpEventApiManager.cs">
<Link>Odp\IOdpEventApiManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\IOdpEventManager.cs">
<Link>Odp\IOdpEventManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\IOdpManager.cs">
<Link>Odp\IOdpManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\IOdpSegmentApiManager.cs">
<Link>Odp\IOdpSegmentApiManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\IOdpSegmentManager.cs">
<Link>Odp\IOdpSegmentManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\LruCache.cs">
<Link>Odp\LruCache.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpConfig.cs">
<Link>Odp\OdpConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpEventApiManager.cs">
<Link>Odp\OdpEventApiManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpEventManager.cs">
<Link>Odp\OdpEventManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpManager.cs">
<Link>Odp\OdpManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpSegmentApiManager.cs">
<Link>Odp\OdpSegmentApiManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Odp\OdpSegmentManager.cs">
<Link>Odp\OdpSegmentManager.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Optimizely.cs">
<Link>Optimizely.cs</Link>
</Compile>
Expand Down Expand Up @@ -223,6 +301,9 @@
<Compile Include="..\OptimizelySDK\Utils\AttributeMatchTypes.cs">
<Link>Utils\AttributeMatchTypes.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\CollectionExtensions.cs">
<Link>Utils\CollectionExtensions.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\Utils\ConditionParser.cs">
<Link>Utils\ConditionParser.cs</Link>
</Compile>
Expand Down
176 changes: 176 additions & 0 deletions OptimizelySDK.Tests/AudienceConditionsTests/SegmentsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Copyright 2022-2023 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 Moq;
using NUnit.Framework;
using OptimizelySDK.AudienceConditions;
using OptimizelySDK.Entity;
using OptimizelySDK.Logger;
using System.Collections.Generic;
using System.Linq;

namespace OptimizelySDK.Tests.AudienceConditionsTests
{
[TestFixture]
public class SegmentsTests
{
private BaseCondition _firstThirdPartyOdpQualifiedMatchCondition;
private BaseCondition _secondThirdPartyOdpQualifiedMatchCondition;
private ICondition _customExactMatchCondition;
private Mock<ILogger> _mockLogger;

private const string FIRST_CONDITION_VALUE = "first_condition_value";
private const string SECOND_CONDITION_VALUE = "second_condition_value";

[TestFixtureSetUp]
public void Setup()
{
_firstThirdPartyOdpQualifiedMatchCondition = new BaseCondition
{
Value = FIRST_CONDITION_VALUE,
Type = "third_party_dimension",
Name = "odp.audiences",
Match = "qualified",
};

_secondThirdPartyOdpQualifiedMatchCondition = new BaseCondition
{
Value = SECOND_CONDITION_VALUE,
Type = "third_party_dimension",
Name = "odp.audiences",
Match = "qualified",
};

_customExactMatchCondition = new BaseCondition()
{
Value = "test_custom_value",
Type = "custom_attribute",
Name = "test_custom_name",
Match = "exact",
};

_mockLogger = new Mock<ILogger>();
_mockLogger.Setup(l => l.Log(It.IsAny<LogLevel>(), It.IsAny<string>()));
}

[Test]
public void ShouldGetSegmentsFromDatafileTypedAudiences()
{
var expectedSegments = new SortedSet<string>
{
"ats_bug_bash_segment_gender",
"ats_bug_bash_segment_has_purchased",
"has_email_opted_out",
"ats_bug_bash_segment_dob",
};
var optimizelyClient = new Optimizely(TestData.OdpSegmentsDatafile,
new ValidEventDispatcher(), _mockLogger.Object);

var allSegments = optimizelyClient.ProjectConfigManager.GetConfig().Segments;

var orderedDistinctSegments = new SortedSet<string>(allSegments);
// check for no duplicates
Assert.AreEqual(allSegments.Length, orderedDistinctSegments.Count);
Assert.AreEqual(expectedSegments, orderedDistinctSegments);
}

[Test]
public void ShouldFindOdpSegmentFromAndCondition()
{
var conditions = new AndCondition
{
Conditions = new[]
{
_firstThirdPartyOdpQualifiedMatchCondition, _customExactMatchCondition,
},
};

var allSegments = Audience.GetSegments(conditions);

Assert.AreEqual(_firstThirdPartyOdpQualifiedMatchCondition.Value.ToString(),
allSegments.FirstOrDefault());
}

[Test]
public void ShouldFindOdpSegmentFromOrCondition()
{
var conditions = new OrCondition
{
Conditions = new[]
{
_customExactMatchCondition, _firstThirdPartyOdpQualifiedMatchCondition,
},
};

var allSegments = Audience.GetSegments(conditions);

Assert.AreEqual(_firstThirdPartyOdpQualifiedMatchCondition.Value.ToString(),
allSegments.FirstOrDefault());
}

[Test]
public void ShouldNotFindOdpSegmentsFromConditions()
{
var conditions = new AndCondition
{
Conditions = new[]
{
_customExactMatchCondition, _customExactMatchCondition, _customExactMatchCondition,
},
};

var allSegments = Audience.GetSegments(conditions);

Assert.IsEmpty(allSegments);
}

[Test]
public void ShouldFindAndDedupeNestedOdpSegments()
{
var qualifiedAndExact = new AndCondition
{
Conditions = new ICondition[]
{
_firstThirdPartyOdpQualifiedMatchCondition, _customExactMatchCondition,
},
};
var twoQualified = new AndCondition
{
Conditions = new ICondition[]
{
_secondThirdPartyOdpQualifiedMatchCondition, _firstThirdPartyOdpQualifiedMatchCondition,
},
};
var orConditions = new OrCondition
{
Conditions = new ICondition[]
{
qualifiedAndExact, twoQualified,
},
};
var notCondition = new NotCondition
{
Condition = orConditions,
};

var allSegments = Audience.GetSegments(notCondition).ToList();

Assert.AreEqual(2, allSegments.Count);
Assert.Contains(FIRST_CONDITION_VALUE, allSegments);
Assert.Contains(SECOND_CONDITION_VALUE, allSegments);
}
}
}
Loading
0