Skip to content

Commit

Permalink
Merge pull request #14 from configcat/feature/datagovernance
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein authored Oct 12, 2020
2 parents a20c2d7 + d75e88a commit 7bd21b9
Show file tree
Hide file tree
Showing 47 changed files with 2,429 additions and 794 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 ConfigCat
Copyright (c) 2020 ConfigCat

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 1 addition & 0 deletions src/ConfigCat.Client.Tests/BaseUrlTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace ConfigCat.Client.Tests
{
[TestCategory(TestCategories.Integration)]
[TestClass]
public class BaseUrlTests
{
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigCat.Client.Tests/BasicConfigEvaluatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace ConfigCat.Client.Tests
[TestClass]
public class BasicConfigEvaluatorTests : ConfigEvaluatorTestsBase
{
protected override string SampleJsonFileName => "sample_v4.json";
protected override string SampleJsonFileName => "sample_v5.json";

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

Expand Down
51 changes: 31 additions & 20 deletions src/ConfigCat.Client.Tests/ConfigCacheTests.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace ConfigCat.Client.Tests
{
[TestCategory(TestCategories.Integration)]
[TestClass]
public class ConfigCacheTests
{
Expand All @@ -13,71 +16,79 @@ public void ConfigCache_Override_AutoPoll_Works()
{
ProjectConfig cachedConfig = ProjectConfig.Empty;
Mock<IConfigCache> configCacheMock = new Mock<IConfigCache>();
configCacheMock.Setup(c => c.Set(It.IsAny<ProjectConfig>())).Callback<ProjectConfig>((config) =>

configCacheMock.Setup(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>())).Callback<string, ProjectConfig>((key, config) =>
{
cachedConfig = config;
});

configCacheMock.Setup(c => c.Get()).Returns(() => cachedConfig);

var client = ConfigCatClientBuilder.Initialize(SDKKEY).WithAutoPoll().WithConfigCache(configCacheMock.Object).Create();

configCacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None)).ReturnsAsync(() => cachedConfig);

var client = ConfigCatClientBuilder
.Initialize(SDKKEY)
.WithLogger(new ConsoleLogger(LogLevel.Debug))
.WithAutoPoll()
.WithConfigCache(configCacheMock.Object)
.Create();

var actual = client.GetValue("stringDefaultCat", "N/A");

Assert.AreEqual("Cat", actual);

configCacheMock.Verify(c => c.Set(It.IsAny<ProjectConfig>()), Times.AtLeastOnce);
configCacheMock.Verify(c => c.Get(), Times.AtLeastOnce);
configCacheMock.Verify(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>()), Times.AtLeastOnce);
configCacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None), Times.AtLeastOnce);
}

[TestMethod]
public void ConfigCache_Override_ManualPoll_Works()
{
ProjectConfig cachedConfig = ProjectConfig.Empty;
Mock<IConfigCache> configCacheMock = new Mock<IConfigCache>();
configCacheMock.Setup(c => c.Set(It.IsAny<ProjectConfig>())).Callback<ProjectConfig>((config) =>
configCacheMock.Setup(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>())).Callback<string, ProjectConfig>((key, config) =>
{
cachedConfig = config;
});

configCacheMock.Setup(c => c.Get()).Returns(() => cachedConfig);
configCacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None)).ReturnsAsync(() => cachedConfig);

var client = ConfigCatClientBuilder.Initialize(SDKKEY).WithManualPoll().WithConfigCache(configCacheMock.Object).Create();

configCacheMock.Verify(c => c.Set(It.IsAny<ProjectConfig>()), Times.Never);
configCacheMock.Verify(c => c.Get(), Times.Never);
configCacheMock.Verify(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>()), Times.Never);
configCacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None), Times.Never);

var actual = client.GetValue("stringDefaultCat", "N/A");

Assert.AreEqual("N/A", actual);
configCacheMock.Verify(c => c.Set(It.IsAny<ProjectConfig>()), Times.Never);
configCacheMock.Verify(c => c.Get(), Times.Once);
configCacheMock.Verify(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>()), Times.Never);
configCacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None), Times.Once);

client.ForceRefresh();

actual = client.GetValue("stringDefaultCat", "N/A");
Assert.AreEqual("Cat", actual);
configCacheMock.Verify(c => c.Set(It.IsAny<ProjectConfig>()), Times.Once);
configCacheMock.Verify(c => c.Get(), Times.Exactly(3));
configCacheMock.Verify(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>()), Times.Once);
configCacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None), Times.Exactly(3));
}

[TestMethod]
public void ConfigCache_Override_LazyLoad_Works()
{
ProjectConfig cachedConfig = ProjectConfig.Empty;
Mock<IConfigCache> configCacheMock = new Mock<IConfigCache>();
configCacheMock.Setup(c => c.Set(It.IsAny<ProjectConfig>())).Callback<ProjectConfig>((config) =>
configCacheMock.Setup(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>())).Callback<string, ProjectConfig>((key, config) =>
{
cachedConfig = config;
});

configCacheMock.Setup(c => c.Get()).Returns(() => cachedConfig);
configCacheMock.Setup(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None)).ReturnsAsync(() => cachedConfig);

var client = ConfigCatClientBuilder.Initialize(SDKKEY).WithLazyLoad().WithConfigCache(configCacheMock.Object).Create();

var actual = client.GetValue("stringDefaultCat", "N/A");
Assert.AreEqual("Cat", actual);

configCacheMock.Verify(c => c.Set(It.IsAny<ProjectConfig>()), Times.AtLeastOnce);
configCacheMock.Verify(c => c.Get(), Times.AtLeastOnce);
configCacheMock.Verify(c => c.SetAsync(It.IsAny<string>(), It.IsAny<ProjectConfig>()), Times.AtLeastOnce);
configCacheMock.Verify(c => c.GetAsync(It.IsAny<string>(), CancellationToken.None), Times.AtLeastOnce);
}
}
}
14 changes: 7 additions & 7 deletions src/ConfigCat.Client.Tests/ConfigCat.Client.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Moq" Version="4.10.0" />
<PackageReference Include="Moq" Version="4.14.6" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
Expand All @@ -26,22 +26,22 @@
</ItemGroup>

<ItemGroup>
<None Update="data\sample_number_v4.json">
<None Update="data\sample_number_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_sensitive_v4.json">
<None Update="data\sample_sensitive_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_semantic_2_v4.json">
<None Update="data\sample_semantic_2_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_semantic_v4.json">
<None Update="data\sample_semantic_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_v4.json">
<None Update="data\sample_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\sample_variationid_v4.json">
<None Update="data\sample_variationid_v5.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="data\testmatrix.csv">
Expand Down
Loading

0 comments on commit 7bd21b9

Please sign in to comment.