public void Assert_ActionException()
        {
            Action TestCase(int testNumber, TestActual testActual, AssertException assertException, Exception expectedAssertException, Type expectedExceptionType = null) => () => {
                var msg = "No." + testNumber;

                // Act
                Exception exception_ = null;
                try {
                    testActual.Assert(assertException?.Invoke);
                }
                catch (Exception ex_) {
                    exception_ = ex_;
                }

                // Assert
                Assert.AreEqual(expectedExceptionType, exception_?.GetType(), msg);
                Assert.AreEqual(expectedAssertException, assertException?.InvokedParams, msg);
            };

            var ex = new DummyException();

            foreach (var action in new[] {
                TestCase(0, new TestActual(null), null, expectedAssertException: null, expectedExceptionType: typeof(ArgumentNullException)),
                TestCase(1, new TestActual(null), new AssertException(), expectedAssertException: null),
                TestCase(2, new TestActual(ex), null, expectedAssertException: null, expectedExceptionType: typeof(ArgumentNullException)),
                TestCase(3, new TestActual(ex), new AssertException(), expectedAssertException: ex),
            })
            {
                action();
            }
        }
        public void ExceptionTryGetMessageShouldThrowIfExceptionMessageThrows()
        {
            var errorMessage = string.Format(Resource.UTF_FailedToGetExceptionMessage, "System.NotImplementedException");
            var exception    = new DummyException(() => { throw new NotImplementedException(); });

            exception.TryGetMessage();
        }
        public void Construct()
        {
            var exception = new DummyException("This is a dummy");

            var resourceResult = new ExceptionResourceResult(exception);

            Assert.Equal(exception.ToString(), resourceResult.Message);
        }
Beispiel #4
0
        public void CallAbstractWarnWithException()
        {
            var loggerMock = new Mock <LoggerBase>();
            var exception  = new DummyException();

            loggerMock.Object.Warn("message Format", exception, new object[] { "One", 2 });

            loggerMock.Verify(l => l.Warn(It.IsAny <string>(), exception), Times.Once());
        }
Beispiel #5
0
        public void ReducePolicyOnError()
        {
            var ex = new DummyException("I am a problem.");

            Policy.RequestMetadataMock.Setup(r => r.ResponseContentType).Throws(ex);

            Assert.Equal(RuntimePolicy.Off, Policy.Execute(Policy.ContextMock.Object));
            Policy.LoggerMock.Verify(l => l.Warn(It.IsAny <string>(), ex, It.IsAny <object[]>()), Times.Once());
        }
Beispiel #6
0
        public void Ctor_Exception()
        {
            var ex = new DummyException();

            // Act
            var ret = new TestActual <DummyObject>(exception: ex);

            // Assert
            Assert.AreEqual(default, ret.Return);
        public void ConstructWithMessageAndInnerException()
        {
            var message        = "Testing";
            var innerException = new DummyException();
            var exception      = new GlimpseException(message, innerException);

            Assert.Equal(message, exception.Message);
            Assert.Equal(innerException, exception.InnerException);
        }
Beispiel #8
0
        public void ReduceRuntimePolicyOnException()
        {
            var exception = new DummyException("Houston, we have a problem");

            Policy.RequestMetadataMock.Setup(r => r.RequestUri).Throws(exception);

            Assert.Equal(RuntimePolicy.Off, Policy.Execute(Policy.ContextMock.Object));

            Policy.LoggerMock.Verify(l => l.Warn(It.IsAny <string>(), exception, It.IsAny <object[]>()), Times.Once());
        }
Beispiel #9
0
        public void SerializeCustomProperty()
        {
            DummyException  ex  = new DummyException();
            ReportException rex = ReportException.FromException(ex);

            foreach (ReportProperty p in rex.Properties)
            {
                if (p.Name == "Dummy")
                {
                    Assert.AreEqual(p.Value, ex.Dummy);
                    return;
                }
            }
            Assert.Fail("Dummy property not found");
        }
        public void SerializeCustomProperty()
        {
            DummyException ex = new DummyException();
            ReportException rex = ReportException.FromException(ex);

            foreach(ReportProperty p in rex.Properties)
            {
                if (p.Name == "Dummy")
                {
                    Assert.AreEqual(p.Value, ex.Dummy);
                    return;
                }
            }
            Assert.Fail("Dummy property not found");
        }
        public void Execute()
        {
            var providerMock = new Mock <IFrameworkProvider>();
            var contextMock  = new Mock <IResourceResultContext>();

            contextMock.Setup(c => c.FrameworkProvider).Returns(providerMock.Object);

            var exception = new DummyException("This is a dummy");

            var resourceResult = new ExceptionResourceResult(exception);

            resourceResult.Execute(contextMock.Object);

            providerMock.Verify(p => p.WriteHttpResponse(exception.ToString()));
            providerMock.Verify(p => p.SetHttpResponseStatusCode(500));
        }
Beispiel #12
0
        public void Equals()
        {
            Action TestCase(int testNumber, TestActual testActual, TestActual other, bool expected) => () => {
                Assert.AreEqual(expected, testActual.Equals(other)
                                , message: $"No.{testNumber}: Equals"
                                );

                Assert.AreEqual(expected, testActual.Equals((object)other)
                                , message: $"No.{testNumber}: Equals(object)"
                                );

                // 全く関係のない object との比較なので、常に false。
                Assert.AreEqual(false, testActual.Equals(new object())
                                , message: $"No.{testNumber}: Equals(new object)"
                                );

                Assert.AreEqual(expected, testActual == other
                                , message: $"No.{testNumber}: =="
                                );

                Assert.AreEqual(!expected, testActual != other
                                , message: $"No.{testNumber}: !="
                                );

                Assert.AreEqual(expected, ((object)testActual).Equals((object)other)
                                , message: $"No.{testNumber}: object.Equals(object)"
                                );

                // 固有型の == 演算子オーバーロードが機能しないので、常に false。
                Assert.AreEqual(false, (object)testActual == (object)other
                                , message: $"No.{testNumber}: object == object"
                                );
            };

            var ex = new DummyException();

            foreach (var action in new[] {
                TestCase(0, new TestActual(), new TestActual(), true),
                TestCase(1, new TestActual(ex), new TestActual(ex), true),
                TestCase(2, new TestActual(ex), new TestActual(new DummyException()), false),
            })
            {
                action();
            }
        }
Beispiel #13
0
 private void OnLogMessageReceived(string condition, string stackTrace, LogType type)
 {
     try
     {
         if (type != LogType.Exception)
         {
             return;
         }
         DummyException Ex = new DummyException(condition, stackTrace);
         if (IsOpened)
         {
             QueuedException.Add(Ex);
             return;
         }
         ExceptionMessage    = Ex.Message;
         ExceptionStackTrace = Ex.StackTrace;
         StartBannerAnimation(true);
     }
     catch (Exception)
     {
     }
 }
        public void Assert_ActionTReturn_ActionException()
        {
            Action TestCase(int testNumber, TestActual <DummyObject> testActual, AssertReturn @return, AssertException assertException, (DummyObject @return, Exception assertException) expected, Type expectedExceptionType = null) => () => {
                var msg = "No." + testNumber;

                // Act
                Exception exception_ = null;
                try {
                    testActual.Assert(@return?.Invoke, assertException?.Invoke);
                }
                catch (Exception ex_) {
                    exception_ = ex_;
                }

                // Assert
                Assert.AreEqual(expectedExceptionType, exception_?.GetType(), msg);
                Assert.AreEqual(expected.@return, @return?.InvokedParams, msg);
                Assert.AreEqual(expected.assertException, assertException?.InvokedParams, msg);
            };

            var obj = new DummyObject();
            var ex  = new DummyException();

            foreach (var action in new[] {
        public void ExceptionTryGetMessageReturnsEmptyStringIfExceptionMessageIsNull()
        {
            var exception = new DummyException(() => null);

            Assert.AreEqual(string.Empty, exception.TryGetMessage());
        }