public void InstrumentationIsWiredUpCorrectlyWhenConfigurationSectionIsPresent()
        {
            EventSource source
                = EnterpriseLibraryFactory.BuildUp <EventSource>("ignore", configSource);

            Assert.IsTrue(source.IsWired);
        }
        public void InstrumentationAvoidsTryingToWireUpToObjectsWithNoListenerDefined()
        {
            NoListenerEventSource source
                = EnterpriseLibraryFactory.BuildUp <NoListenerEventSource>("ignore", configSource);

            Assert.IsFalse(source.IsWired);
        }
Exemplo n.º 3
0
        public void CanStillCreateLoggerWithoutConfigurationSectionPresent()
        {
            DictionaryConfigurationSource configSource = new DictionaryConfigurationSource();
            DefaultEventLogger            logger       = EnterpriseLibraryFactory.BuildUp <DefaultEventLogger>(configSource);

            Assert.IsFalse(logger.EventLoggingEnabled);
        }
Exemplo n.º 4
0
 public MsmqListener(DistributorService distributorService, int timerInterval, string msmqPath)
 {
     this.distributorService = distributorService;
     this.QueueTimerInterval = timerInterval;
     this.eventLogger        = distributorService.EventLogger;
     this.logDistributor     = new MsmqLogDistributor(EnterpriseLibraryFactory.BuildUp <LogWriter>(), msmqPath, this.eventLogger);
 }
        private void NullEncryptorTests(string instanceName)
        {
            MockStorageEncryptionProvider.Encrypted = false;
            MockStorageEncryptionProvider.Decrypted = false;

            CacheManagerSettings          settings               = (CacheManagerSettings)TestConfigurationSource.GenerateConfiguration().GetSection(CacheManagerSettings.SectionName);
            CacheStorageData              cacheStorageData       = settings.BackingStores.Get(settings.CacheManagers.Get(instanceName).CacheStorage);
            StorageEncryptionProviderData encryptionProviderData = settings.EncryptionProviders.Get(cacheStorageData.StorageEncryption);

            IStorageEncryptionProvider provider =
                EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>(encryptionProviderData.Name, TestConfigurationSource.GenerateConfiguration());

            Assert.IsNotNull(provider);

            byte[] input     = new byte[] { 0, 1, 2, 3, 4, 5 };
            byte[] encrypted = provider.Encrypt(input);

            Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted");

            Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed");

            byte[] decrypted = provider.Decrypt(encrypted);
            Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted");

            Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed");
            Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2");
        }
Exemplo n.º 6
0
        public void CanCreateSqlDatabase()
        {
            Database database = EnterpriseLibraryFactory.BuildUp <Database>("Service_Dflt");

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(SqlDatabase), database.GetType());
        }
Exemplo n.º 7
0
        private static ExceptionPolicyImpl GetExceptionPolicy(Exception exception, string policyName, ExceptionPolicyFactory factory)
        {
            try
            {
                return(factory.Create(policyName));
            }
            catch (ConfigurationErrorsException configurationException)
            {
                try
                {
                    DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>();
                    logger.LogConfigurationError(configurationException, policyName);
                }
                catch { }

                throw;
            }
            catch (Exception ex)
            {
                try
                {
                    string exceptionMessage = ExceptionUtility.FormatExceptionHandlingExceptionMessage(policyName, ex, null, exception);

                    DefaultExceptionHandlingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultExceptionHandlingEventLogger>();
                    logger.LogInternalError(policyName, exceptionMessage);
                }
                catch { }

                throw new ExceptionHandlingException(ex.Message, ex);
            }
        }
        public void InstrumentationNotWiredWhenConfigurationSectionNotPresent()
        {
            EventSource source
                = EnterpriseLibraryFactory.BuildUp <EventSource>("ignore", new DictionaryConfigurationSource());

            Assert.IsFalse(source.IsWired);
        }
        public void CanBuildLogWriterStructureHolder()
        {
            LogWriterStructureHolder setup
                = EnterpriseLibraryFactory.BuildUp <LogWriterStructureHolder>(configurationSource);

            Assert.IsNotNull(setup);
            Assert.AreEqual(2, setup.TraceSources.Count);
        }
Exemplo n.º 10
0
        public void CanCreateGenericDatabase()
        {
            Database database = EnterpriseLibraryFactory.BuildUp <Database>("OdbcDatabase");

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(GenericDatabase), database.GetType());
            DbCommand command = database.GetStoredProcCommand("ignore");

            Assert.AreSame(typeof(OdbcCommand), command.GetType());
        }
Exemplo n.º 11
0
 internal static void TryLogConfigurationFailure(ConfigurationErrorsException configurationException)
 {
     try
     {
         DefaultLoggingEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultLoggingEventLogger>();
         logger.LogConfigurationError(configurationException);
     }
     catch
     { }
 }
Exemplo n.º 12
0
        public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
        public void InstrumentationNotWiredWhenConfigurationValuesAllFalse()
        {
            DictionaryConfigurationSource section = new DictionaryConfigurationSource();

            section.Add(InstrumentationConfigurationSection.SectionName,
                        new InstrumentationConfigurationSection(false, false, false, "fooApplicationInstanceName"));
            EventSource source
                = EnterpriseLibraryFactory.BuildUp <EventSource>("ignore", new DictionaryConfigurationSource());

            Assert.IsFalse(source.IsWired);
        }
Exemplo n.º 14
0
        public void CanCreateThroughObjectBuilder()
        {
            DictionaryConfigurationSource       configSource  = new DictionaryConfigurationSource();
            InstrumentationConfigurationSection configSection = new InstrumentationConfigurationSection();

            configSection.EventLoggingEnabled = true;
            configSource.Add(InstrumentationConfigurationSection.SectionName, configSection);
            DefaultEventLogger logger = EnterpriseLibraryFactory.BuildUp <DefaultEventLogger>(configSource);

            Assert.IsTrue(logger.EventLoggingEnabled);
        }
Exemplo n.º 15
0
        public void CanBuildDefaultLogger()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(InstrumentationConfigurationSection.SectionName, new InstrumentationConfigurationSection(true, true, true));

            DefaultCachingEventLogger logger
                = EnterpriseLibraryFactory.BuildUp <DefaultCachingEventLogger>(configurationSource);

            Assert.IsNotNull(logger);
        }
        public void SetUp()
        {
            logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();
            MockTraceListener.Reset();
            ErrorsMockTraceListener.Reset();

            emptyTraceSource = new LogSource("none");
            if (emptyTraceSource.Listeners.Count == 1)
            {
                emptyTraceSource.Listeners.RemoveAt(0);
            }
        }
Exemplo n.º 17
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string instanceName)
 {
     try
     {
         DefaultDataEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultDataEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(configurationException, instanceName);
         }
     }
     catch { }
 }
Exemplo n.º 18
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string instanceName)
 {
     try
     {
         DefaultSecurityEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultSecurityEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(instanceName, Resources.ErrorAuthorizationConfigurationFailedMessage, configurationException);
         }
     }
     catch { }
 }
Exemplo n.º 19
0
        public void CanBuildCustomAuthorizationProviderFromSystemConfiguration()
        {
            IConfigurationSource configurationSource
                = new SystemConfigurationSource();

            IAuthorizationProvider custom
                = EnterpriseLibraryFactory.BuildUp <IAuthorizationProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomAuthorizationProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomAuthorizationProvider)custom).customValue);
        }
Exemplo n.º 20
0
 private static void TryLogConfigurationError(ConfigurationErrorsException configurationException, string hashInstance, string template)
 {
     try
     {
         DefaultCryptographyEventLogger eventLogger = EnterpriseLibraryFactory.BuildUp <DefaultCryptographyEventLogger>();
         if (eventLogger != null)
         {
             eventLogger.LogConfigurationError(hashInstance, template, configurationException);
         }
     }
     catch { }
 }
Exemplo n.º 21
0
        public void CanCreateOracleDatabase()
        {
            Database database = EnterpriseLibraryFactory.BuildUp <Database>("OracleTest");

            Assert.IsNotNull(database);
            Assert.AreSame(typeof(OracleDatabase), database.GetType());
            DbCommand dbCommand1 = database.GetStoredProcCommand(OracleTestStoredProcedureInPackageWithTranslation);

            Assert.AreEqual((object)OracleTestTranslatedStoredProcedureInPackageWithTranslation, dbCommand1.CommandText);
            DbCommand dbCommand2 = database.GetStoredProcCommand(OracleTestStoredProcedureInPackageWithoutTranslation);

            Assert.AreEqual((object)OracleTestStoredProcedureInPackageWithoutTranslation, dbCommand2.CommandText);
        }
        public void SetUp()
        {
            AppDomain.CurrentDomain.SetData("APPBASE", Environment.CurrentDirectory);

            logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();
            MockTraceListener.Reset();
            ErrorsMockTraceListener.Reset();

            emptyTraceSource = new LogSource("none");
            if (emptyTraceSource.Listeners.Count == 1)
            {
                emptyTraceSource.Listeners.RemoveAt(0);
            }
        }
Exemplo n.º 23
0
        public void InstrumentationIsTurnedOffWhenPassingNoConfigurationSource()
        {
            int initialValue = GetCounterValue(performanceCounterTracesPerSecondName, operation);

            LogWriter logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();

            using (Tracer tracer = new Tracer(operation, logWriter, null))
            {
                int i = new Random().Next();
            }
            int valueAfterTracing = GetCounterValue(performanceCounterTracesPerSecondName, operation);

            Assert.IsTrue(valueAfterTracing == initialValue);
        }
Exemplo n.º 24
0
        private static TracerInstrumentationListener GetInstrumentationListener(IConfigurationSource configurationSource)
        {
            TracerInstrumentationListener instrumentationListener;

            if (configurationSource != null)
            {
                instrumentationListener = EnterpriseLibraryFactory.BuildUp <TracerInstrumentationListener>(configurationSource);
            }
            else
            {
                instrumentationListener = new TracerInstrumentationListener(false);
            }

            return(instrumentationListener);
        }
Exemplo n.º 25
0
 public void UpdateLogWriter(object sender, ConfigurationChangedEventArgs args)
 {
     if (logWriter != null)
     {
         try
         {
             LogWriterStructureHolder newStructureHolder
                 = EnterpriseLibraryFactory.BuildUp <LogWriterStructureHolder>(configurationSource);
             logWriter.ReplaceStructureHolder(newStructureHolder);
         }
         catch (ConfigurationErrorsException configurationException)
         {
             logWriter.ReportConfigurationFailure(configurationException);
         }
     }
 }
            public static CacheManager Create(string name, IConfigurationSource configurationSource)
            {
                CachingConfigurationView configurationView   = new CachingConfigurationView(configurationSource);
                CacheManagerData         objectConfiguration = configurationView.GetCacheManagerData(name);

                IBackingStore backingStore =
                    EnterpriseLibraryFactory.BuildUp <IBackingStore>(objectConfiguration.CacheStorage, configurationSource);

                return(new MockCacheManagerFactoryHelper().BuildCacheManager(
                           name,
                           backingStore,
                           objectConfiguration.MaximumElementsInCacheBeforeScavenging,
                           objectConfiguration.NumberToRemoveWhenScavenging,
                           objectConfiguration.ExpirationPollFrequencyInSeconds,
                           new CachingInstrumentationProvider()));
            }
        public void LogWriterCanGetConfiguredCategories()
        {
            LogWriter logWriter = EnterpriseLibraryFactory.BuildUp <LogWriter>();

            LogSource source = null;

            foreach (string key in logWriter.TraceSources.Keys)
            {
                logWriter.TraceSources.TryGetValue(key, out source);
                Assert.IsNotNull(source, key);
                Assert.AreEqual(key, source.Name);
            }

            source = null;
            logWriter.TraceSources.TryGetValue("AppTest", out source);
            logWriter.Dispose();

            Assert.IsNotNull(source);
        }
Exemplo n.º 28
0
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            IStorageEncryptionProvider encryptionProvider = null;

            encryptionProvider = EnterpriseLibraryFactory.BuildUp <IStorageEncryptionProvider>("Fred");

            DataBackingStore encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];

            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.GetExpirations()[0].GetType());
        }
        public void CanBuildCustomHashProviderFromGivenConfiguration()
        {
            CustomHashProviderData customData
                = new CustomHashProviderData("custom", typeof(MockCustomHashProvider));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();

            settings.HashProviders.Add(customData);
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(CryptographyConfigurationView.SectionName, settings);

            IHashProvider custom
                = EnterpriseLibraryFactory.BuildUp <IHashProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomHashProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomHashProvider)custom).customValue);
        }
        public void CanBuildCustomBackingStoreFromGivenConfiguration()
        {
            CustomCacheStorageData customData
                = new CustomCacheStorageData("custom", typeof(MockCustomStorageBackingStore));

            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CacheManagerSettings settings = new CacheManagerSettings();

            settings.BackingStores.Add(customData);
            settings.CacheManagers.Add(new CacheManagerData("ignore", 0, 0, 0, "custom"));
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();

            configurationSource.Add(CacheManagerSettings.SectionName, settings);

            IBackingStore custom
                = EnterpriseLibraryFactory.BuildUp <IBackingStore>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomStorageBackingStore), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomStorageBackingStore)custom).customValue);
        }