public void MissingChildrenElement_ExceptionWithMessageContaining()
        {
            string assemblyPath = ExternalConfiguration.GetConfigurationAssemblyPath(MethodBase.GetCurrentMethod());

            Assert.That(() => new CachingConfiguration(assemblyPath), Throws.InstanceOf <ConfigurationErrorsException>()
                        .With.Message.Contain(ExceptionMessagePart.For.MissingRequiredChildElement <DependantCachesCollection>()));
        }
예제 #2
0
        public void GetConfigurationAssemblyPath_TestNotDecoratedWithAssemblyFile_Exception()
        {
            MethodBase testMethod = MethodBase.GetCurrentMethod();

            Assert.That(() => ExternalConfiguration.GetConfigurationAssemblyPath(testMethod), Throws.InstanceOf <MissingMemberException>()
                        .With.Message.Contain(typeof(ConfigurationAssemblyAttribute).Name));
        }
        public void InvalidAttributeValue_ExceptionWithMessageContaining()
        {
            string assemblyPath = ExternalConfiguration.GetConfigurationAssemblyPath(MethodBase.GetCurrentMethod());

            Assert.That(() => new CachingConfiguration(assemblyPath), Throws.InstanceOf <ConfigurationErrorsException>()
                        .With.Message.Contain(ExceptionMessagePart.For.InvalidAttributeValue(ExpirationElement.NAME)));
        }
        public void UndefinedElement_ExceptionWithMessageContaining()
        {
            string assemblyPath = ExternalConfiguration.GetConfigurationAssemblyPath(MethodBase.GetCurrentMethod());

            Assert.That(() => new CachingConfiguration(assemblyPath), Throws.InstanceOf <ConfigurationErrorsException>()
                        .With.Message.Contain(ExceptionMessagePart.For.UndefinedElement(ExpirationElement.ElementName)));
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurationService"/> class.
 /// </summary>
 /// <param name="logger">Injected Logger Provider.</param>
 /// <param name="configuration">Injected Configuration Provider.</param>
 public ConfigurationService(
     ILogger <ConfigurationService> logger,
     IConfiguration configuration)
 {
     this.logger = logger;
     this.config = new ExternalConfiguration();
     this.config = configuration.Get <ExternalConfiguration>();
 }
        public void GetAppSettingReturnsNullForNotFoundSetting()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetAppSetting("very unknown name");

            Assert.IsNull(result);
        }
        public void GetAppSettingReturnsFoundSetting()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetAppSetting("externalKey1");

            Assert.AreEqual("externalValue1", result);
        }
예제 #8
0
        public void GetConfigurationAssemblyPath_AssemblyFileNotAnAssembly_Exception()
        {
            MethodBase testMethod = MethodBase.GetCurrentMethod();

            Assert.That(() => ExternalConfiguration.GetConfigurationAssemblyPath(testMethod), Throws.InstanceOf <ArgumentException>()
                        .With.Message.Contain("\\notAnAssembly.txt").And
                        .Property("ParamName").EqualTo("path"));
        }
        public void WrongAttributeValue_ExceptionWithMessageContaining()
        {
            string assemblyPath = ExternalConfiguration.GetConfigurationAssemblyPath(MethodBase.GetCurrentMethod());

            //NOTE: for the exception to be thrown the element needs to be accessed
            Assert.That(() => new CachingConfiguration(assemblyPath).TimeToExpire("name"), Throws.InstanceOf <ConfigurationErrorsException>()
                        .With.Message.Contain(ExceptionMessagePart.For.WrongMemberValue(ExpirationElement.VALUE)));
        }
        public void GetConnectionStringReturnsFoundString()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetConnectionString("externalName1");

            Assert.AreEqual("System.Data.SqlClient", result.ProviderName);
            Assert.AreEqual("externalString1", result.ConnectionString);
        }
예제 #11
0
        public void GetConfigurationAssemblyPath_AssemblyFileDoesNotExist_Exception()
        {
            // in order to get the test method, we have to execute outside the delegate
            MethodBase testMethod = MethodBase.GetCurrentMethod();

            Assert.That(() => ExternalConfiguration.GetConfigurationAssemblyPath(testMethod), Throws.InstanceOf <ArgumentException>()
                        .With.Message.Contain("\\notExisting.dll").And
                        .Property("ParamName").EqualTo("path"));
        }
예제 #12
0
        public void GetConfigurationAssemblyPath_TestDecoratedWithAssemblyFile_AllowsAccessToConfigurationValuesFromCustomConfiguration()
        {
            string assemblyPath = ExternalConfiguration.GetConfigurationAssemblyPath(MethodBase.GetCurrentMethod());

            ICachingConfiguration subject = null;

            Assert.That(() => subject = new CachingConfiguration(assemblyPath), Throws.Nothing);

            Assert.That(subject.TimeToExpire("expiration1"), Is.EqualTo(1.Seconds()));
            Assert.That(subject.HasDependencies("cache2"), Is.True);
            Assert.That(subject.GetDependantCaches("cache1"), Is.EqualTo(new[] { "cache1_1", "cache1_2" }));
        }
        private IConfigurationProvider GetMockConfigurationProvider()
        {
            var host   = ConfigurationManager.AppSettings["AerospikeHost"];
            var ns     = ConfigurationManager.AppSettings["SessionNamespace"];
            var config = new ExternalConfiguration()
            {
                ExpiryInSeconds       = 9999,
                MaxItemsPerAsyncQueue = 10
            };

            var mock = new Mock <IConfigurationProvider>();

            mock.Setup(x => x.GetGlobalConfigurationAsync <ExternalConfiguration>(ConfigurationSection, ConfigurationKey)).ReturnsAsync(config);
            mock.Setup(x => x.GetGlobalConfigurationAsync <AerospikeSettings>(Keystore.AerospikeKeys.SettingsSection, Keystore.AerospikeKeys.StateSettings))
            .ReturnsAsync(new AerospikeSettings {
                Host = host, Port = 3000, Namespace = ns
            });
            return(mock.Object);
        }
        public void GenericGetSectionReturnsNullForExistingSectionOfWrongType()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetSection<TestConfigurationSection>("anotherTestConfigurationSection");

            Assert.IsNull(result);
        }
        public void GenericGetSectionReturnsNullForNotFoundSection()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetSection<TestConfigurationSection>("very unknown name");

            Assert.IsNull(result);
        }
        public void GenericGetSectionReturnsFoundSection()
        {
            var target = new ExternalConfiguration("DocaLabs.Utils.Tests.External.config");

            var result = target.GetSection<TestConfigurationSection>("externalSection1");

            Assert.IsNotNull(result);
            Assert.AreEqual("externalTestValue1", result.TestValue);
        }