c# - Cannot make nunit test exception to work .Using .net 2.0 -


for whatever reason cannot seem syntax right. how make following test work. have simple method testthrowexception , pass doing wrong here?

           [testfixture]             public class exceptionstests             {                        [test]                 public void when_calling_my_method_it_should_throw_an_exception()                 {                 //this not work                     person person=new person();                      personexception ex = assert.throws<personexception>(delegate { person.throwpersonexception(); },                                                              has.property("message").equalto("test person exception throw"));                  }             }              public class person             {                 public void throwexception()                 {                     throw new exception("test exception thrown");                 }                 public void throwpersonexception()                 {                     throw new customerexception("test person exception thrown");                 }                   public void throwargumentexception(string myparam)                 {                     throw new argumentexception("argument exception", myparam);                 }             }             [serializable]             public class personexception : exception             {                  public personexception()                 {                 }                  public personexception(string message)                     : base(message)                 {                 }                  public personexception(string message, exception inner)                     : base(message, inner)                 {                 }                  protected personexception(                     serializationinfo info,                     streamingcontext context)                     : base(info, context)                 {                 }             }         } 

apart issues type of exception throwing, this. think more readable.

[test] public void when_calling_my_method_it_should_throw_an_exception() {     person person=new person();     personexception ex = assert.throws<personexception>(delegate { person.throwpersonexception(); });     assert.that(ex.message,is.equalto("test person exception thrown"); } 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -