public void IncludesNameInMessage()
        {
            var name      = "bad!";
            var exception = new InvalidNameException(name);

            Assert.StartsWith($"\"{name}\"", exception.Message);
            Assert.Equal(name, exception.Name);
        }
Example #2
0
        /// <summary>
        /// If obj is null, throws an ArgumentNullException.
        /// 
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        /// 
        /// Otherwise, returns the normalized version of name.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected string CorrectInput(string name, object obj)
        {
            Exception e = new InvalidNameException();
            if (obj == null)
                throw new ArgumentNullException();
            if (name == null)
                throw e;
            if (!Regex.IsMatch(name, @"^[a-zA-Z]+\d+$"))
                throw e;
            if (!IsValid(name))
                throw e;

            name = Normalize(name);

            return name;
        }
 public void InvalidNameExceptionConstructorTest()
 {
     InvalidNameException target = new InvalidNameException();
     Assert.IsTrue(target != null);
 }