public void Should_cache_previous_lookups_by_default()
        {
            configSource = new AzureConfigurationSource(azureSettings);

            azureSettings.Stub(x => x.TryGetSetting(
               Arg.Is("TestConfigSection.StringSetting"),
               out Arg<string>.Out("test").Dummy))
               .Return(true);

            Assert.AreEqual(configSource.GetConfiguration<TestConfigSection>(), configSource.GetConfiguration<TestConfigSection>());
        }
Esempio n. 2
0
        public void Should_cache_previous_lookups_by_default()
        {
            configSource = new AzureConfigurationSource(azureSettings);

            azureSettings.Stub(x => x.TryGetSetting(
                                   Arg.Is("TestConfigSection.StringSetting"),
                                   out Arg <string> .Out("test").Dummy))
            .Return(true);

            Assert.AreEqual(configSource.GetConfiguration <TestConfigSection>(), configSource.GetConfiguration <TestConfigSection>());
        }
Esempio n. 3
0
        T IConfigurationSource.GetConfiguration <T>()
        {
            var config = innerSource.GetConfiguration <T>();
            var index  = 0;

            if (RoleEnvironment.IsAvailable)
            {
                index = ParseIndexFrom(RoleEnvironment.CurrentRoleInstance.Id);
            }

            var queueConfig = config as AppFabricQueueConfig;

            if (queueConfig != null && queueConfig.QueueName != null && RoleEnvironment.IsAvailable)
            {
                var individualQueueName = ParseQueueNameFrom(queueConfig.QueueName)
                                          + (index > 0 ? "-" : "")
                                          + (index > 0 ? index.ToString() : "");

                if (queueConfig.QueueName.Contains("@"))
                {
                    individualQueueName += "@" + ParseMachineNameFrom(queueConfig.QueueName);
                }

                queueConfig.QueueName = individualQueueName;
            }

            return(config);
        }
Esempio n. 4
0
        private static void SetUpConfiguration(IConfigurationSource source, Type type, ISessionFactoryHolder holder)
        {
            IConfiguration config = source.GetConfiguration(type);

            if (config != null)
            {
                Configuration nconf = CreateConfiguration(config);

                if (source.NamingStrategyImplementation != null)
                {
                    Type namingStrategyType = source.NamingStrategyImplementation;

                    if (!typeof(INamingStrategy).IsAssignableFrom(namingStrategyType))
                    {
                        String message =
                            String.Format("The specified type {0} does " + "not implement the interface INamingStrategy",
                                          namingStrategyType.FullName);

                        throw new ActiveRecordException(message);
                    }

                    nconf.SetNamingStrategy((INamingStrategy)Activator.CreateInstance(namingStrategyType));
                }

                AddContributorsToConfig(type, nconf);
                holder.Register(type, nconf);
            }
        }
        public void GetConnectionStringFromWebConfig()
        {
            IConfigurationSource source = ConfigurationManager.GetSection("activerecord-asp-net-2.0") as IConfigurationSource;

            IConfiguration config = source.GetConfiguration(typeof(ActiveRecordBase));

            string expected = config.Children["connection.connection_string"].Value;

            Assert.AreEqual("Test Connection String", expected);
        }
        private static void SetUpConfiguration(IConfigurationSource source, Type type, ISessionFactoryHolder holder)
        {
            IConfiguration config = source.GetConfiguration(type);

            if (config != null)
            {
                Configuration nconf = CreateConfiguration(config);
                holder.Register(type, nconf);
            }
        }
Esempio n. 7
0
        public void The_service_configuration_should_override_appconfig()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            azureSettings.Stub(x => x.TryGetSetting(
                                   Arg.Is("TestConfigSection.StringSetting"),
                                   out Arg <string> .Out("test").Dummy))
            .Return(true);

            Assert.AreEqual(configSource.GetConfiguration <TestConfigSection>().StringSetting, "test");
        }
        public void Value_types_should_be_converted_from_string_to_its_native_type()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

           azureSettings.Stub(x => x.TryGetSetting(
              Arg.Is("TestConfigSection.IntSetting"),
              out Arg<string>.Out("23").Dummy))
              .Return(true);

            Assert.AreEqual(configSource.GetConfiguration<TestConfigSection>().IntSetting, 23);
        }
        public void Overrides_should_be_possible_for_non_existing_sections()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            azureSettings.Stub(x => x.TryGetSetting(
               Arg.Is("SectionNotPresentInConfig.SomeSetting"),
               out Arg<string>.Out("test").Dummy))
               .Return(true);

            Assert.AreEqual(configSource.GetConfiguration<SectionNotPresentInConfig>().SomeSetting, "test");
        }
        public void The_service_configuration_should_override_appconfig()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            azureSettings.Stub(x => x.TryGetSetting(
                Arg.Is("TestConfigSection.StringSetting"),
                out Arg<string>.Out("test").Dummy))
                .Return(true);

            Assert.AreEqual(configSource.GetConfiguration<TestConfigSection>().StringSetting, "test");
        }
Esempio n. 11
0
        public void Overrides_should_be_possible_for_non_existing_sections()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            azureSettings.Stub(x => x.TryGetSetting(
                                   Arg.Is("SectionNotPresentInConfig.SomeSetting"),
                                   out Arg <string> .Out("test").Dummy))
            .Return(true);

            Assert.AreEqual(configSource.GetConfiguration <SectionNotPresentInConfig>().SomeSetting, "test");
        }
Esempio n. 12
0
        public void Value_types_should_be_converted_from_string_to_its_native_type()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            azureSettings.Stub(x => x.TryGetSetting(
                                   Arg.Is("TestConfigSection.IntSetting"),
                                   out Arg <string> .Out("23").Dummy))
            .Return(true);

            Assert.AreEqual(configSource.GetConfiguration <TestConfigSection>().IntSetting, 23);
        }
Esempio n. 13
0
        /// <summary>
        /// Retrieve all classes decorated with ActiveRecordAttribute or that have been configured
        /// as a AR base class.
        /// </summary>
        /// <param name="assembly">Assembly to retrieve types from</param>
        /// <param name="list">Array to store retrieved types in</param>
        /// <param name="source">IConfigurationSource to inspect AR base declarations from</param>
        private static void CollectValidActiveRecordTypesFromAssembly(Assembly assembly, ICollection <Type> list,
                                                                      IConfigurationSource source)
        {
            registeredAssemblies.Add(assembly);
            Type[] types = GetExportedTypesFromAssembly(assembly);

            foreach (Type type in types)
            {
                if (IsActiveRecordType(type) || IsEventListener(type) || source.GetConfiguration(type) != null)
                {
                    list.Add(type);
                }
            }
        }
Esempio n. 14
0
        private SqlConnection CreateSqlConnection()
        {
            IConfigurationSource config = GetConfigSource();

            IConfiguration db2 = config.GetConfiguration(typeof(Test2ARBase));

            SqlConnection conn = null;

            foreach (IConfiguration child in db2.Children)
            {
                if (child.Name == "hibernate.connection.connection_string")
                {
                    conn = new SqlConnection(child.Value);
                }
            }

            return(conn);
        }
Esempio n. 15
0
 /// <summary>
 /// Returns true if any type in the configuration uses the ActiveRecord ByteCode.
 /// </summary>
 public static bool UseARByteCode(IConfigurationSource source, Type[] types)
 {
     foreach (var type in types)
     {
         var config = source.GetConfiguration(type);
         if (config != null)
         {
             foreach (var child in config.Children)
             {
                 if (child.Name == "proxyfactory.factory_class" &&
                     child.Value.Contains("Castle.ActiveRecord.ByteCode.ProxyFactoryFactory"))
                 {
                     return(true);
                 }
             }
         }
     }
     return(false);
 }
Esempio n. 16
0
 private static bool IsConfiguredAsRootType(Type type)
 {
     return(configSource.GetConfiguration(type) != null);
 }
        public void No_section_should_be_returned_if_both_azure_and_app_configs_are_empty()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            Assert.Null(configSource.GetConfiguration<SectionNotPresentInConfig>());
        }
		private static void SetUpConfiguration(IConfigurationSource source, Type type, ISessionFactoryHolder holder)
		{
			IConfiguration config = source.GetConfiguration(type);

			if (config != null)
			{
				Configuration nconf = CreateConfiguration(config);

				if (source.NamingStrategyImplementation != null)
				{
					Type namingStrategyType = source.NamingStrategyImplementation;

					if (!typeof(INamingStrategy).IsAssignableFrom(namingStrategyType))
					{
						String message =
							String.Format("The specified type {0} does " + "not implement the interface INamingStrategy",
							              namingStrategyType.FullName);

						throw new ActiveRecordException(message);
					}

					nconf.SetNamingStrategy((INamingStrategy) Activator.CreateInstance(namingStrategyType));
				}

				AddContributorsToConfig(type, nconf);
				holder.Register(type, nconf);
			}
		}
		/// <summary>
		/// Retrieve all classes decorated with ActiveRecordAttribute or that have been configured
		/// as a AR base class.
		/// </summary>
		/// <param name="assembly">Assembly to retrieve types from</param>
		/// <param name="list">Array to store retrieved types in</param>
		/// <param name="source">IConfigurationSource to inspect AR base declarations from</param>
		private static void CollectValidActiveRecordTypesFromAssembly(Assembly assembly, ICollection<Type> list,
		                                                              IConfigurationSource source)
		{
			registeredAssemblies.Add(assembly);
			Type[] types = GetExportedTypesFromAssembly(assembly);

			foreach(Type type in types)
			{
				if (IsActiveRecordType(type) || IsEventListener(type) || source.GetConfiguration(type) != null)
				{
					list.Add(type);
				}
			}
		}
Esempio n. 20
0
        public void The_service_configuration_should_override_appconfig()
        {
            azureSettings.Stub(x => x.GetSetting("TestConfigSection.StringSetting")).Return("test");

            Assert.AreEqual(configSource.GetConfiguration <TestConfigSection>().StringSetting, "test");
        }
Esempio n. 21
0
        public void No_section_should_be_returned_if_both_azure_and_app_configs_are_empty()
        {
            configSource = new AzureConfigurationSource(azureSettings, false);

            Assert.Null(configSource.GetConfiguration <SectionNotPresentInConfig>());
        }
 /// <summary>
 /// Returns true if any type in the configuration uses the ActiveRecord ByteCode.
 /// </summary>
 public static bool UseARByteCode(IConfigurationSource source, Type[] types)
 {
     foreach(var type in types)
     {
         var config = source.GetConfiguration(type);
         if(config != null)
         {
             foreach(var child in config.Children) 
             {
                 if (child.Name == "proxyfactory.factory_class" &&
                     child.Value.Contains("Castle.ActiveRecord.ByteCode.ProxyFactoryFactory"))
                 {
                     return true;
                 }
             }
         }
     }
     return false;
 }