小编Mik*_*ike的帖子

使用Moq,如何使用out参数模拟受保护的方法?

对于像这样的方法:

protected virtual bool DoSomething(string str) { }
Run Code Online (Sandbox Code Playgroud)

我经常嘲笑它:

var mockModule = new Mock<MyClass> { CallBase = true };
mockModule.Protected().Setup<bool>("DoSomething", ItExpr.IsAny<string>()).Returns(true);
Run Code Online (Sandbox Code Playgroud)

但对于像这样的方法:

protected virtual bool DoSomething(out string str) { }
Run Code Online (Sandbox Code Playgroud)

我怎么嘲笑它?

c# unit-testing moq

7
推荐指数
2
解决办法
3808
查看次数

如何在rspec中模拟实例变量

我有两个类OneClassAnotherClass:

class OneClass
  def initialize(*args)
    @another_member = AnotherClass.new()
  end

  def my_method()
    if @another_member.another_method1() then
      @another_member.another_method2()
    end
    @another_member.another_method3()
  end
end
Run Code Online (Sandbox Code Playgroud)

我正在写单位OneClass.我怎么能嘲笑@another_member

rspec

6
推荐指数
2
解决办法
3793
查看次数

如何在运行时更改 NLog 规则目标?

我有原始配置:

<rules>
    <logger name="Logger" minlevel="Trace" writeTo="FileLog,syslog" />
</rules>
Run Code Online (Sandbox Code Playgroud)

它将打印到文件以及发送到服务器。

我希望在运行时更改目标,有时更改为 FileLog,有时更改为 syslog,有时更改为两者。有可编程的方式吗?

.net nlog

4
推荐指数
1
解决办法
1831
查看次数

标签 统计

.net ×1

c# ×1

moq ×1

nlog ×1

rspec ×1

unit-testing ×1