我正在使用NUnit和NSubstitute编写C#单元测试.我正在测试一个类,它将尝试从实现以下接口的配置提供程序中检索对象:
public interface IConfigProvider<T> {
T GetConfig(int id);
T GetConfig(string id);
}
Run Code Online (Sandbox Code Playgroud)
正在测试的类只GetConfig在setUpFixture中使用int版本,我执行以下操作来设置一个总是返回相同虚拟对象的模拟配置提供程序:
IConfigProvider<ConfigType> configProvider = Substitute.For<IConfigProvider<ConfigType>>();
configProvider.GetConfig(Arg.Any<int>()).Returns<ConfigType>(new ConfigType(/* args */);
Run Code Online (Sandbox Code Playgroud)
如果TestFixture是唯一运行的TestFixture,则运行绝对正常.但是,在同一个程序集中的不同TestFixture中,我检查接收到的调用如下:
connection.Received(1).SetCallbacks(Arg.Any<Action<Message>>(), Arg.Any<Action<long>>(), Arg.Any<Action<long, Exception>>());
Run Code Online (Sandbox Code Playgroud)
如果这些Received测试在配置提供程序测试之前运行,则配置测试在SetUpFixture中失败并出现AmbiguousArgumentsException:
Here.Be.Namespace.ProfileManagerTests+Setup (TestFixtureSetUp):
SetUp : NSubstitute.Exceptions.AmbiguousArgumentsException : Cannot determine argument specifications to use.
Please use specifications for all arguments of the same type.
at NSubstitute.Core.Arguments.NonParamsArgumentSpecificationFactory.Create(Object argument, IParameterInfo parameterInfo, ISuppliedArgumentSpecifications suppliedArgumentSpecifications)
at System.Linq.Enumerable.<SelectIterator>d__7`2.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at NSubstitute.Core.Arguments.MixedArgumentSpecificationsFactory.Create(IList`1 argumentSpecs, Object[] arguments, IParameterInfo[] parameterInfos)
at NSubstitute.Core.Arguments.ArgumentSpecificationsFactory.Create(IList`1 argumentSpecs, Object[] arguments, IParameterInfo[] parameterInfos, MatchArgs …Run Code Online (Sandbox Code Playgroud) [注意 - 我解决了使用bash函数遇到的问题,但我想了解为什么我的初始尝试不起作用.
我在Windows中运行git,并使用Git Bash命令行应用程序来管理存储库.我有几个存储库,我经常想要一次性完成.以前我只是通过在命令行输入以下内容来执行此操作:
for i in *; do cd $i; git pull --rebase; cd ..; done;
Run Code Online (Sandbox Code Playgroud)
为了节省时间,我决定为此创建一个别名.所以,我在主目录中创建了一个.bashrc文件(在我的例子中为C:/ git)并添加了该行
alias pr="for i in *; do cd $i; git pull --rebase; cd ..; done;"
Run Code Online (Sandbox Code Playgroud)
然而,这根本不起作用,输出是
sh.exe" cd: /etc/profile.d/*.sh: No such file or directory
Run Code Online (Sandbox Code Playgroud)
然后git抱怨它不在存储库中.对于单个呼叫,输出将重复超过20次.MinGW文件系统的根,上面的/ etc派生自的地方,是我安装git到(C:/ Program Files(x86)/ Git)的地方.
现在,我通过在.bashrc文件中创建一个函数来解决这个问题,就像这样:
pr(){
for i in *
do
cd $i
git pull --rebase
cd ..
done
}
Run Code Online (Sandbox Code Playgroud)
所以,我的问题已经解决了,但我确实想了解为什么我的初始方法不起作用.显然有一些关于别名的东西,我不明白,大概是在'i in*'位.我的期望是bash会将别名映射的字符串替换为然后对其进行评估,但它似乎并不那么简单.