Skip to content
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

Create virtual methods on user context #280

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
1 change: 1 addition & 0 deletions OptimizelySDK.Tests/OptimizelySDK.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
<Compile Include="TestBucketer.cs" />
<Compile Include="BucketerTest.cs" />
<Compile Include="ProjectConfigTest.cs" />
<Compile Include="TestSetup.cs" />
<Compile Include="UtilsTests\ConditionParserTest.cs" />
<Compile Include="UtilsTests\EventTagUtilsTest.cs" />
<Compile Include="UtilsTests\ExceptionExtensionsTest.cs" />
Expand Down
25 changes: 25 additions & 0 deletions OptimizelySDK.Tests/TestSetup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using NUnit.Framework;
using System.Globalization;
using System.Threading;

namespace OptimizelySDK.Tests
{
[SetUpFixture]
public class TestSetup
{
[SetUp]
public void Init()
{
/* There are some issues doing assertions on tests with floating point numbers using the .ToString()
* method, as it's culture dependent. EG: TestGetFeatureVariableValueForTypeGivenFeatureFlagIsNotEnabledForUser,
* assigning the culture to English will make this kind of tests to work on others culture based systems. */
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
}

[TearDown]
public void Cleanup()
{
// Empty, but required: https://nunit.org/nunitv2/docs/2.6.4/setupFixture.html
}
}
}
20 changes: 10 additions & 10 deletions OptimizelySDK/OptimizelyUserContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public OptimizelyUserContext(Optimizely optimizely, string userId, UserAttribute
/// Returns Optimizely instance associated with the UserContext.
/// </summary>
/// <returns> Optimizely instance.</returns>
public Optimizely GetOptimizely()
public virtual Optimizely GetOptimizely()
{
return Optimizely;
}
Expand All @@ -61,7 +61,7 @@ public Optimizely GetOptimizely()
/// Returns UserId associated with the UserContext
/// </summary>
/// <returns>UserId of this instance.</returns>
public string GetUserId()
public virtual string GetUserId()
{
return UserId;
}
Expand Down Expand Up @@ -108,7 +108,7 @@ public void SetAttribute(string key, object value)
/// </summary>
/// <param name="key">A flag key for which a decision will be made.</param>
/// <returns>A decision result.</returns>
public OptimizelyDecision Decide(string key)
public virtual OptimizelyDecision Decide(string key)
{
return Decide(key, new OptimizelyDecideOption[] { });
}
Expand All @@ -122,7 +122,7 @@ public OptimizelyDecision Decide(string key)
/// <param name="key">A flag key for which a decision will be made.</param>
/// <param name="options">A list of options for decision-making.</param>
/// <returns>A decision result.</returns>
public OptimizelyDecision Decide(string key,
public virtual OptimizelyDecision Decide(string key,
OptimizelyDecideOption[] options)
{
var optimizelyUserContext = Copy();
Expand All @@ -134,7 +134,7 @@ public OptimizelyDecision Decide(string key,
/// </summary>
/// <param name="keys">list of flag keys for which a decision will be made.</param>
/// <returns>A dictionary of all decision results, mapped by flag keys.</returns>
public Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys, OptimizelyDecideOption[] options)
public virtual Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys, OptimizelyDecideOption[] options)
{
var optimizelyUserContext = Copy();
return Optimizely.DecideForKeys(optimizelyUserContext, keys, options);
Expand All @@ -145,7 +145,7 @@ public Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys, Optim
/// </summary>
/// <param name="keys">list of flag keys for which a decision will be made.</param>
/// <returns>A dictionary of all decision results, mapped by flag keys.</returns>
public Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys)
public virtual Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys)
{
return DecideForKeys(keys, new OptimizelyDecideOption[] { });
}
Expand All @@ -154,7 +154,7 @@ public Dictionary<string, OptimizelyDecision> DecideForKeys(string[] keys)
/// Returns a key-map of decision results ({@link OptimizelyDecision}) for all active flag keys.
/// </summary>
/// <returns>A dictionary of all decision results, mapped by flag keys.</returns>
public Dictionary<string, OptimizelyDecision> DecideAll()
public virtual Dictionary<string, OptimizelyDecision> DecideAll()
{
return DecideAll(new OptimizelyDecideOption[] { });
}
Expand All @@ -164,7 +164,7 @@ public Dictionary<string, OptimizelyDecision> DecideAll()
/// </summary>
/// <param name="options">A list of options for decision-making.</param>
/// <returns>All decision results mapped by flag keys.</returns>
public Dictionary<string, OptimizelyDecision> DecideAll(OptimizelyDecideOption[] options)
public virtual Dictionary<string, OptimizelyDecision> DecideAll(OptimizelyDecideOption[] options)
{
var optimizelyUserContext = Copy();
return Optimizely.DecideAll(optimizelyUserContext, options);
Expand All @@ -174,7 +174,7 @@ public Dictionary<string, OptimizelyDecision> DecideAll(OptimizelyDecideOption[]
/// Track an event.
/// </summary>
/// <param name="eventName">The event name.</param>
public void TrackEvent(string eventName)
public virtual void TrackEvent(string eventName)
{
TrackEvent(eventName, new EventTags());
}
Expand All @@ -184,7 +184,7 @@ public void TrackEvent(string eventName)
/// </summary>
/// <param name="eventName">The event name.</param>
/// <param name="eventTags">A map of event tag names to event tag values.</param>
public void TrackEvent(string eventName,
public virtual void TrackEvent(string eventName,
EventTags eventTags)
{
Optimizely.Track(eventName, UserId, Attributes, eventTags);
Expand Down