示例#1
0
        public static void ThrowIfError2()
        {
            var nok = Fallible.FromError(Error);
            var ex  = Record.Exception(() => nok.ThrowIfError());

            Assert.NotNull(ex);
            Assert.IsType <SimpleException>(ex);
            Assert.Equal(ErrorMessage, ex.Message);
        }
示例#2
0
        public static void ThrowIfError2()
        {
            var error = "My message";
            var nok   = Result <Obj, SimpleException> .FromError(new SimpleException(error));

            var ex = Record.Exception(() => nok.ThrowIfError());

            Assert.NotNull(ex);
            Assert.IsType <SimpleException>(ex);
            Assert.Equal(error, ex.Message);
        }
示例#3
0
        public static void ValueOrThrow_Throws_IfError()
        {
            var nok = Fallible <Obj> .FromError(Error);

            Action act = () => nok.ValueOrThrow();
            var    ex  = Record.Exception(act);

            Assert.NotNull(ex);
            Assert.IsType <SimpleException>(ex);
            Assert.Equal(ErrorMessage, ex.Message);
        }
示例#4
0
        public static void State3()
        {
            var    message = "My message";
            Action act     = () => Require.State(false, message);

            var ex = Record.Exception(act);

            Assert.NotNull(ex);
            Assert.IsType <InvalidOperationException>(ex);
            Assert.Equal(message, ex.Message);
        }
示例#5
0
        public static void True2()
        {
            var    paramName = "paramName";
            Action act       = () => Require.True(false, paramName);

            var ex = Record.Exception(act);

            Assert.NotNull(ex);
            Assert.NotNull(ex.Message);
            var argex = Assert.IsType <ArgumentException>(ex);

            Assert.Equal(paramName, argex.ParamName);
        }
示例#6
0
        public static void NotNullOrWhiteSpace4()
        {
            var    paramName = "paramName";
            Action act       = () => Require.NotNullOrWhiteSpace(" ", paramName);

            var ex = Record.Exception(act);

            Assert.NotNull(ex);
            Assert.NotNull(ex.Message);
            var argex = Assert.IsType <ArgumentException>(ex);

            Assert.Equal(paramName, argex.ParamName);
        }
示例#7
0
        public static void NotNullUnconstrained2()
        {
            Object obj       = null;
            var    paramName = "paramName";
            Action act       = () => Require.NotNullUnconstrained(obj, paramName);

            var ex = Record.Exception(act);

            Assert.NotNull(ex);
            Assert.NotNull(ex.Message);
            var argex = Assert.IsType <ArgumentNullException>(ex);

            Assert.Equal(paramName, argex.ParamName);
        }
示例#8
0
        public static void True3()
        {
            var    paramName = "paramName";
            var    message   = "My message";
            Action act       = () => Require.True(false, paramName, message);

            var ex = Record.Exception(act);

            Assert.NotNull(ex);
            var argex = Assert.IsType <ArgumentException>(ex);

            Assert.Equal(paramName, argex.ParamName);
            // ArgumentException appends some info to our message.
            Assert.StartsWith(message, ex.Message, StringComparison.OrdinalIgnoreCase);
        }