Mercurial > pub > bltoolkit
view HowTo/Aspects/NotNull.cs @ 9:1e85f66cf767 default tip
update bltoolkit
author | nickolay |
---|---|
date | Thu, 05 Apr 2018 20:53:26 +0300 |
parents | f990fcb411a9 |
children |
line wrap: on
line source
using System; using NUnit.Framework; using BLToolkit.Aspects; using BLToolkit.Reflection; namespace HowTo.Aspects { [TestFixture] public class NotNullTest { public /*[a]*/abstract/*[/a]*/ class TestObject { public /*[a]*/virtual/*[/a]*/ void Foo1(string str1, [/*[a]*/NotNull/*[/a]*/] string str2, string str3) {} public /*[a]*/virtual/*[/a]*/ void Foo2(string str1, [/*[a]*/NotNull/*[/a]*/(/*[a]*/"Null"/*[/a]*/)] string str2, string str3) {} public /*[a]*/virtual/*[/a]*/ void Foo3(string str1, [/*[a]*/NotNull/*[/a]*/(/*[a]*/"Null: {0}"/*[/a]*/)] string str2, string str3) {} public static TestObject CreateInstance() { return /*[a]*/TypeAccessor/*[/a]*/<TestObject>.CreateInstance(); } } [Test, ExpectedException(typeof(ArgumentNullException))] // Error message is localized by framework. public void Test1() { TestObject o = TestObject.CreateInstance(); o.Foo1("str1", /*[a]*/null/*[/a]*/, "str3"); } [Test] [ExpectedException(typeof(ArgumentNullException), ExpectedMessage="Null")] public void Test2() { TestObject o = TestObject.CreateInstance(); o.Foo2("str1", /*[a]*/null/*[/a]*/, "str3"); } [Test] [ExpectedException(typeof(ArgumentNullException), ExpectedMessage="Null: str2")] public void Test3() { TestObject o = TestObject.CreateInstance(); o.Foo3("str1", /*[a]*/null/*[/a]*/, "str3"); } } }