示例#1
0
        public void Validation_OnNoError_ReturnsValue()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName("BooBoo");//returns the value if valid

            Assert.Equal("BooBoo", v);
        }
示例#2
0
        public void Validation_OnError_DoesNotReturnValue()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName("FooBoo");//returns the value if valid

            Assert.NotEqual("FooBoo", v);
        }
示例#3
0
        public void Validation_OnNoError_IsValidIsTrue()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName("BooBoo");

            Assert.True(v.IsValid);
        }
示例#4
0
        public void Validation_OnInvalid_IsValidIsFalse()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName("foo");

            Assert.False(v.IsValid);
        }
示例#5
0
        public void Validation_OnError_IsValidIsFalse()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName(null);

            Assert.False(v.IsValid);
        }
示例#6
0
        public void GetOrElse_OnNoError_ReturnsValue()
        {
            var example = new ThrowMyToys();
            var v       = example.ValidateName("BooBoo");
            var result  = v.GetOrElse("Bob");

            Assert.Equal("BooBoo", result);
        }
示例#7
0
        public void Validation_OnError_ContainsErrors()
        {
            var example           = new ThrowMyToys();
            Validation <string> v = example.ValidateName("fooBoo");

            v.Match(
                Invalid: errors => Assert.Equal(2, errors.Count()),
                Valid: str => Assert.True(false)
                );
        }
示例#8
0
        public void GetOrElse_OnError_CallsFallback()
        {
            var           result   = false;
            Func <string> fallback = () => {
                result = true;
                return("Bob");
            };
            var example = new ThrowMyToys();
            var v       = example.ValidateName("FooBoo");

            var x = v.GetOrElse(fallback);

            Assert.True(result);
        }