小编Luk*_*kas的帖子

switch语句C#的测试用例

我是C#和单元测试的新手。我需要为switch语句编写一个单元测试,并且我不得不承认我已经经历了很多尝试寻找内容的页面。有谁能给我一些如何创建的提示?请在下面我的代码:

public static Message create(String body)
{
    Message result = null;
    switch (body.ToArray()[0])
    {
        case 'S':
            //checking the regex for a sms message
            Match matchS = Regex.Match(body, @"[S][0-9]{9}\+[0-9]{12}");
            if (matchS.Success)
            {
                MessageBox.Show("This is SMS message");
                //if the regex will match a sms_message class will be started
                result = new Sms_Message(body.Substring(1));
            }
            //if the regex doesn't match the message should be displayed
            else throw new Exception("I don't like content!!!!!!!!!!");       
            break;
        case 'T':
            //checking the regex for a tweet message
            Match matchT …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing switch-statement

2
推荐指数
1
解决办法
4683
查看次数

标签 统计

c# ×1

switch-statement ×1

unit-testing ×1