Skip to content

Commit

Permalink
sdk improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
configcat-developer committed Nov 25, 2019
1 parent ed8e247 commit 2d7022e
Show file tree
Hide file tree
Showing 44 changed files with 1,466 additions and 397 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ client.Dispose();
## Getting user specific setting values with Targeting
Using this feature, you will be able to get different setting values for different users in your application by passing a `User Object` to the `GetValue()` function.

Read more about [Targeting here](https://docs.configcat.com/docs/advanced/targeting/).
Read more about [Targeting here](https://configcat.com/docs/advanced/targeting).
```c#
User currentUser = new User("435170f4-8a8b-4b67-a723-505ac7cdea92");

Expand All @@ -87,5 +87,5 @@ If you need help how to use this SDK feel free to to contact the ConfigCat Staff
Contributions are welcome.

## About ConfigCat
- [Documentation](https://docs.configcat.com)
- [Blog](https://blog.configcat.com)
- [Documentation](https://configcat.com/docs)
- [Blog](https://configcat.com/blog)
Original file line number Diff line number Diff line change
Expand Up @@ -8,59 +8,26 @@ namespace ConfigCat.Client.Tests
{
[TestCategory("Integration")]
[TestClass]
public class ConfigCatClientIntegrationTests
public class BasicConfigCatClientIntegrationTests
{
private const string APIKEY = "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A";

private static IConfigCatClient client = new ConfigCatClient(APIKEY);
private static readonly IConfigCatClient client = new ConfigCatClient(APIKEY);

[TestMethod]
public async Task GetValue_MatrixTests()
{
await ConfigEvaluatorTests.MatrixTest(AssertValue);
}
private static readonly ILogger consoleLogger = new ConsoleLogger(LogLevel.Debug);

[ClassCleanup()]
public static void ClassCleanup()
{
client?.Dispose();
}

private void AssertValue(string keyName, string expected, User user)
{
var k = keyName.ToLowerInvariant();

if (k.StartsWith("bool"))
{
var actual = client.GetValue(keyName, false, user);

Assert.AreEqual(bool.Parse(expected), actual, $"keyName: {keyName} | userId: {user?.Identifier}");
}
else if (k.StartsWith("double"))
{
var actual = client.GetValue(keyName, double.NaN, user);

Assert.AreEqual(double.Parse(expected, CultureInfo.InvariantCulture), actual, $"keyName: {keyName} | userId: {user?.Identifier}");
}
else if (k.StartsWith("integer"))
{
var actual = client.GetValue(keyName, int.MaxValue, user);

Assert.AreEqual(int.Parse(expected), actual, $"keyName: {keyName} | userId: {user?.Identifier}");
}
else
{
var actual = client.GetValue(keyName, string.Empty, user);

Assert.AreEqual(expected, actual, $"keyName: {keyName} | userId: {user?.Identifier}");
}
}
}

[TestMethod]
public void ManualPollGetValue()
{
IConfigCatClient manualPollClient = ConfigCatClientBuilder
.Initialize(APIKEY)
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithManualPoll()
.Create();

Expand All @@ -74,6 +41,7 @@ public void AutoPollGetValue()
{
IConfigCatClient client = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithAutoPoll()
.WithMaxInitWaitTimeSeconds(30)
.WithPollIntervalSeconds(600)
Expand All @@ -87,6 +55,7 @@ public void LazyLoadGetValue()
{
IConfigCatClient client = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithLazyLoad()
.WithCacheTimeToLiveSeconds(30)
.Create();
Expand All @@ -99,6 +68,7 @@ public async Task ManualPollGetValueAsync()
{
IConfigCatClient client = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithManualPoll()
.Create();

Expand All @@ -112,6 +82,7 @@ public async Task AutoPollGetValueAsync()
{
IConfigCatClient client = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithAutoPoll()
.WithMaxInitWaitTimeSeconds(30)
.WithPollIntervalSeconds(600)
Expand All @@ -125,6 +96,7 @@ public async Task LazyLoadGetValueAsync()
{
IConfigCatClient client = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithLazyLoad()
.WithCacheTimeToLiveSeconds(30)
.Create();
Expand All @@ -137,6 +109,7 @@ public void GetAllKeys()
{
IConfigCatClient manualPollClient = ConfigCatClientBuilder
.Initialize(APIKEY)
.WithLogger(consoleLogger)
.WithManualPoll()
.Create();

Expand Down
51 changes: 51 additions & 0 deletions src/ConfigCat.Client.Tests/BasicConfigEvaluatorTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;

namespace ConfigCat.Client.Tests
{
[TestClass]
public class BasicConfigEvaluatorTests : ConfigEvaluatorTestsBase
{
protected override string SampleJsonFileName => "sample_v3.json";

protected override string MatrixResultFileName => "testmatrix.csv";

[TestMethod]
public void GetValue_WithSimpleKey_ShouldReturnCat()
{
string actual = configEvaluator.Evaluate(config, "stringDefaultCat", string.Empty);

Assert.AreNotEqual(string.Empty, actual);
Assert.AreEqual("Cat", actual);
}

[TestMethod]
public void GetValue_WithNonExistingKey_ShouldReturnDefaultValue()
{
string actual = configEvaluator.Evaluate(config, "NotExistsKey", "NotExistsValue");

Assert.AreEqual("NotExistsValue", actual);
}

[TestMethod]
public void GetValue_WithEmptyProjectConfig_ShouldReturnDefaultValue()
{
string actual = configEvaluator.Evaluate(ProjectConfig.Empty, "stringDefaultCat", "Default");

Assert.AreEqual("Default", actual);
}

[TestMethod]
public void GetValue_WithUser_ShouldReturnEvaluatedValue()
{
double actual = configEvaluator.Evaluate(config, "doubleDefaultPi", double.NaN, new User("[email protected]")
{
Email = "[email protected]",
Country = "United Kingdom",
Custom = new Dictionary<string, string> { { "Custom1", "admin" } }
});

Assert.AreEqual(3.1415, actual);
}
}
}
25 changes: 23 additions & 2 deletions src/ConfigCat.Client.Tests/ConfigCat.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,31 @@
</ItemGroup>

<ItemGroup>
<None Update="sample_v2.json">
<None Update="data\sample_number_v2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="testmatrix.csv">
<None Update="data\sample_number_v3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_semantic_v2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_semantic_v3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_v2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_v3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\testmatrix.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\testmatrix_number.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\testmatrix_semantic.csv">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/ConfigCat.Client.Tests/ConfigCatClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public void CreateAnInstance_WhenManualPollConfigurationIsNull_ShouldThrowArgume

[ExpectedException(typeof(ArgumentNullException))]
[TestMethod]
public void CreateAnInstance_WhenLoggerFactoryIsNull_ShouldThrowArgumentNullException()
public void CreateAnInstance_WhenLoggerIsNull_ShouldThrowArgumentNullException()
{
var clientConfiguration = new AutoPollConfiguration
{
ApiKey = "hsdrTr4sxbHdSgdhHRZds346hdgsS2vfsgf/GsdrTr4sxbHdSgdhHRZds346hdOPsSgvfsgf",
LoggerFactory = null
Logger = null
};

new ConfigCatClient(clientConfiguration);
Expand Down
Loading

0 comments on commit 2d7022e

Please sign in to comment.