示例#1
0
        public void ExpressionsCanBeUsed_ToDefine_AnArgumentName()
        {
            var        paramName1 = string.Empty;
            ClassOuter paramName2 = null;

            var ex1 =
                Assert.Throws <ArgumentNullException>(() =>
                                                      Checker.NotNullArgument(null, () => paramName1));

            var ex2 =
                Assert.Throws <ArgumentNullException>(() =>
                                                      Checker.NotNullArgument(paramName2?.InnerProp?.InnerInnerProp,
                                                                              () => paramName2.InnerProp.InnerInnerProp));

            Assert.Equal("paramName1", ex1.ParamName);
            Assert.Equal("paramName2.InnerProp.InnerInnerProp", ex2.ParamName);
        }
示例#2
0
        public void ExpressionsCanBeUsed_ToDefine_AnArgumentNameInAllExtensionsMethods()
        {
            ClassOuter paramName = null;

            var ex1 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotNullArgument(null, () => paramName.InnerProp.InnerInnerProp));
            var ex2 = Assert.Throws <NullReferenceException>(() =>
                                                             Checker.NotNullObject(null, () => paramName.InnerProp.InnerInnerProp));
            var ex3 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotEmptyArgument(null, () => paramName.InnerProp.InnerInnerProp));
            var ex4 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotEmptyArgument(string.Empty, () => paramName.InnerProp.InnerInnerProp));
            var ex5 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotEmptyOrWhiteArgument(null, () => paramName.InnerProp.InnerInnerProp));
            var ex6 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotEmptyOrWhiteArgument(string.Empty,
                                                                                            () => paramName.InnerProp.InnerInnerProp));
            var ex7 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotEmptyOrWhiteArgument("      ",
                                                                                            () => paramName.InnerProp.InnerInnerProp));
            var ex8 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotNullOrEmptyArgument((int[])null,
                                                                                           () => paramName.InnerProp.InnerInnerProp));
            var ex9 = Assert.Throws <ArgumentNullException>(() =>
                                                            Checker.NotNullOrEmptyArgument(new int[0],
                                                                                           () => paramName.InnerProp.InnerInnerProp));

            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex1.ParamName);
            Assert.Equal("Object paramName.InnerProp.InnerInnerProp can not be null", ex2.Message);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex3.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex4.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex5.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex6.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex7.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex8.ParamName);
            Assert.Equal("paramName.InnerProp.InnerInnerProp", ex9.ParamName);
        }