-
Notifications
You must be signed in to change notification settings - Fork 20
Feat: Add Config support for initializing EP & HttpProjectConfigManager #197
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
Changes from all commits
e93fe65
ffff6e6
d5ff115
333d428
af395a9
89c4349
493b050
14cf23d
42903c3
546d180
c8e6d18
0343779
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,31 @@ | |
that apply only to the Test project. | ||
--> | ||
<configuration> | ||
<appSettings> | ||
|
||
</appSettings> | ||
<configSections> | ||
<section name="optlySDKConfigSection" | ||
type="OptimizelySDK.OptimizelySDKConfigSection, OptimizelySDK, Version=3.2.0.0, Culture=neutral, PublicKeyToken=null" /> | ||
</configSections> | ||
|
||
<optlySDKConfigSection> | ||
|
||
<HttpProjectConfig sdkKey="43214321" | ||
url="www.testurl.com" | ||
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. This url is not needed because you have the url format 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. I think this is not for actual HttpConfigManager testing, it's only to check, if the url what we set is readonly through property or not. |
||
format="https://cdn.optimizely.com/data/{0}.json" | ||
pollingInterval="2000" | ||
blockingTimeOutPeriod="10000" | ||
autoUpdate="true" | ||
defaultStart="true"> | ||
</HttpProjectConfig> | ||
|
||
<BatchEventProcessor batchSize="10" | ||
flushInterval="2000" | ||
timeoutInterval="10000" | ||
defaultStart="true"> | ||
</BatchEventProcessor> | ||
|
||
</optlySDKConfigSection> | ||
|
||
<connectionStrings> | ||
|
||
</connectionStrings> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2019, 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. | ||
*/ | ||
|
||
#if !NETSTANDARD1_6 && !NET35 | ||
|
||
using NUnit.Framework; | ||
using System.Configuration; | ||
|
||
namespace OptimizelySDK.Tests | ||
{ | ||
[TestFixture] | ||
public class ClientConfigHandlerTest | ||
{ | ||
|
||
[Test] | ||
public void TestHTTPAppConfigSection() | ||
{ | ||
var configSection = ConfigurationManager.GetSection("optlySDKConfigSection") as OptimizelySDKConfigSection; | ||
var httpSetting = configSection.HttpProjectConfig; | ||
Assert.IsNotNull(httpSetting); | ||
Assert.IsTrue(httpSetting.AutoUpdate); | ||
Assert.AreEqual(httpSetting.BlockingTimeOutPeriod, 10000); | ||
Assert.AreEqual(httpSetting.Format, "https://cdn.optimizely.com/data/{0}.json"); | ||
Assert.IsTrue(httpSetting.DefaultStart); | ||
Assert.AreEqual(httpSetting.PollingInterval, 2000); | ||
Assert.AreEqual(httpSetting.SDKKey, "43214321"); | ||
Assert.AreEqual(httpSetting.Url, "www.testurl.com"); | ||
} | ||
|
||
[Test] | ||
public void TestBatchEventAppConfigSection() | ||
{ | ||
var configSection = ConfigurationManager.GetSection("optlySDKConfigSection") as OptimizelySDKConfigSection; | ||
var batchSetting = configSection.BatchEventProcessor; | ||
Assert.IsNotNull(batchSetting); | ||
Assert.AreEqual(batchSetting.BatchSize, 10); | ||
Assert.AreEqual(batchSetting.FlushInterval, 2000); | ||
Assert.AreEqual(batchSetting.TimeoutInterval, 10000); | ||
Assert.IsTrue(batchSetting.DefaultStart); | ||
} | ||
|
||
} | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright 2019, 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 System.Configuration; | ||
|
||
namespace OptimizelySDK | ||
{ | ||
public class HttpProjectConfigElement : ConfigurationElement | ||
{ | ||
[ConfigurationProperty("sdkKey", IsRequired = true, IsKey = true)] | ||
public string SDKKey | ||
{ | ||
get { return (string)base["sdkKey"]; } | ||
} | ||
|
||
[ConfigurationProperty("url")] | ||
public string Url | ||
{ | ||
get { return (string)base["url"]; } | ||
} | ||
|
||
[ConfigurationProperty("format")] | ||
public string Format | ||
{ | ||
get { return (string)base["format"]; } | ||
} | ||
|
||
[ConfigurationProperty("pollingInterval")] | ||
public int PollingInterval | ||
{ | ||
get { return base["pollingInterval"] is int ? (int)base["pollingInterval"] : 0; } | ||
} | ||
|
||
[ConfigurationProperty("blockingTimeOutPeriod")] | ||
public int BlockingTimeOutPeriod | ||
{ | ||
get { return base["blockingTimeOutPeriod"] is int ? (int)base["blockingTimeOutPeriod"] : 0; } | ||
} | ||
|
||
[ConfigurationProperty("autoUpdate")] | ||
public bool AutoUpdate | ||
{ | ||
get { return (bool)base["autoUpdate"]; } | ||
} | ||
|
||
[ConfigurationProperty("defaultStart")] | ||
public bool DefaultStart | ||
{ | ||
get { return (bool)base["defaultStart"]; } | ||
} | ||
} | ||
|
||
public class BatchEventProcessorElement : ConfigurationElement | ||
{ | ||
[ConfigurationProperty("batchSize")] | ||
public int BatchSize | ||
{ | ||
get { return (int)base["batchSize"]; } | ||
} | ||
|
||
[ConfigurationProperty("flushInterval")] | ||
public int FlushInterval | ||
{ | ||
get { return base["flushInterval"] is int ? (int)base["flushInterval"] : 0; } | ||
} | ||
|
||
[ConfigurationProperty("timeoutInterval")] | ||
public int TimeoutInterval | ||
{ | ||
get { return base["timeoutInterval"] is int ? (int)base["timeoutInterval"] : 0; } | ||
} | ||
|
||
[ConfigurationProperty("defaultStart")] | ||
public bool DefaultStart | ||
{ | ||
get { return (bool)base["defaultStart"]; } | ||
} | ||
} | ||
|
||
public class OptimizelySDKConfigSection : ConfigurationSection | ||
{ | ||
[ConfigurationProperty("HttpProjectConfig")] | ||
public HttpProjectConfigElement HttpProjectConfig | ||
{ | ||
get { return (HttpProjectConfigElement)base["HttpProjectConfig"]; } | ||
set { base["HttpProjectConfig"] = value; } | ||
} | ||
|
||
[ConfigurationProperty("BatchEventProcessor")] | ||
public BatchEventProcessorElement BatchEventProcessor { | ||
get { return (BatchEventProcessorElement)(base["BatchEventProcessor"]); } | ||
set { base["BatchEventProcessor"] = value; } | ||
} | ||
} | ||
} |
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.
Can you please add notes in the README for this and how it affects unit tests?