public void CanConstructUsingConstructorWithFormattedMessageParameterAndObjectArrayParamsFormatArgumentWithFourArgsAsObjectArray()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a four values: {0}, {1}, {2} and {3}.";

            const int value1 = 123;
            object arg0 = value1;
            const bool value2 = false;
            object arg1 = value2;
            const string value3 = "Hello";
            object arg2 = value3;
            const string value4 = "World";
            object arg3 = value4;

            object[] args = new[] { arg0, arg1, arg2, arg3 };

            const string expectedMessage = "This is a test exception with a four values: 123, False, Hello and World.";

            // Act
            TestException testException = new TestException(messageFormat, args);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #2
0
        public virtual void TestSuppressedExceptions()
        {
            // test with prior exception
            try
            {
                TestException t = new TestException();
                IOUtils.CloseWhileHandlingException(t, new BrokenIDisposable(1), new BrokenIDisposable(2));
            }
            catch (TestException e1)
            {
                Assert.IsTrue(e1.Data.Contains("SuppressedExceptions"));
                Assert.IsTrue(((List<Exception>) e1.Data["SuppressedExceptions"]).Count == 2);
            }
            catch (Exception e2)
            {
                Assert.Fail("Exception should not be thrown here");
            }

            // test without prior exception
            try
            {
                IOUtils.CloseWhileHandlingException((TestException)null, new BrokenIDisposable(1), new BrokenIDisposable(2));
            }
            catch (IOException e1)
            {
                Assert.IsTrue(e1.Data.Contains("SuppressedExceptions"));
                Assert.IsTrue(((List<Exception>)e1.Data["SuppressedExceptions"]).Count == 1);
            }
            catch (Exception e2)
            {
                Assert.Fail("Exception should not be thrown here");
            }
        }
Пример #3
0
        public void DetailedMessageIsExceptionStackTrace()
        {
            const string stacktrace = "some stack trace error of code issues";
            var exception = new TestException("msg", stacktrace);

            var sut = new FailureResult(TEST_NAME, exception);

            Assert.AreEqual(exception.Message, sut.DetailedMessage);
        }
Пример #4
0
 public void It_should_display_inner_exception_in_ToString()
 {
     try
     {
         var testEx = new TestException();
         throw new ColomboException("ColomboExceptionMessage", testEx);
     }
     catch (ColomboException ex)
     {
         Assert.That(ex.ToString(), Contains.Substring("TestExceptionContent"));
     }
 }
        public void Constructor_HappyPath_InitializesCorrectExceptionMessage()
        {
            var e = new TestException("Problem in A.", new[] {"try x", "try y", "try z"}, null);

            Assert.That(e.Message ==
                        @"Problem in A.
            Suggestions:
             - try x
             - try y
             - try z
            ");
        }
        public void TestTypeAliasException()
        {
            var serializer = new ProtobufSerializer(null);

            var exception = new TestException { ErrorCode = 1000, ErrorDetail = "Test" };
            var obj = new ResponseMessage { Exception = exception };
            var bytes = serializer.ToBinary(obj);

            var obj2 = (ResponseMessage)serializer.FromBinary(bytes, null);
            Assert.Equal(obj.Exception.GetType(), obj2.Exception.GetType());

            var exception2 = (TestException)obj2.Exception;
            Assert.Equal(exception.ErrorCode, exception2.ErrorCode);
            Assert.Equal(exception.ErrorDetail, exception2.ErrorDetail);
        }
Пример #7
0
 public void It_should_display_inner_exception_for_aggregate_exception_in_ToString()
 {
     try
     {
         var testEx = new TestException();
         var testEx2 = new TestException2();
         var aggregateException = new AggregateException(testEx, testEx2);
         throw new ColomboException("ColomboExceptionMessage", aggregateException);
     }
     catch (ColomboException ex)
     {
         Console.WriteLine(ex);
         Assert.That(ex.ToString(),
             Contains.Substring("TestExceptionContent")
             .And.Contains("TestException2Content"));
     }
 }
        public void CanConstructUsingConstructorWithFormattedMessageParameterAndObjectArrayParamsFormatArgumentWithOneArg()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a value of {0}.";

            const int value = 123;

            const string expectedMessage = "This is a test exception with a value of 123.";

            // Act
            TestException testException = new TestException(messageFormat, value);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void ContinueWithActionInterfaceContinuationTest()
        {
            var operation = new AsyncOperation<bool>();
            IOperationResult<bool> operationResult = OperationResult
                .CreateResult(OperationType.PageNavigation, this, true, DataContext.Empty);
            var exception = new TestException();
            var continuationAction = new ActionContinuationMock
            {
                Invoke = result =>
                {
                    throw exception;
                }
            };

            var continueWith = operation.ContinueWith(continuationAction);
            continueWith.IsCompleted.ShouldBeFalse();
            operation.SetResult(operationResult);

            continueWith.IsCompleted.ShouldBeTrue();
            continueWith.Result.IsFaulted.ShouldBeTrue();
            continueWith.Result.Exception.ShouldEqual(exception);
        }
        public void ContinueWithFunctionInterfaceGenericContinuationToOperationCallbackTest()
        {
            var operation = new AsyncOperation<bool>();
            IOperationResult<bool> operationResult = OperationResult
                .CreateResult(OperationType.PageNavigation, this, true, DataContext.Empty);
            var exception = new TestException();
            var continuationFunction = new FunctionContinuationMock<bool, object>
            {
                Invoke = result =>
                {
                    throw exception;
                }
            };

            var continueWith = operation.ContinueWith(continuationFunction);
            continueWith.IsCompleted.ShouldBeFalse();
            operation.ToOperationCallback().Invoke(operationResult);

            continueWith.IsCompleted.ShouldBeTrue();
            continueWith.Result.IsFaulted.ShouldBeTrue();
            continueWith.Result.Exception.ShouldEqual(exception);
        }
Пример #11
0
        public void TestExceptionFromIdlNetSerializable() {
            // check, that the generated exception is serializable also with other formatters, i.e. implements ISerializable correctly
            TestException ex = new TestException();
            ex.Code = 2;
            ex.Msg = "msg";
            System.Runtime.Serialization.Formatters.Binary.BinaryFormatter formatter =
                new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
            System.IO.MemoryStream serialised = new System.IO.MemoryStream();
            try {
                formatter.Serialize(serialised, ex);

                serialised.Seek(0, System.IO.SeekOrigin.Begin);
                formatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                TestException deser = (TestException)formatter.Deserialize(serialised);
                Assertion.AssertEquals("ex.Code", ex.Code, deser.Code);
                Assertion.AssertEquals("ex.Msg", ex.Msg, deser.Msg);
            } finally {
                serialised.Close();
            }

        }
        public void CanConstructUsingConstructorWithFormattedMessageParameterAndThreeFormatArguments()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a three values: {0}, {1} and {2}.";

            const int value1 = 123;
            object arg0 = value1;
            const bool value2 = false;
            object arg1 = value2;
            const string value3 = "Hello";
            object arg2 = value3;

            const string expectedMessage = "This is a test exception with a three values: 123, False and Hello.";

            // Act
            TestException testException = new TestException(messageFormat, arg0, arg1, arg2);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #13
0
 private void DoError()
 {
     var err = new TestException(Message ?? "testerror").ErrorRecord;
     if (NoError.IsPresent)
     {
         if (Message != null)
         {
             Host.UI.WriteLine(Message);
         }
     }
     else if (Terminating.IsPresent)
     {
         ThrowTerminatingError(err);
     }
     else
     {
         WriteError(err);
     }
 }
        public void CanConstructUsingConstructorWithInnerExceptionAndFormattedMessageParameterAndTwoFormatArguments()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a two values: {0} and {1}.";

            const int value1 = 123;
            object arg0 = value1;
            const bool value2 = false;
            object arg1 = value2;

            const string expectedMessage = "This is a test exception with a two values: 123 and False.";

            const string expectedArgumentMessage = "This is a test argument exception.";
            ArgumentException testInnerException = new ArgumentException(expectedArgumentMessage);

            // Act
            TestException testException = new TestException(testInnerException, messageFormat, arg0, arg1);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNotNull(testException.InnerException);
            Assert.AreSame(testInnerException, testException.InnerException);
            Assert.AreEqual(expectedArgumentMessage, testException.InnerException.Message);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #15
0
 public bool ThrowTestException() {
     TestException result = new TestException();
     result.Msg = "test-msg";
     result.Code = 1;
     throw result;
 }
        public void CanConstructUsingConstructorWithInnerExceptionAndFormattedMessageParameterAndObjectArrayParamsFormatArgumentWithFourArgs()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a four values: {0}, {1}, {2} and {3}.";

            const int value1 = 123;
            const bool value2 = false;
            const string value3 = "Hello";
            const string value4 = "World";

            const string expectedMessage = "This is a test exception with a four values: 123, False, Hello and World.";

            const string expectedArgumentMessage = "This is a test argument exception.";
            ArgumentException testInnerException = new ArgumentException(expectedArgumentMessage);

            // Act
            TestException testException = new TestException(testInnerException, messageFormat, value1, value2, value3, value4);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNotNull(testException.InnerException);
            Assert.AreSame(testInnerException, testException.InnerException);
            Assert.AreEqual(expectedArgumentMessage, testException.InnerException.Message);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #17
0
        public void FatalWithFormatted()
        {
            var messagesLogged = 0;
            var exception = new TestException(LogSeverity.Fatal);

            var formatArgs = MakeMessage(LogSeverity.Fatal, withException: false);
            var format = formatArgs.Item1;
            var args = formatArgs.Item2;
            var formatted = string.Format(format, args);
            var messageReturned = logger.Site().FatalAndReturnFormatted(format, args);
            Assert.AreEqual(LogSeverity.Fatal, sink.LastMessageSeverity);
            StringAssert.Contains(formatted, sink.LastMessage);
            StringAssert.Contains(messageReturned, sink.LastMessage);
            Assert.IsNull(sink.LastException);
            Assert.AreEqual(messagesLogged + 1, sink.MessagesReceived);
            messagesLogged++;
            sink.Clear();

            formatArgs = MakeMessage(LogSeverity.Fatal, withException: true);
            format = formatArgs.Item1;
            args = formatArgs.Item2;
            formatted = string.Format(format, args);
            messageReturned = logger.Site().FatalAndReturnFormatted(exception, format, args);
            Assert.AreEqual(LogSeverity.Fatal, sink.LastMessageSeverity);
            StringAssert.Contains(formatted, sink.LastMessage);
            StringAssert.Contains(messageReturned, sink.LastMessage);
            Assert.NotNull(sink.LastException);
            Assert.AreEqual(LogSeverity.Fatal, ((TestException)sink.LastException).Severity);
            Assert.AreEqual(messagesLogged + 1, sink.MessagesReceived);
        }
        public void CanConstructUsingConstructorWithInnerExceptionAndFormattedMessageParameterAndObjectArrayParamsFormatArgumentWithThreeArgsAsObjectArray()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a three values: {0}, {1} and {2}.";

            const int value1 = 123;
            object arg0 = value1;
            const bool value2 = false;
            object arg1 = value2;
            const string value3 = "Hello";
            object arg2 = value3;

            object[] args = new[] { arg0, arg1, arg2 };

            const string expectedMessage = "This is a test exception with a three values: 123, False and Hello.";

            const string expectedArgumentMessage = "This is a test argument exception.";
            ArgumentException testInnerException = new ArgumentException(expectedArgumentMessage);

            // Act
            TestException testException = new TestException(testInnerException, messageFormat, args);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNotNull(testException.InnerException);
            Assert.AreSame(testInnerException, testException.InnerException);
            Assert.AreEqual(expectedArgumentMessage, testException.InnerException.Message);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingConstructorWithMessageParameterWithEmptyStringValue()
        {
            // Arrange
            const string expectedMessage = "";

            // Act
            TestException testException = new TestException(string.Empty);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingConstructorWithMessageParameter()
        {
            // Arrange
            const string expectedMessage = "This is a test exception.";

            // Act
            TestException testException = new TestException(expectedMessage);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingConstructorWithMessageAndInnerExceptionParameters()
        {
            // Arrange
            const string expectedMessage = "This is a test exception.";
            const string expectedArgumentMessage = "This is a test argument exception.";
            ArgumentException testInnerException = new ArgumentException(expectedArgumentMessage);

            // Act
            TestException testException = new TestException(expectedMessage, testInnerException);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNotNull(testException.InnerException);
            Assert.AreSame(testInnerException, testException.InnerException);
            Assert.AreEqual(expectedArgumentMessage, testException.InnerException.Message);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingConstructorWithFormattedMessageParameterAndObjectArrayParamsFormatArgumentWithTwoArgsAsObjectArray()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a two values: {0} and {1}.";

            const int value1 = 123;
            object arg0 = value1;
            const bool value2 = false;
            object arg1 = value2;

            object[] args = new[] { arg0, arg1 };

            const string expectedMessage = "This is a test exception with a two values: 123 and False.";

            // Act
            TestException testException = new TestException(messageFormat, args);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #23
0
 public void TestExceptions()
 {
     var t = new TestException();
 }
Пример #24
0
 public virtual void TestDetailerMessage()
 {
     var message = "Detailed message";
     var e = new TestException(message, new Exception("The reason!"));
     Assert.IsGreaterOrEqual(0, e.ToString().IndexOf(message));
 }
        public void GetServiceCallerTest()
        {
            // Arrange.
            var serviceGuid1 = new Guid("{71B4DAD4-8AF1-438B-8E0D-5BD50F90E3F9}");
            var serviceGuid2 = new Guid("{6C6115F1-5CB4-4417-B28F-6A3A5563804B}");
            var invalidGuid = new Guid("{692A348B-C92A-41B9-8EBA-5855F8E1EBEE}");

            var callDefinition1 = new Mock<IServiceCallDefinition>();
            callDefinition1.Setup(x => x.Guid).Returns(serviceGuid1);

            var callDefinition2 = new Mock<IServiceCallDefinition>();
            callDefinition2.Setup(x => x.Guid).Returns(serviceGuid2);

            var serviceCaller1 = new Mock<IServiceCaller>();

            var serviceCallerFactory = new Mock<IServiceCallerFactory>();
            serviceCallerFactory.Setup(x => x.CreateServiceCaller(callDefinition1.Object)).Returns(serviceCaller1.Object);

            var exception = new TestException();
            serviceCallerFactory.Setup(x => x.CreateServiceCaller(callDefinition2.Object)).Throws(exception);

            var logger = new Mock<ILogger>();

            var callsManager = new TestServiceCallsManager { ServiceCallerFactory = serviceCallerFactory.Object, Logger = logger.Object };
            callsManager.Initialize(new[] { callDefinition1.Object, callDefinition2.Object });

            // Act.
            TestsHelper.VerifyThrow<ArgumentException>(() => callsManager.GetServiceCaller(invalidGuid));
            TestsHelper.VerifyThrow<InvalidOperationException>(() => callsManager.GetServiceCaller(serviceGuid2));
            
            var result = callsManager.GetServiceCaller(serviceGuid1);

            // Assert.
            Assert.AreSame(serviceCaller1.Object, result);
            logger.Verify(x => x.Log(LogSeverity.Error, It.IsAny<string>(), exception), Times.Once());
        }
        public void CanConstructUsingConstructorWithMessageParameterWithNullValue()
        {
            // Arrange
            const string expectedMessage = "Exception of type 'System.TestException' was thrown.";

            // Act
            TestException testException = new TestException(null);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingConstructorWithInnerExceptionAndFormattedMessageParameterAndOneFormatArgument()
        {
            // Arrange
            const string messageFormat = "This is a test exception with a value of {0}.";

            const int value = 123;
            object arg0 = value;

            const string expectedMessage = "This is a test exception with a value of 123.";

            const string expectedArgumentMessage = "This is a test argument exception.";
            ArgumentException testInnerException = new ArgumentException(expectedArgumentMessage);

            // Act
            TestException testException = new TestException(testInnerException, messageFormat, arg0);

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNotNull(testException.InnerException);
            Assert.AreSame(testInnerException, testException.InnerException);
            Assert.AreEqual(expectedArgumentMessage, testException.InnerException.Message);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
        public void CanConstructUsingDefaultConstructor()
        {
            // Arrange
            const string expectedMessage = "Exception of type 'System.TestException' was thrown.";

            // Act
            TestException testException = new TestException();

            // Assert
            Assert.IsNotNull(testException);
            Assert.IsNull(testException.InnerException);
            Assert.AreEqual(expectedMessage, testException.Message);
        }
Пример #29
0
        public void Levels()
        {
            // Make sure we're testing all severities.
            CollectionAssert.AreEquivalent(allSeverities, levelLoggers.Keys);
            CollectionAssert.AreEquivalent(allSeverities, exceptionLevelLoggers.Keys);

            var messagesLogged = 0;

            foreach (var severity in allSeverities)
            {
                var logIt = levelLoggers[severity];
                var logItEx = exceptionLevelLoggers[severity];
                var exception = new TestException(severity);

                var formatArgs = MakeMessage(severity, withException: false);
                var format = formatArgs.Item1;
                var args = formatArgs.Item2;
                var message = string.Format(format, args);
                logIt(logger, format, args);
                Assert.AreEqual(severity, sink.LastMessageSeverity);
                StringAssert.Contains(message, sink.LastMessage);
                Assert.IsNull(sink.LastException);
                Assert.AreEqual(messagesLogged + 1, sink.MessagesReceived);
                messagesLogged++;
                sink.Clear();

                formatArgs = MakeMessage(severity, withException: true);
                format = formatArgs.Item1;
                args = formatArgs.Item2;
                message = string.Format(format, args);
                logItEx(logger, exception, format, args);
                Assert.AreEqual(severity, sink.LastMessageSeverity);
                StringAssert.Contains(message, sink.LastMessage);
                Assert.NotNull(sink.LastException);
                Assert.AreEqual(severity, ((TestException)sink.LastException).Severity);
                Assert.AreEqual(messagesLogged + 1, sink.MessagesReceived);
                messagesLogged++;
                sink.Clear();
            }
        }