- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如何使用 Moq 创建纯 stub ?使用 Rhino Mocks,我是这样做的:
[TestFixture]
public class UrlHelperAssetExtensionsTests
{
private HttpContextBase httpContextBaseStub;
private RequestContext requestContext;
private UrlHelper urlHelper;
private string stylesheetPath = "/Assets/Stylesheets/{0}";
[SetUp]
public void SetUp()
{
httpContextBaseStub = MockRepository.GenerateStub<HttpContextBase>();
requestContext = new RequestContext(httpContextBaseStub, new RouteData());
urlHelper = new UrlHelper(requestContext);
}
[Test]
public void PbeStylesheet_should_return_correct_path_of_stylesheet()
{
// Arrange
string expected = stylesheetPath.FormatWith("stylesheet.css");
// Act
string actual = urlHelper.PbeStylesheet();
// Assert
Assert.AreEqual(expected, actual);
}
}
我将如何为 MockRepository.GenerateStub<HttpContextBase>();
创建 stub 使用最小起订量?还是我应该继续使用 Rhino Mocks?
最佳答案
这是我给你的建议:
Mock<HttpContextBase> mock = new Mock<HttpContextBase>();
mock.SetupAllProperties();
然后您必须进行设置。
有关更多信息,请参阅 homepage of the MOQ project.
关于c# - 如何使用 Moq 创建 stub ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8241887/
我有一个测试,我像这样传入一个对象: var repo = new ActualRepo(); var sut = new Sut(repo); 在我的测试中,Repo 有一个我需要实际执行的方法,而
想知道是否有可能将 Prism 事件聚合器最小化 让我们以他们拥有的EventAggregator快速入门为例 [TestMethod] public void Presente
我正在 mock MSMQ 的包装器。包装器只是允许创建一个直接调用 MessageQueue 类的静态方法的对象实例。 我想测试阅读队列是否筋疲力尽。为此,我希望模拟包装器返回一些好的结果,并在第四
我正在尝试开始使用最小起订量,但无法找到任何好的资源来做我需要的事情。 我有一个数据接口(interface)类,它有一个通过存储过程返回数据集的 Get 方法。这就是代码的编写方式,我目前无法更改它
我想使用 Moq 框架。我想下载框架,所以我到达了http://code.google.com/p/moq/通过谷歌,但第一行提到这个项目已转移到GitHub。当我去 GitHub 时,我只看到了源代
我想看看 Moq 是否是我想在新项目中使用的东西,因为我使用的其他模拟框架正在挑战恕我直言。例如,我有一个方法: IEnumerable GetPickLists(); 我不确定我应该如何 mock
这看起来很简单,但我似乎无法让它工作。 我有一个带有 Save 方法的类,它只调用另一个方法 ShouldBeCalled()。我想验证如果我调用 Save() 另一个方法 ShouldBeCalle
我正在修改一个类方法,它格式化一些输入参数日期,这些日期随后在方法调用中用作参数到基类(位于另一个程序集中)。 我想验证我传递给我的方法的日期在传递给基类方法时的格式是否正确,因此我想对基类方法调用进
我有以下方法: public CustomObect MyMethod() { var lUser = GetCurrentUser(); if (lUser.HaveAccess)
我有一个对象,我正在尝试使用最小起订量来模拟。该对象的构造函数具有必需的参数: public class CustomerSyncEngine { public CustomerSyncEng
我找不到对齐的 moq 和 moq contrib 版本。我可能只是谷歌失败了。 详情: 是否有适用于 moq 版本 4.0.10827 的 moq.contrib 版本,最新版本来自 http://
有没有人试过这个? 我喜欢最小起订量,我喜欢 pex 正在做的事情,但还没有一起尝试过。我认为在大多数情况下,我更喜欢使用 moq 而不是痣,但很想知道是否有人遇到了障碍? 他们玩得好吗? 最佳答案
VerABLE() 的目的是什么? 如果我验证 Mock 并将其保留,它仍然会验证 SetUp。 编辑:我使用的是VerifyAll(),因此所有内容都被验证。更改为 Verify() 后,仅检查我的
我在一个使用 Moq 和 AutoFixture.AutoMoq 的特定项目的构建服务器上运行单元测试时遇到问题。这是错误: System.IO.FileLoadException : Could n
我正在尝试创建一个具体类的模拟,并用另一个模拟来模拟它的一个属性。 public class MyClass { public virtual IAdapter Adapter {get; int
我无法使用 Moq (v.4.2) 在 protected 方法上设置回调。 代码如下所示: public abstract class AbstractClass { protected a
我在我的测试约定中使用 AutoMoqCustomization。 考虑下面的代码。一切都很好,直到我向其中一个具体类添加构造函数。当我这样做时,我得到“找不到无参数构造函数”。我们知道 AutoFi
在 Moq 中模拟 protected 虚拟(非通用)方法很容易: public class MyClass { .... protected virtual int MyMethod(D
如何验证是否使用 Moq 调用了“CallWithRef”方法? public interface ITest { void CallWithoutRef(string value, List
在我的单元测试中使用 Moq 生成 stub 和模拟,我有一个案例,我想验证是否调用了采用 Delegate 参数的方法。我不关心提供的特定 Delegate 参数,我只想确保该方法实际上被调用。该方
我是一名优秀的程序员,十分优秀!