Beispiel #1
0
        public void IsValid()
        {
            var attribute = new MustBeValidFileNameAttribute();

            Assert.AreEqual(true, attribute.IsValid(null));
            Assert.AreEqual(true, attribute.IsValid(DBNull.Value));
            Assert.AreEqual(false, attribute.IsValid(string.Empty));
            Assert.AreEqual(false, attribute.IsValid(" "));
            Assert.AreEqual(true, attribute.IsValid("abc.txt"));
            Assert.AreEqual(false, attribute.IsValid(@"C:\Windows\tmp\file.txt"));
            Assert.AreEqual(false, attribute.IsValid(@"C:\Wi|ndows\tmp"));
        }
Beispiel #2
0
        public void IsValidFail(object value)
        {
            var attribute = new MustBeValidFileNameAttribute();

            try
            {
                attribute.IsValid(value);

                Assert.Fail();
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("Value must be of type String.", ex.Message);
            }
        }