-
Notifications
You must be signed in to change notification settings - Fork 20
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
176 changes: 176 additions & 0 deletions
176
OptimizelySDK.Tests/AudienceConditionsTests/SegmentsTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Uh oh!
There was an error while loading. Please reload this page.
feat: Integrated ODPManager with UserContext and Optimizely client #323
Changes from all commits
57b6927
3f27cfe
040138c
bf9005a
d58a5a9
65512ac
6e498d8
e7579cf
9a487bc
3c8fc1c
0a79a42
0212708
d99e2cb
3f29686
002b115
4edb545
e4fbd0d
2f15f8d
19bac38
bc75c20
3aa85d5
6e818b9
4a0deea
06f4a6a
e7fec76
dd16f7c
de7c5aa
00260a4
519ee78
516cff2
3b00476
3eaf48f
e132807
0aad28c
3dde070
c68eea9
5604d6d
3903532
0d7da83
27d30e5
52451ca
9f2db6e
c5a3ead
c273a4b
6a4a044
b4ba4b0
ca207f0
8053e44
361511f
4e5b652
7ea0856
016680b
0206a74
50d1a96
f61d05b
47562aa
1bb4b1c
a05a49c
b540978
8460538
4e35a66
4653690
c6c86ae
97678de
5827136
90c75e6
d886133
597cb49
99a42d8
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.