C#Web服务单元测试

时间:2015-04-01 17:06:46

标签: c# testing soap

我有以下实体:

Amount

Currency -  String

Value -  decimal

我还有一个使用这个实体的wcf服务,我想对这个类进行单元测试。

我的问题是我希望测试无效值到实体中的值,如果我尝试在c#中分配输入

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

错误。

我该如何测试这种情况?

例如,我可以在soapUI中发出以下请求:

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

我从服务中得到错误。

我希望通过单元测试来做同样的事情。

我希望你能帮助我。

1 个答案:

答案 0 :(得分:1)

你在寻找这样的东西:

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