Exemplo n.º 1
0
        public void BasicConfigWrongTypeInListenerMissingAssembly()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\BasicConfigMissingAssembly.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "Could not load file or assembly 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Tests' or one of its dependencies. The system cannot find the file specified.");
        }
Exemplo n.º 2
0
        public void ThrowsArgumentNullExceptionWhenHadlingExceptionWithNullPolicy()
        {
            var policies = new Dictionary <string, ExceptionPolicyDefinition>();
            ExceptionManager exceptionManager = new ExceptionManager(policies);

            ExceptionAssertHelper.Throws <ArgumentNullException>(() => exceptionManager.HandleException(new Exception(), null));
        }
Exemplo n.º 3
0
        public void ThrowsExceptionHandlingExceptionWhenPostHandlingIsNotifyRethrowAndExceptionShouldBeHandled()
        {
            var originalException = new DBConcurrencyException();

            ExceptionAssertHelper.Throws <ExceptionHandlingException>(() =>
                                                                      this.exceptionManager.HandleException(originalException, "Throwing when DBConcurrencyException, NotifyRethrow postHandling"));
        }
Exemplo n.º 4
0
        public void WhenFormatterTypeNotFound()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\WithWrongFormatterParameter2.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "Could not load type 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Formatters' from assembly 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging'.");
        }
Exemplo n.º 5
0
        public void WhenUsingWrongFormatter()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\WithWrongFormatter.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "Could not load type 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.OutProc.Tests.CustomFormatterWithWait' from assembly 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.OutProc.Tests'.");
        }
Exemplo n.º 6
0
        public void WhenCustomSinkConstructionFails()
        {
            var exc = ExceptionAssertHelper.Throws <Exception>(() => TraceEventServiceConfiguration.Load("Configurations\\CustomSink\\CustomSqlDBNotAllParams.xml"));

            StringAssert.Contains(exc.ToString(), "Value cannot be null");
            StringAssert.Contains(exc.ToString(), "Parameter name: instanceName");
        }
Exemplo n.º 7
0
        public void GetWrongUserReplacesException()
        {
            using (var subscription = obsListener.LogToSqlDatabase("test", TracingDatabaseConnectionString, bufferingCount: 1))
            {
                string username = "******";
                var    roles    = new[] { "Employee" };
                Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);

                var repository = new UserRepository(ldapStore, exceptionMgr, container);

                //assert that the friendly excetpion is thrown to the UI
                var ex = ExceptionAssertHelper.Throws <NotifyException>(() => repository.GetUser(username));

                subscription.Sink.FlushAsync().Wait();

                var entries = DatabaseHelper.GetAllLogEntries(TracingDatabaseConnectionString);
                Assert.AreEqual(2, entries.Count);
                Assert.IsTrue(entries.Any(e => e.Level == (int)EventLevel.Error));
                Assert.IsTrue(entries.Any(e => e.EventId == 1000));
                Assert.IsTrue(entries.Any(e => e.Payload.Contains(Resources.UserNotRegisteredMessage)));

                Assert.IsNotNull(ex, "Exception not thrown");
                StringAssert.Contains(ex.Message, Resources.FriendlyMessage);
            }
        }
Exemplo n.º 8
0
        public void GetWrongUserReplacesException()
        {
            string username = "******";
            var    roles    = new[] { "Employee" };

            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), roles);

            var repository = new UserRepository(LDAPStore, exceptionMgr, container);

            //assert that the friendly excetpion is thrown to the UI
            var ex = ExceptionAssertHelper.Throws <NotifyException>(
                () => repository.GetUser(username));

            Assert.IsNotNull(ex, "Exception not thrown");
            StringAssert.Contains(ex.Message, Resources.FriendlyMessage);

            //assert that the inner execption is logged to the database

            var errors = DatabaseHelper.GetExceptionsFromDB(LoggingDatabaseConnectionString);
            var error  = errors.FirstOrDefault();

            Assert.IsNotNull(error, "Inner exception not logged to the db");
            StringAssert.Contains(error.FormattedMessage, Resources.UserNotRegisteredMessage);
            StringAssert.Contains(error.Title, Resources.NotifyExceptionTitle);
        }
        public void ThrowsArgumentExceptionWhenPolicyNameIsEmpty()
        {
            var excepionPolicies = new List <ExceptionPolicyDefinition>();

            ExceptionAssertHelper.Throws <ArgumentException>(() =>
                                                             excepionPolicies.Add(new ExceptionPolicyDefinition(string.Empty, new List <ExceptionPolicyEntry>())));
        }
Exemplo n.º 10
0
        public void EmptyKeywords()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\EmptyKeyword.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "The 'matchAnyKeyword' attribute is invalid - The value '' is invalid according to its datatype");
        }
Exemplo n.º 11
0
        public void BasicConfigWrongTypeInListener()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\BasicConfigWrongType.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "Could not load type 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.OutProc.Tests.TestObjects.Foo' from assembly 'Microsoft.Practices.EnterpriseLibrary.SemanticLogging.OutProc.Tests'.");
        }
Exemplo n.º 12
0
        public void ThrowsExceptionHandlingExceptionWhenUsingProcessWithNonMatchingPolicy()
        {
            var policies         = new Dictionary <string, ExceptionPolicyDefinition>();
            var exceptionManager = new ExceptionManager(policies);

            ExceptionAssertHelper.Throws <ExceptionHandlingException>(() => exceptionManager.Process(() => { throw new DBConcurrencyException(); }, "NonMatchingPolicy"));
        }
Exemplo n.º 13
0
        public void ThrowsExceptionHandlingExceptionWhenHadlingExceptionWithPolicyThatDoesNotExist()
        {
            var policies         = new Dictionary <string, ExceptionPolicyDefinition>();
            var exceptionManager = new ExceptionManager(policies);

            ExceptionAssertHelper.Throws <ExceptionHandlingException>(() => exceptionManager.HandleException(new Exception(), "NonMatchingPolicy"));
        }
Exemplo n.º 14
0
        public void SinkNameIsLongerThan200Chars()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\LongSinkName.xml"));

            StringAssert.Contains(exc.ToString(), "The 'name' attribute is invalid - The value");
            StringAssert.Contains(exc.ToString(), "The actual length is greater than the MaxLength value.");
        }
Exemplo n.º 15
0
        public void TwoListenersSameNameShouldNotBeAllowed()
        {
            var validConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["valid"].ConnectionString;

            DatabaseHelper.CleanLoggingDB(validConnectionString);
            var logger = MockEventSourceOutProc.Logger;

            EventSourceSettings settings = new EventSourceSettings("MockEventSourceOutProc", null, EventLevel.LogAlways);
            var subject = new EventEntrySubject();

            subject.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(10), 200);
            SinkSettings sinkSettings = new SinkSettings("dbSink", subject, new List <EventSourceSettings>()
            {
                { settings }
            });
            var subject2 = new EventEntrySubject();

            subject2.LogToSqlDatabase("testInstance", validConnectionString, "Traces", TimeSpan.FromSeconds(10), 200);
            SinkSettings sinkSettings2 = new SinkSettings("dbSink", subject2, new List <EventSourceSettings>()
            {
                { settings }
            });
            List <SinkSettings> sinks = new List <SinkSettings>()
            {
                sinkSettings, sinkSettings2
            };
            var exc = ExceptionAssertHelper.
                      Throws <Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Etw.Configuration.ConfigurationException>(
                () => new TraceEventServiceConfiguration(sinks));

            StringAssert.Contains(exc.ToString(), "Duplicate sinks");
        }
Exemplo n.º 16
0
        public void StringKeywords()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\StringKeyword.xml"));

            StringAssert.Contains(exc.ToString(), "One or more errors occurred when loading the TraceEventService configuration file.");
            StringAssert.Contains(exc.ToString(), "The 'matchAnyKeyword' attribute is invalid - The value 'Database' is invalid according to its datatype 'http://www.w3.org/2001/XMLSchema:long' - The string 'Database' is not a valid Int64 value.");
        }
        public void WhenSessionNameIsTooLong()
        {
            // session name should not be more than 200 chars
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\LongSessionPrefix.xml"));

            StringAssert.Contains(exc.ToString(), "The 'sessionNamePrefix' attribute is invalid - The value");
            StringAssert.Contains(exc.ToString(), "The actual length is greater than the MaxLength value.");
        }
        public void WhenDuplicateSinkNames()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\TwoSinksSameName.xml"));

            string expectedMessage = "There is a duplicate key sequence 'listener1'";

            StringAssert.Contains(exc.ToString(), expectedMessage);
        }
Exemplo n.º 19
0
        public void OutProcRollingFlatFileEmptyTimeStampPattern()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\RollingFlatFile\\RollingFlatFileEmptyTimeStampPattern.xml"));

            string expectedMessage = "The 'timeStampPattern' attribute is invalid - The value '' is invalid according to its datatype";

            StringAssert.Contains(exc.ToString(), expectedMessage);
        }
Exemplo n.º 20
0
        public void WhenEmptyDateTime()
        {
            MockConsoleOutput mockConsole = new MockConsoleOutput();

            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\Console\\ConsoleEmptyDateTimeFormat.xml"));

            StringAssert.Contains(exc.ToString(), "The 'dateTimeFormat' attribute is invalid - The value '' is invalid according to its datatype ");
        }
        public void WhenCustomSinkSchemaHasMissingAttribute()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\InnerSchemaValidation2.xml"));

            string expectedMessage = "The required attribute 'name' is missing.";

            StringAssert.Contains(exc.ToString(), expectedMessage);
        }
Exemplo n.º 22
0
        public void WhenFilePathIsInvalid()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\FlatFile\\FlatWrongFormatInFile.xml"));

            string fullExc = exc.ToString();

            StringAssert.Contains(fullExc, "The given path's format is not supported.");
        }
Exemplo n.º 23
0
        public void ThrowsArgumentNullExceptionWhenProcessingNullPolicy()
        {
            var policies         = new Dictionary <string, ExceptionPolicyDefinition>();
            var exceptionManager = new ExceptionManager(policies);

            ExceptionAssertHelper.Throws <ArgumentNullException>(
                () => exceptionManager.Process(() => { }, null));
        }
Exemplo n.º 24
0
        public void WhenEmptyMaxArchiveFiles()
        {
            var exc = ExceptionAssertHelper.Throws <ConfigurationException>(() => TraceEventServiceConfiguration.Load("Configurations\\RollingFlatFile\\RollingFlatFileEmptyMaxArchiveFiles.xml"));

            string expectedMessage = "The 'maxArchivedFiles' attribute is invalid - The value '' is invalid according to its datatype";

            StringAssert.Contains(exc.ToString(), expectedMessage);
        }
Exemplo n.º 25
0
        public void ThrowsWrapedExceptionWhenPostHandlingIsThrowNewExceptionAndExceptionShouldBeHandled()
        {
            var originalException = new DBConcurrencyException();

            BusinessException thrownException = ExceptionAssertHelper.Throws <BusinessException>(() =>
                                                                                                 this.exceptionManager.HandleException(originalException, "Wrap DBConcurrencyException into BusinessException, ThrowNewException postHandling"));

            Assert.AreSame(originalException, thrownException.InnerException);
        }
        public void ThrowsArgumentExceptionWhenPolicyNameIsEmpty()
        {
            ConfigurationSourceBuilder builder = new ConfigurationSourceBuilder();

            ExceptionAssertHelper.Throws <ArgumentException>(() =>
                                                             builder.ConfigureExceptionHandling()
                                                             .GivenPolicyWithName(string.Empty)
                                                             .ForExceptionType <Exception>().ThenDoNothing());
        }
        public void WrongUserThrows()
        {
            string username = "******";

            var ex = ExceptionAssertHelper.Throws <ArgumentException>(
                () => LDAPStore.GetAttributesFor(username, new[] { "costCenter", "manager", "displayName" }));

            Assert.AreEqual(Resources.UserDoesNotExistInLDAPMessage, ex.Message);
        }
Exemplo n.º 28
0
        public void ThrowsReplacedExceptionWhenPostHandlingIsThrowNewExceptionAndExceptionShouldBeHandled()
        {
            var originalException = new DBConcurrencyException();

            BusinessException thrownException = ExceptionAssertHelper.Throws <BusinessException>(() =>
                                                                                                 this.exceptionManager.HandleException(originalException, "Replace DBConcurrencyException with BusinessException, ThrowNewException postHandling"));

            Assert.IsNotNull(thrownException);
            Assert.IsTrue(typeof(BusinessException).IsAssignableFrom(thrownException.GetType()));
        }
Exemplo n.º 29
0
        public void ProcessThrowsOriginalExceptionWhenPostHandlingIsThrowNewExceptionAndExceptionShouldNotBeHandled()
        {
            var originalException = new ApplicationException();

            ApplicationException thrownException = ExceptionAssertHelper.Throws <ApplicationException>(() =>
                                                                                                       this.exceptionManager.Process(
                                                                                                           () => { throw originalException; },
                                                                                                           "Wrap DBConcurrencyException into BusinessException, ThrowNewException postHandling"));

            Assert.AreSame(originalException, thrownException);
        }
Exemplo n.º 30
0
        public void ProcessThrowsOriginalExceptionWhenPostHandlingIsNotifyRethrowAndExceptionShouldNotBeHandled()
        {
            var originalException = new ApplicationException();

            ApplicationException thrownException = ExceptionAssertHelper.Throws <ApplicationException>(() =>
                                                                                                       this.exceptionManager.Process(
                                                                                                           () => { throw originalException; },
                                                                                                           "Replace DBConcurrencyException with BusinessException, NotifyRethrow postHandling"));

            Assert.AreSame(originalException, thrownException);
        }