-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added ODPManager implementation (#322)
* Initial ODP Manager * Outline unit tests * WIP Unit tests + changes to CUD * Implement fetch, identify, and send events with Builder pattern * WIP Fixing final unit test * Finish unit tests * Add documentation * Lint fixes * Pull request code revisions + additional unit tests * Lint fixes * Change to use string array over List * Clean usings * Add new OdpConfig test * Small refactors * Pull request code review changes * Code review changes * Mark _odpConfig as volatile * Return `volatile` denotation
- Loading branch information
1 parent
3cd6745
commit bdaef7f
Showing
12 changed files
with
879 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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,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)); | ||
} | ||
} | ||
} |
This file contains 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
Oops, something went wrong.