-
Notifications
You must be signed in to change notification settings - Fork 8
fix: IfMatchContext/AndMatchContext utilize context kind. #225
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
+350
−3
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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 |
|---|---|---|
|
|
@@ -132,5 +132,242 @@ public void DataSourcePropagatesToMultipleClients() | |
| } | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IfMatchContext_MatchingContextKind_EvaluatesToTrue() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
|
|
||
| _td.Update(_td.Flag("company-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var matchingCompany = Context.Builder("company-123") | ||
| .Kind(companyKind) | ||
| .Set("name", "Acme") | ||
| .Build(); | ||
|
|
||
| Assert.True(client.BoolVariation("company-flag", matchingCompany, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IfMatchContext_NonMatchingAttributeValue_EvaluatesToFalse() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
|
|
||
| _td.Update(_td.Flag("company-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var nonMatchingCompany = Context.Builder("company-456") | ||
| .Kind(companyKind) | ||
| .Set("name", "OtherCorp") | ||
| .Build(); | ||
|
|
||
| Assert.False(client.BoolVariation("company-flag", nonMatchingCompany, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IfMatchContext_WrongContextKind_EvaluatesToFalse() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
|
|
||
| _td.Update(_td.Flag("company-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| // User context with same attribute value should not match (wrong context kind) | ||
| var userContext = Context.Builder("user-123") | ||
| .Set("name", "Acme") | ||
| .Build(); | ||
|
|
||
| Assert.False(client.BoolVariation("company-flag", userContext, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void IfMatchContext_MultiContextWithMatchingKind_EvaluatesToTrue() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
|
|
||
| _td.Update(_td.Flag("company-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| // Multi-context with matching company should return true | ||
| var multiContext = Context.NewMulti( | ||
| Context.New("user-123"), | ||
| Context.Builder("company-123").Kind(companyKind).Set("name", "Acme").Build() | ||
| ); | ||
|
|
||
| Assert.True(client.BoolVariation("company-flag", multiContext, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AndMatchContext_BothConditionsMatch_EvaluatesToTrue() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
| var orgKind = ContextKind.Of("org"); | ||
|
|
||
| _td.Update(_td.Flag("multi-kind-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .AndMatchContext(orgKind, "tier", LdValue.Of("premium")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var matchingMulti = Context.NewMulti( | ||
| Context.Builder("company-123").Kind(companyKind).Set("name", "Acme").Build(), | ||
| Context.Builder("org-456").Kind(orgKind).Set("tier", "premium").Build() | ||
| ); | ||
|
|
||
| Assert.True(client.BoolVariation("multi-kind-flag", matchingMulti, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AndMatchContext_OnlyFirstConditionMatches_EvaluatesToFalse() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
| var orgKind = ContextKind.Of("org"); | ||
|
|
||
| _td.Update(_td.Flag("multi-kind-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .AndMatchContext(orgKind, "tier", LdValue.Of("premium")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var onlyCompanyMatches = Context.NewMulti( | ||
| Context.Builder("company-123").Kind(companyKind).Set("name", "Acme").Build(), | ||
| Context.Builder("org-456").Kind(orgKind).Set("tier", "standard").Build() | ||
| ); | ||
|
|
||
| Assert.False(client.BoolVariation("multi-kind-flag", onlyCompanyMatches, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AndMatchContext_OnlySecondConditionMatches_EvaluatesToFalse() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
| var orgKind = ContextKind.Of("org"); | ||
|
|
||
| _td.Update(_td.Flag("multi-kind-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .AndMatchContext(orgKind, "tier", LdValue.Of("premium")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var onlyOrgMatches = Context.NewMulti( | ||
| Context.Builder("company-123").Kind(companyKind).Set("name", "OtherCorp").Build(), | ||
| Context.Builder("org-456").Kind(orgKind).Set("tier", "premium").Build() | ||
| ); | ||
|
|
||
| Assert.False(client.BoolVariation("multi-kind-flag", onlyOrgMatches, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AndMatchContext_NeitherConditionMatches_EvaluatesToFalse() | ||
| { | ||
| var companyKind = ContextKind.Of("company"); | ||
| var orgKind = ContextKind.Of("org"); | ||
|
|
||
| _td.Update(_td.Flag("multi-kind-flag") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(companyKind, "name", LdValue.Of("Acme")) | ||
| .AndMatchContext(orgKind, "tier", LdValue.Of("premium")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| var neitherMatches = Context.NewMulti( | ||
| Context.Builder("company-123").Kind(companyKind).Set("name", "OtherCorp").Build(), | ||
| Context.Builder("org-456").Kind(orgKind).Set("tier", "standard").Build() | ||
| ); | ||
|
|
||
| Assert.False(client.BoolVariation("multi-kind-flag", neitherMatches, false)); | ||
| } | ||
| } | ||
|
|
||
| [Fact] | ||
| public void AndMatchContext_TwoCustomContextKindsOnSameAttribute_EvaluatesCorrectly() | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also customer replication. |
||
| { | ||
| var contextA = ContextKind.Of("context_a"); | ||
| var contextB = ContextKind.Of("context_b"); | ||
|
|
||
| _td.Update(_td.Flag("flag_A") | ||
| .BooleanFlag() | ||
| .FallthroughVariation(false) | ||
| .IfMatchContext(contextA, "key", LdValue.Of("A1")) | ||
| .AndMatchContext(contextB, "key", LdValue.Of("B2")) | ||
| .ThenReturn(true)); | ||
|
|
||
| using (var client = new LdClient(_config)) | ||
| { | ||
| // Both contexts match - should return true | ||
| var bothMatch = Context.NewMulti( | ||
| Context.Builder("A1").Kind(contextA).Build(), | ||
| Context.Builder("B2").Kind(contextB).Build() | ||
| ); | ||
| Assert.True(client.BoolVariation("flag_A", bothMatch, false)); | ||
|
|
||
| // Only context_a matches - should return false | ||
| var onlyAMatches = Context.NewMulti( | ||
| Context.Builder("A1").Kind(contextA).Build(), | ||
| Context.Builder("wrong").Kind(contextB).Build() | ||
| ); | ||
| Assert.False(client.BoolVariation("flag_A", onlyAMatches, false)); | ||
|
|
||
| // Only context_b matches - should return false | ||
| var onlyBMatches = Context.NewMulti( | ||
| Context.Builder("wrong").Kind(contextA).Build(), | ||
| Context.Builder("B2").Kind(contextB).Build() | ||
| ); | ||
| Assert.False(client.BoolVariation("flag_A", onlyBMatches, false)); | ||
|
|
||
| // Neither matches - should return false | ||
| var neitherMatches = Context.NewMulti( | ||
| Context.Builder("wrong1").Kind(contextA).Build(), | ||
| Context.Builder("wrong2").Kind(contextB).Build() | ||
| ); | ||
| Assert.False(client.BoolVariation("flag_A", neitherMatches, false)); | ||
|
|
||
| // Wrong context kinds - should return false | ||
| var wrongKinds = Context.NewMulti( | ||
| Context.Builder("A1").Build(), // user context, not context_a | ||
| Context.Builder("B2").Build() // user context, not context_b | ||
| ); | ||
| Assert.False(client.BoolVariation("flag_A", wrongKinds, false)); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replication of github issue.