大家好。请教下大家一个问题。目前我有一个 helper 类型,用于读取webconfig 配置的内容。如下边的代码
/// <summary>
/// webconfig 的帮助类
/// </summary>
public static class WebConfig
{
    /// <summary>
    /// 根据枚举,返回相对应的值。
    /// </summary>
    public static string GetValue(Connections con)
    {
        //操作....
    }    /// <summary>
    /// webconfig 中的链接字符串列表。
    /// </summary>
    public enum Connections
    {
        Connection1,
        Connection2,
    }
}
根据枚举,读取 webconfig 中相对应选项中的内容
 <connectionStrings>
    <add name="Connection1" connectionString="省略....."/>
    <add name="Connection2" connectionString="省略....."/>
 </connectionStrings>
然后我有一个 GetValue 的测试方法。用于测试,输入的枚举类型
在 webconfig 中没有找到的特殊情况下,抛出异常。。
        /// <summary>
        /// GetValue 方法测试
        /// 断言:当参数传入的选项在
        /// webconfig 中没有找到的时候。
        /// 程序应该抛出异常。
        /// </summary>
        [TestMethod]
        public void GetValue_ReturnsExceptionWhenItemDoesNotExist()
        {
            try
            {
                //操作
                //自己假设存在 Connections.ErrorItem
                //WebConfig.GetValue(Connections.ErrorItem);                //断言
                Assert.Fail("测试失败,没有产生期望的异常。");
            }
            catch (Exception e)
            { 
                //断言
                Assert.AreEqual("webconfig中没有找到对应的项目", e.Message);
            }
        }
好了。现在的问题是:如何完成这个单元测试的方法呢。。?Connections 枚举本身不存在 ErrorItem这一项。。虽然可以在 Connections 枚举中加入 ErrorItem用以测试。。如下...
/// <summary>
    /// webconfig 中的链接字符串列表。
    /// </summary>
    public enum Connections
    {
        Connection1,
        Connection2,
        ErrorItem,
    }
但是测试通过之后,ErrorItem又要被删除掉了。。删除之后 GetValue_ReturnsExceptionWhenItemDoesNotExist 测试方法又失败了。。
= =! 希望各位看得明白我在说什么先谢谢了