10000 feat(OptimizelyConfig): Add new fields to OptimizelyConfig by mnoman09 · Pull Request #266 · optimizely/csharp-sdk · GitHub
[go: up one dir, main page]

Skip to content

feat(OptimizelyConfig): Add new fields to OptimizelyConfig #266

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 26 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
98dcba5
Added new Optimizely config fields
mnoman09 Jun 30, 2021
41e684b
Added delivery rules
mnoman09 Jul 2, 2021
c6ad489
Added optimizelyAudience and rollout featureVariables fix
mnoman09 Jul 6, 2021
9973794
Added new line at end
mnoman09 Jul 6, 2021
665c553
Added audiences and fixed tests
mnoman09 Jul 8, 2021
3c04342
Net 3.5 deserializing fix
mnoman09 Jul 9, 2021
1c0bf1a
Used string builder instead of string
mnoman09 Jul 13, 2021
ef6218b
Added OptimizelyProjectConfigTest file in tests
mnoman09 Jul 13, 2021
9fc9d54
Moved getEvent After GetFeaturesMap
mnoman09 Jul 13, 2021
53fbc69
Resolved comments and refactored logic
mnoman09 Jul 15, 2021
c8ccfca
Fixed space was added before NOT condition in audiences
mnoman09 Jul 26, 2021
b85ae86
Resolved comments
mnoman09 Jul 26, 2021
22a2039
Resolved unitTest issue
mnoman09 Jul 26, 2021
9ace97f
removed two additional tests for testing
mnoman09 Jul 27, 2021
621e62c
Merge branch 'master' into mnoman/optimizelyConfigNewFields
mnoman09 Jul 27, 2021
ce2505b
Audience array merge fix Unit test fix
mnoman09 Jul 27, 2021
b362593
Condition simplified
mnoman09 Jul 27, 2021
cb47e3c
Added OptimizelyEvent and OptimizelyAttribute Class
mnoman09 Jul 27, 2021
8ba7fe5
Added $opt_dummy_audience in datafile to verify that it is getting ig…
mnoman09 Jul 28, 2021
62ed97f
Added serializedAudiences Tests cases
mnoman09 Jul 28, 2021
c685c61
refactored little bit.
msohailhussain Jul 29, 2021
7351048
Refactored comments
mnoman09 Jul 29, 2021
f1e684f
added unit tests for multiple experiment and removed sdk and env key.
msohailhussain Jul 29, 2021
b5d3383
Setting sdkKey and environment key default value as empty string
mnoman09 Jul 30, 2021
1e9d40f
fixed sorting issue
msohailhussain Jul 30, 2021
6a8dafa
corrected sequence of audiences
msohailhussain Aug 2, 2021
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
Prev Previous commit
Next Next commit
Added OptimizelyEvent and OptimizelyAttribute Class
  • Loading branch information
mnoman09 committed Jul 27, 2021
commit cb47e3c2c0e5e8c59754f76c125e58339c8d497c
6 changes: 6 additions & 0 deletions OptimizelySDK.Net35/OptimizelySDK.Net35.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyConfig.cs">
<Link>OptlyConfig\OptimizelyConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyAttribute.cs">
<Link>OptlyConfig\OptimizelyAttribute.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyEvent.cs">
<Link>OptlyConfig\OptimizelyEvent.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyExperiment.cs">
<Link>OptlyConfig\OptimizelyExperiment.cs</Link>
</Compile>
Expand Down
6 changes: 6 additions & 0 deletions OptimizelySDK.Net40/OptimizelySDK.Net40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyConfig.cs">
<Link>OptlyConfig\OptimizelyConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyAttribute.cs">
<Link>OptlyConfig\OptimizelyAttribute.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyEvent.cs">
<Link>OptlyConfig\OptimizelyEvent.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyExperiment.cs">
<Link>OptlyConfig\OptimizelyExperiment.cs</Link>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<Compile Include="..\OptimizelySDK\Config\PollingProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\Config\HttpProjectConfigManager.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyConfig.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyAttribute.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyEvent.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyExperiment.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyFeature.cs" />
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyVariable.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,9 +258,15 @@
</Compile>
<Compile Include="..\OptimizelySDK\Event\EventProcessor.cs">
<Link>Event\EventProcessor.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyAttribute.cs">
<Link>OptlyConfig\OptimizelyAttribute.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyConfig.cs">
<Link>OptlyConfig\OptimizelyConfig.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyEvent.cs">
<Link>OptlyConfig\OptimizelyEvent.cs</Link>
</Compile>
<Compile Include="..\OptimizelySDK\OptlyConfig\OptimizelyExperiment.cs">
<Link>OptlyConfig\OptimizelyExperiment.cs</Link>
Expand Down
20 changes: 10 additions & 10 deletions OptimizelySDK.Tests/OptimizelyConfigTests/OptimizelyConfigTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,21 +400,21 @@ public void TestGetOptimizelyConfigService()
OptimizelyConfig expectedOptimizelyConfig = new OptimizelyConfig(datafileProjectConfig.Revision,
datafileProjectConfig.SDKKey,
datafileProjectConfig.EnvironmentKey,
attributes: new Entity.Attribute[]
attributes: new OptimizelyAttribute[]
{
new Entity.Attribute
new OptimizelyAttribute
{
Id = "594015", Key = "house"
},
new Entity.Attribute
new OptimizelyAttribute
{
Id = "594016", Key = "lasers"
},
new Entity.Attribute
new OptimizelyAttribute
{
Id = "594017", Key = "should_do_it"
},
new Entity.Attribute
new OptimizelyAttribute
{
Id = "594018", Key = "favorite_ice_cream"
}
Expand All @@ -438,13 +438,13 @@ public void TestGetOptimizelyConfigService()
new OptimizelyAudience("3468206643", "exactBoolean", new object[] { "and", new object[] { "or", new object[] { "or", new Dictionary<string, object>() { { "name", "should_do_it" }, { "type", "custom_attribute" }, { "match", "exact" }, { "value", true } } } } }),
new OptimizelyAudience("3468206648", "notExist", new object[] { "not", new Dictionary<string, object>() { { "name", "input_value" }, { "type", "custom_attribute" }, { "match", "exists" } } }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also need validate "$opt_dummy_audience" audience is filtered out. See TDD.

},
events: new Entity.Event[]
events: new OptimizelyEvent[]
{
new Entity.Event()
new OptimizelyEvent()
{
Id = "594089", Key = "item_bought", ExperimentIds = new string[] { "11564051718", "1323241597" }
},
new Entity.Event()
new OptimizelyEvent()
{
Id = "594090", Key = "user_signed_up", ExperimentIds = new string[] { "1323241598", "1323241599" }
}
Expand All @@ -465,9 +465,9 @@ public void TestOptimizelyConfigEntity()
OptimizelyConfig expectedOptlyFeature = new OptimizelyConfig("123",
"testSdkKey",
"Development",
attributes: new Entity.Attribute[0],
attributes: new OptimizelyAttribute[0],
audiences: new OptimizelyAudience[0],
events: new Entity.Event[0],
events: new OptimizelyEvent[0],
experimentsMap: new Dictionary<string, OptimizelyExperiment>(),
featuresMap: new Dictionary<string, OptimizelyFeature>()
);
Expand Down
2 changes: 2 additions & 0 deletions OptimizelySDK/OptimizelySDK.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
<Compile Include="Optimizely.cs" />
<Compile Include="Bucketing\UserProfile.cs" />
<Compile Include="OptlyConfig\IOptimizelyConfigManager.cs" />
<Compile Include="OptlyConfig\OptimizelyEvent.cs" />
<Compile Include="OptlyConfig\OptimizelyAttribute.cs" />
<Compile Include="OptlyConfig\OptimizelyAudience.cs" />
<Compile Include="OptlyConfig\OptimizelyConfig.cs" />
<Compile Include="OptlyConfig\OptimizelyConfigService.cs" />
Expand Down
24 changes: 24 additions & 0 deletions OptimizelySDK/OptlyConfig/OptimizelyAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2021, 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
*
* http://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 OptimizelySDK.Entity;

namespace OptimizelySDK.OptlyConfig
{
public class OptimizelyAttribute : IdKeyEntity
{
}
}
7 changes: 3 additions & 4 deletions OptimizelySDK/OptlyConfig/OptimizelyConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

using Newtonsoft.Json;
using OptimizelySDK.Entity;
using System.Collections.Generic;

namespace OptimizelySDK.OptlyConfig
Expand All @@ -27,9 +26,9 @@ public class OptimizelyConfig
public string SDKKey { get; private set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string EnvironmentKey { get; private set; }
public Entity.Event[] Events { get; private set; }
public OptimizelyEvent[] Events { get; private set; }
public OptimizelyAudience[] Audiences { get; private set; }
public Attribute[] Attributes { get; private set; }
public OptimizelyAttribute[] Attributes { get; private set; }
public IDictionary<string, OptimizelyExperiment> ExperimentsMap { get; private set; }
public IDictionary<string, OptimizelyFeature> FeaturesMap { get; private set; }

Expand All @@ -43,7 +42,7 @@ public OptimizelyConfig(string revision, IDictionary<string, OptimizelyExperimen
_datafile = datafile;
}

public OptimizelyConfig(string revision, string sdkKey, string environmentKey, Attribute[] attributes, OptimizelyAudience[] audiences, Entity.Event[] events, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
public OptimizelyConfig(string revision, string sdkKey, string environmentKey, OptimizelyAttribute[] attributes, OptimizelyAudience[] audiences, OptimizelyEvent[] events, IDictionary<string, OptimizelyExperiment> experimentsMap, IDictionary<string, OptimizelyFeature> featuresMap, string datafile = null)
{
Revision = revision;
SDKKey = sdkKey;
Expand Down
25 changes: 21 additions & 4 deletions OptimizelySDK/OptlyConfig/OptimizelyConfigService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,18 @@ public OptimizelyConfigService(ProjectConfig projectConfig)
projectConfig.ToDatafile());
}

private Entity.Event[] GetEvents(ProjectConfig projectConfig)
private OptimizelyEvent[] GetEvents(ProjectConfig projectConfig)
{
return projectConfig.Events ?? new Entity.Event[0];
var optimizelyEvents = new List<OptimizelyEvent>();
foreach (var ev in projectConfig.Events)
{
var optimizelyEvent = new OptimizelyEvent();
10000 optimizelyEvent.Id = ev.Id;
optimizelyEvent.Key = ev.Key;
optimizelyEvent.ExperimentIds = ev.ExperimentIds;
optimizelyEvents.Add(optimizelyEvent);
}
return optimizelyEvents.ToArray();
}

private OptimizelyAudience[] GetAudiences(ProjectConfig projectConfig)
Expand All @@ -63,9 +72,17 @@ private OptimizelyAudience[] GetAudiences(ProjectConfig projectConfig)
return audiencesArr.Select(aud => new OptimizelyAudience(aud.Id, aud.Name, aud.Conditions)).ToArray<OptimizelyAudience>();
Copy link
Contributor
@msohailhussain msohailhussain Jul 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be you should override implicit equal operator.

}

private Entity.Attribute[] GetAttributes(ProjectConfig projectConfig)
private OptimizelyAttribute[] GetAttributes(ProjectConfig projectConfig)
{
return projectConfig.Attributes;
var attributes = new List<OptimizelyAttribute>();
foreach (var attr in projectConfig.Attributes)
{
var attribute = new OptimizelyAttribute();
attribute.Id = attr.Id;
attribute.Key = attr.Key;
attributes.Add(attribute);
}
return attributes.ToArray();
}

/// <summary>
Expand Down
28 changes: 28 additions & 0 deletions OptimizelySDK/OptlyConfig/OptimizelyEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright 2021, 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
*
* http://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 OptimizelySDK.Entity;

namespace OptimizelySDK.OptlyConfig
{
public class OptimizelyEvent : IdKeyEntity
{
/// <summary>
/// Associated Experiment with this Event
/// </summary>
public string[] ExperimentIds { get; set; }
}
}
0