今天我改为在我的代码中使用StringDictionary
而不是Dictionary<string,string>
,但是旧的单元测试失败了。所以我写了一个小单元测试来测试这个。
这是我的小测试:
using Rhino.Mocks;
using NUnit.Framework;
//using CustomDictionary = System.Collections.Specialized.StringDictionary;
using CustomDictionary = System.Collections.Generic.Dictionary<string, string>;
namespace ConsoleApplication1
{
public interface ITest
{
void DoSth(CustomDictionary dic);
}
public class OneTest : ITest
{
public void DoSth(CustomDictionary dic) {/*do nothing*/}
}
[TestFixture]
public class TestClass
{
[Test]
public void Test1()
{
var mockRepository = new MockRepository();
var test = mockRepository.StrictMock<ITest>();
using (mockRepository.Record())
{
Expect.Call(() => test.DoSth(new CustomDictionary { { "Test", "Test1" } }));
}
test.DoSth(new CustomDictionary { { "Test", "Test1" } });
mockRepository.VerifyAll();
}
}
}
如果我使用Dictionary<string,string>
,测试将通过,但是当我使用 时StringDictionary
,测试失败。
这里有什么问题?