1. 程式人生 > >Util應用程式框架公共操作類(六):驗證擴充套件

Util應用程式框架公共操作類(六):驗證擴充套件

using System; using Microsoft.VisualStudio.TestTools.UnitTesting; namespace Util.Tests.Extensions { /// <summary> /// 驗證擴充套件測試 /// </summary> [TestClass] public class ValidateExtensionTest { /// <summary> /// 檢查空值,不為空則正常執行 /// </summary> [TestMethod]
public void TestCheckNull() { var test = new object(); test.CheckNull( "test" ); } /// <summary> /// 檢查空值,值為null則丟擲異常 /// </summary> [TestMethod] [ExpectedException( typeof( ArgumentNullException ) )] public
void TestCheckNull_Null_Throw() { try { object test = null; test.CheckNull( "test" ); } catch ( ArgumentNullException ex ) { Assert.IsTrue( ex.Message.Contains( "test" ), ex.Message ); throw; } }
/// <summary> /// 測試是否空值 /// </summary> [TestMethod] public void TestIsEmpty_String() { string value = null; Assert.IsTrue( value.IsEmpty() ); Assert.IsTrue( "".IsEmpty() ); Assert.IsTrue( " ".IsEmpty() ); Assert.IsFalse( "a".IsEmpty() ); } /// <summary> /// 測試是否空值 /// </summary> [TestMethod] public void TestIsEmpty_Guid() { Guid value = Guid.Empty; Assert.IsTrue( value.IsEmpty() ); value = Guid.NewGuid(); Assert.IsFalse( value.IsEmpty() ); } /// <summary> /// 測試是否空值 /// </summary> [TestMethod] public void TestIsEmpty_Guid_Nullable() { Guid? value = null; Assert.IsTrue( value.IsEmpty() ); value = Guid.Empty; Assert.IsTrue( value.IsEmpty() ); value = Guid.NewGuid(); Assert.IsFalse( value.IsEmpty() ); } } }