Beispiel #1
0
        public void TryCatch_Return_1()
        {
            // Setup
            var ex   = new Exception();
            var mock = new Mock <ITryCatchFinally>();

            mock.Setup(m => m.Try <string>()).Returns("Test");

            var m = mock.Object;

            // Act
            var returnValue = Try.CatchReturn(m.Try <string>, m.Catch);

            // Assert
            Assert.Equal("Test", returnValue);

            mock.Verify(m => m.Try <string>(), Times.Once);
            mock.Verify(m => m.Catch(It.IsAny <Exception>()), Times.Never);
        }
Beispiel #2
0
        public void TryCatch_Return_2()
        {
            // Setup
            var ex   = new Exception();
            var mock = new Mock <ITryCatchFinally>();

            mock.Setup(m => m.Try <string>()).Throws(ex);

            var m = mock.Object;

            // Act
            var returnValue = Try.CatchReturn(m.Try <string>, m.Catch, defaultValue: "Test");

            // Assert
            Assert.Equal("Test", returnValue);

            mock.Verify(m => m.Try <string>(), Times.Once);
            mock.Verify(
                m => m.Catch(It.Is <Exception>(e => ReferenceEquals(e, ex))),
                Times.Once);
        }