public void TryFindSetting_CanFindSettingByName() { var provider1 = Mock.Create <ISettingProvider>(); var provider2 = Mock.Create <ISettingProvider>(); var provider3 = Mock.Create <ISettingProvider>(); provider1 .Arrange(x => x.Read(Arg.IsAny <SelectQuery>())) .Returns(default(ISetting)); provider2 .Arrange(x => x.Read(Arg.Matches <SelectQuery>(arg => arg.SettingName == SettingName.Parse("Type.Member")))) .Returns(Setting.Create("Type.Member", "abc")); provider3 .Arrange(x => x.Read(Arg.IsAny <SelectQuery>())) .Returns(default(ISetting)); var settingFound = FirstSettingFinder.TryFindSetting ( new SelectQuery(SettingName.Parse("Type.Member"), typeof(string)), new[] { provider1, provider2, provider3 }, out var result ); Assert.IsTrue(settingFound); Assert.AreSame(provider2, result.SettingProvider); Assert.AreEqual("abc", result.Setting.Value); }
public void ctor_CanInstantiateFromMember() { var sn = SettingName.Parse("foo"); Assert.That.IsNullOrEmpty(sn.Namespace); Assert.That.IsNullOrEmpty(sn.Type); Assert.AreEqual("foo", sn.Member); Assert.That.IsNullOrEmpty(sn.Instance); }
public void Parse_CanReadNamespaceTypeMemberAndInstance() { var settingName = SettingName.Parse("foo.bar+baz.qux,quux"); Assert.AreEqual("foo.bar", settingName.Namespace); Assert.AreEqual("baz", settingName.Type); Assert.AreEqual("qux", settingName.Member); Assert.AreEqual("quux", settingName.Instance); Assert.AreEqual("foo.bar+baz.qux,quux", settingName.ToString()); }
public void Parse_CanReadNamespaceTypeAndMember() { var settingName = SettingName.Parse("foo.bar+baz.qux"); Assert.AreEqual("foo.bar", settingName.Namespace); Assert.AreEqual("baz", settingName.Type); Assert.AreEqual("qux", settingName.Member); Assert.That.IsNullOrEmpty(settingName.Instance); Assert.AreEqual("foo.bar+baz.qux", settingName.ToString()); }
public void Parse_NamespaceTypePropertyInstance_Name() { var settingName = SettingName.Parse("foo.bar+baz.qux,quux"); Assert.AreEqual("foo.bar", settingName.Namespace); Assert.AreEqual("baz", settingName.Type); Assert.AreEqual("qux", settingName.Property); Assert.AreEqual("quux", settingName.Instance); Assert.AreEqual("foo.bar+baz.qux,quux", settingName.ToString()); }
public void Parse_TypeProperty_Name() { var settingName = SettingName.Parse("baz.qux"); Assert.IsNull(settingName.Namespace); Assert.AreEqual("baz", settingName.Type); Assert.AreEqual("qux", settingName.Property); Assert.IsNull(settingName.Instance); Assert.AreEqual("baz.qux", settingName.ToString()); }
public void Parse_CanReadAssemblyNamespaceTypeMemberAndInstance() { var settingName = SettingName.Parse("Assem.bly:Name.space+Type.Member,Instance"); Assert.AreEqual("Assem.bly", settingName.Prefix); Assert.AreEqual("Name.space", settingName.Namespace); Assert.AreEqual("Type", settingName.Type); Assert.AreEqual("Member", settingName.Member); Assert.AreEqual("Instance", settingName.Instance); Assert.AreEqual("Assem.bly:Name.space+Type.Member,Instance", settingName.ToString()); }
public void Parse_CanReadMember() { var settingName = SettingName.Parse("qux"); Assert.That.IsNullOrEmpty(settingName.Prefix); Assert.That.IsNullOrEmpty(settingName.Namespace); Assert.That.IsNullOrEmpty(settingName.Type); Assert.AreEqual("qux", settingName.Member); Assert.That.IsNullOrEmpty(settingName.Instance); Assert.AreEqual("qux", settingName.ToString()); }
public void CreateProviderSettingName_CanUseDifferentConventions() { Assert.AreEqual ( SettingName.Parse("Type.Member"), Factory.CreateProviderSettingName( SettingName.Parse("Assembly:Namespace+Type.Member"), new SettingProviderNaming { Strength = SettingNameStrength.Medium, PrefixHandling = PrefixHandling.Disable } ) ); Assert.AreEqual ( SettingName.Parse("Type.Member,Instance"), Factory.CreateProviderSettingName(SettingName.Parse("Assembly:Namespace+Type.Member,Instance"), new SettingProviderNaming { Strength = SettingNameStrength.Medium, PrefixHandling = PrefixHandling.Disable } ) ); Assert.AreEqual ( SettingName.Parse("Namespace+Type.Member"), Factory.CreateProviderSettingName(SettingName.Parse("Assembly:Namespace+Type.Member"), new SettingProviderNaming { Strength = SettingNameStrength.High, PrefixHandling = PrefixHandling.Enable } ) ); Assert.AreEqual ( SettingName.Parse("Assembly:Namespace+Type.Member,Instance"), Factory.CreateProviderSettingName(SettingName.Parse("Assembly:Namespace+Type.Member,Instance"), new SettingProviderNaming { Strength = SettingNameStrength.High, Prefix = "Assembly", PrefixHandling = PrefixHandling.Enable } ) ); }
public void GenerateNames_BaseName_NamesByFrequency() { var settingNameGenerator = new SettingNameGenerator(); CollectionAssert.AreEqual( new[] { "baz.qux", "qux", "foo.bar+baz.qux", }, settingNameGenerator.GenerateSettingNames(SettingName.Parse("foo.bar+baz.qux")).Select(name => (string)name).ToList()); }
public void TryFindSetting_DoesNotFindNotExistingSetting() { var provider = Mock.Create <ISettingProvider>(); provider .Arrange(x => x.Read(Arg.IsAny <SelectQuery>())) .Returns(default(ISetting)); var settingFound = FirstSettingFinder.TryFindSetting ( new SelectQuery(SettingName.Parse("Type.Member"), typeof(string)), new[] { provider }, out var result ); Assert.IsFalse(settingFound); }
public void Equals_CanCompareSimilarObjects() { Assert.AreEqual( SettingName.Parse("foo.bar+baz.qux,quux"), SettingName.Parse("foo.bar+baz.qux,quux")); Assert.AreEqual( SettingName.Parse("baz.qux,quux"), SettingName.Parse("baz.qux,quux")); Assert.AreEqual( SettingName.Parse("qux,quux"), SettingName.Parse("qux,quux")); Assert.AreEqual( SettingName.Parse("foo.bar+baz.qux"), SettingName.Parse("foo.bar+baz.qux")); Assert.AreEqual( SettingName.Parse("qux"), SettingName.Parse("qux")); }
public void Parse_DisallowsInvalidFormat() { Assert.That.Throws <DynamicException>(() => SettingName.Parse("foo+bar+baz"), filter => filter.When(name: "^SettingNameFormat")); }
public void Equals_CanCompareDifferentObjects() { Assert.AreNotEqual( SettingName.Parse("foo.bar+baz.qux,quux"), SettingName.Parse("foo.bar+baz.qux")); }