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
/// <summary> | |
/// Sourced from https://tech.trailmax.info/2014/01/convert-your-projects-from-nunitmoq-to-xunit-with-nsubstitute/ | |
/// </summary> | |
public class AutoDomainDataAttribute : AutoDataAttribute | |
{ | |
public AutoDomainDataAttribute() | |
: base(() => new Fixture().Customize(new AutoNSubstituteCustomization())) | |
{ } | |
} |
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
public class SettingInfoProviderFixture : AutomatedTestsWithData | |
{ | |
/// <summary> | |
/// Creates a fake SiteInfo | |
/// </summary> | |
/// <param name="siteId"></param> | |
/// <param name="siteName"></param> | |
public void FakeSiteInfo(int siteId, string siteName) => | |
Fake<SiteInfo, SiteInfoProvider>().WithData( | |
new SiteInfo |
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
[Test, AutoDomainData] | |
public void GetString_Will_Return_Site_Setting_Value( | |
SettingInfoProviderFixture fixture, | |
ISiteContext siteContext) | |
{ | |
// Explicitly defined values | |
string keyName = "key1"; | |
string keyValue = "value1"; | |
string siteName = "testSite"; | |
int siteId = 3; |
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
[Test, AutoDomainData] | |
public void GetString_Will_Return_Site_Setting_Value( | |
SettingInfoProviderFixture fixture, | |
ISiteContext siteContext, | |
string keyName, | |
string keyValue, | |
string siteName, | |
int siteId) | |
{ | |
fixture.FakeSiteInfo(siteId, siteName); |
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
[TestFixture] | |
public class KenticoSettingConfigProviderTests : UnitTests | |
{ | |
[Test] | |
public void Constructor_Guards_Against_Invalid_Parameters() | |
{ | |
Action sut = () => new KenticoSettingConfigProvider(null); | |
sut.Should().Throw<ArgumentNullException>(); | |
} |
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
public class KenticoSettingConfigProvider : IKenticoSettingConfigProvider | |
{ | |
private readonly ISiteContext siteContext; | |
public KenticoSettingConfigProvider(ISiteContext siteContext) | |
{ | |
Guard.Against.Null(siteContext, nameof(siteContext)); | |
this.siteContext = siteContext; | |
} |
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
public class KenticoSettingConfigProvider : IKenticoSettingConfigProvider | |
{ | |
public string GetString(string key, bool global = false) => | |
global | |
? SettingsKeyInfoProvider.GetValue(key) | |
: SettingsKeyInfoProvider.GetValue(key, SiteContext.CurrentSiteName); | |
// ... additional methods below | |
} |
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
using static CMS.SiteProvider.SiteContext; | |
public class KenticoSiteContext : ISiteContext | |
{ | |
public string SiteName => CurrentSiteName; | |
public int SiteId => CurrentSiteID; | |
public SiteInfo Site => CurrentSite; | |
} |
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
public interface ISiteContext | |
{ | |
string SiteName { get; } | |
int SiteId { get; } | |
SiteInfo Site { get; } | |
} |
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
public class KenticoSettingConfigProvider : IKenticoSettingConfigProvider | |
{ | |
private readonly ISiteContext siteContext; | |
public KenticoSettingConfigProvider(ISiteContext siteContext) | |
{ | |
Guard.Against.Null(siteContext, nameof(siteContext)); | |
this.siteContext = siteContext; | |
} |