Assert Not Null Or Empty - CSharp Microsoft.VisualStudio.TestTools.UnitTesting

CSharp examples for Microsoft.VisualStudio.TestTools.UnitTesting:Assert

Description

Assert Not Null Or Empty

Demo Code


using System.Threading.Tasks;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/* w ww .ja  v  a 2s .co m*/

public class Main{
        public static void NotNullOrEmpty(string o, string name)
        {
            Assert.NotNull(o, name);

            if (o.Length == 0)
            {
                name = name ?? "argument";
                throw new ArgumentException(String.Format("{0} cannot be empty", name));
            }
        }
        public static void NotNull(object o, string name)
        {
            if (o == null)
            {
                name = name ?? "argument";
                throw new ArgumentNullException(String.Format("{0} cannot be null", name));
            }
        }
}

Related Tutorials