简体   繁体   中英

C# Web Service Unit Tests

I have the following Entity:

Amount

Currency -  String

Value -  decimal

I have also a wcf service that uses this entity and I want to make a unit test to this class.

My problem is that I want test invalid values to the Value in the entity and if I try to assign in in the c#

Amout m = new Amout{Currency = "EUR", Value = "aaaa"} 

gave error.

How can I test this situation?

For example I can make the following request in soapUI:

<itc1:Amount>
  <itc2:Currency>EUR</itc2:Currency>
  <itc2:Value>aaaaaa</itc2:Value>
</itc1:Amount>

and I get error from the service.

I want to make the same with an unit test.

I hope you can help me.

Are you looking for something like this :

    [TestMethod()]
    [ExpectedException(typeof(KnownExceptionType))]
    public void Test()
    {
        //Do something that throws a KnownExceptionType 
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM