-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added cache flag for configuration validity. (#97)
* Added ConfigurableVaultApplicationBase.IsCurrentConfigurationValid method that will cache the configuration validity. * Added unit tests for various scenarios.
- Loading branch information
1 parent
afa382b
commit 255ebf5
Showing
2 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
MFiles.VAF.Extensions.Tests/ConfigurableVaultApplicationBase.IsCurrentConfigurationValid.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using MFilesAPI; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace MFiles.VAF.Extensions.Tests | ||
{ | ||
[TestClass] | ||
public class ConfigurableVaultApplicationBase | ||
{ | ||
[TestMethod] | ||
[DataRow(true, false, false, true)] // Valid, no cache. | ||
[DataRow(false, false, false, true)] // Invalid, no cache. | ||
[DataRow(true, true, false, false)] // Valid, with cache. | ||
[DataRow(false, true, false, false)] // Invalid, with cache. | ||
[DataRow(true, true, true, true)] // Valid, with cache, force refresh. | ||
[DataRow(false, true, true, true)] // Invalid, with cache, force refresh. | ||
public void IsCurrentConfigurationValid | ||
( | ||
bool isConfigurationValid, // What IsValid will return. | ||
bool warmCache, // If true, cache will be populated before tests. | ||
bool forceCacheRefresh, // If true then the cache will be populated. | ||
bool isValidCallExpected // If true, IsValid must be called. | ||
) | ||
{ | ||
var proxy = new Proxy(isConfigurationValid); // IsValid will return true. | ||
|
||
// Should we warm the cache? | ||
if (warmCache) | ||
{ | ||
proxy.IsCurrentConfigurationValid(null, forceCacheRefresh); // Call it once so that it populates the cache. | ||
proxy.IsValidCalled = false; // Reset our flag. | ||
} | ||
|
||
// Does it return the correct valid? | ||
Assert.AreEqual(isConfigurationValid, proxy.IsCurrentConfigurationValid(null, forceCacheRefresh)); | ||
|
||
// Did it call IsValid? | ||
Assert.AreEqual(isValidCallExpected, proxy.IsValidCalled); | ||
} | ||
|
||
private class Proxy | ||
: ConfigurableVaultApplicationBaseProxy | ||
{ | ||
public bool IsConfigurationValid { get; } = false; | ||
public bool IsValidCalled { get; set; } = false; | ||
public Proxy(bool isConfigurationValid) | ||
{ | ||
this.IsConfigurationValid = isConfigurationValid; | ||
} | ||
public override bool IsValid(Vault vault) | ||
{ | ||
this.IsValidCalled = true; | ||
return this.IsConfigurationValid; | ||
} | ||
public new bool IsCurrentConfigurationValid(Vault vault, bool force = false) | ||
{ | ||
return base.IsCurrentConfigurationValid(vault, force); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters