我刚开始使用Moq,我正在尝试将值传递到Moq的方法中,以便在Returns方法中使用。 我成功地完成了以下工作。 _repositoryMock.Setup(x => x.GetByOrderId(It.IsAny<string>()))
.Returns((string id) => Task.FromResult(
new Order
{
Id = id
})); 代码中的用法: var
试图对存储库调用进行moq。
public async Task<T> GetFirstOrDefault<T>(Expression<Func<T, bool>> predicate) where T : class
{
return await WithQuery<T, T>(q => q.FirstOrDefaultAsync(predicate));
}
然后在我的单元测试中:
var ruleList = new List<Rule>() (Imagine my list here)
_mockR
我已经将行为隔离到下面的测试用例中。我将非常感谢任何人告诉我如何期望/验证List<T>属性的属性集--看起来It.Is<T>(predicate)内部正在发生一些事情,现在对我来说并不是很有意义。示例代码将作为VS2008的控制台应用程序运行-您需要添加对Moq2.6的引用(我在2.6.1014.1) -请尝试取消注释不同的ExpectSet语句,看看发生了什么……
using System;
using Moq;
using System.Collections.Generic;
namespace MoqDemo {
public interface
我有一个这种类型的表达式:
Expression<Action<T>> expression
如何从该表达式中获取参数名称(可选: and values)?
示例:
o => o.Method("value1", 2, new Object());
名称可以是str_par1、int_par2、obj_par3
在重构一些F#代码时,我遇到了一个我无法理解或解决的问题。我有一个类问题,有两个构造函数,一个默认用于F#消费,另一个用于C#便利性,它接受Funcs并将其“转换”为F#函数:
open System
type Problem<'d, 's> (data: 'd, generate: 'd -> Random -> 's, mutate: 'd -> Random -> 's -> 's, evaluate: 's -> float) =
member this.D
我正面临着这个错误 [xUnit.net 00:00:03.08] Moq.MockException :
[xUnit.net 00:00:03.08] Expected invocation on the mock at least once, but was never performed: s => s.Create(ContactScore, It.IsAny<IDbConnection>())
[xUnit.net 00:00:03.08]
[xUnit.net 00:00:03.08] Performed i
我尝试在Mono2.8.2上编译这个moq示例,目标是.NET 3.5,使用MonoDevelop 2.4.1。
using System;
using Moq;
namespace moq_demo
{
public interface IFoo
{
bool DoSomething(string n);
}
class MainClass
{
public static void Main (string[] args)
{
var mock = new Mock<IF
只是在computercraft中胡闹,试图使用一个函数作为参数,但无法使其工作
bla = function() print("bla") end
execfunc = function(func) func() end
execfunc(bla())
我想做一些如上所述的事情,但是使用工作代码,而不是这些废话
我正在使用Moq在C#中执行单元测试。一个测试,特别是我已经在System.Net.Mail.SmtpClient上创建了一个接口包装器,这样就可以对它进行模拟。
public class SmtpClient : ISmtpClient
{
public string Host { get; set; }
public int Port { get; set; }
public ICredentialsByHost Credentials { get; set; }
public bool EnableSsl { get; set; }
public
我正在努力解决如何使用Moq-设置-返回结构的问题。
首先,我的背景是:
一些类型为IRepository-Interface的存储库必须实现StoreAsync-Method,它返回一个带有存储实体的StoreResult对象作为包含的属性。
using System.Threading.Tasks;
using Moq;
using Xunit;
namespace Tests
{
public class Entity { }
public class StoreResult
{
public Entity Entity { get; set;
我有一个简单的数据模型与访问者(fName和lName)和访问(日期,评论)在一个1-m的关系。我正试着为某一天接见所有的访客。为了实现这一点,我需要创建一个谓词来查找从当天开始到结束访问的所有实体。我试过:
...
let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "visitor")
let filter = "ANY visits.date >= %@ AND ANY visits.date < %@" // visits is the visi
在Moq中,我希望断言使用特定参数调用方法TestMethod。当测试失败时,我希望看到一个有用的错误消息,类似于:
TestMethod以意外值X调用参数P,其中Y是预期的。
public interface ITestObject
{
void TestMethod(int parameter);
}
为了举例说明,我可以使用一个手写的模拟来实现这一点,如下所示:
Assert.AreEqual失败了。Expected:<3>。Actual:<2>。TestMethod以参数“实际”的意外值调用。
public class MockTestMetho
我有一个像这样的规格
describe MyClass do
it_behaves_like SharedClass, MyClass.new
end
在我的共享示例规范中,我有
shared_examples_for SharedClass do |instance|
before do
instance.some_my_class_method = double
end
# some specs here
end
在MyClass实例中,有一些方法不能存根到shared_examples_for块中,所以我希望在将它们传递到it_behaves_like语句之前先
我得到了这个奇怪的异常,我不知道如何找出这里出了什么问题
"Serious application error. **Exception was caught during Core Data change processing.** This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. **Can't look for value (552284302) in string (1070635162, 630076961, 690758
我正在模拟我的存储库接口,不确定如何设置一个接受表达式并返回对象的方法?我使用的是Moq和NUnit。
接口:
public interface IReadOnlyRepository : IDisposable
{
IQueryable<T> All<T>() where T : class;
T Single<T>(Expression<Func<T, bool>> expression) where T : class;
}
已经设置了IQueryable测试,但不知道如何设置T Single:
private
我有一个名为ProcessPayment()的方法,它是我通过BDD和mspec开发的。我需要一个新挑战的帮助。我的用户故事说:
Given a payment processing context,
When payment is processed with valid payment information,
Then it should return a successful gateway response code.
为了设置上下文,我使用Moq截断了我的网关服务。
_mockGatewayService = Mock<IGatewayService>();
_mock
我不知道如何在Moq中将参数从Setup()传递到pass ()。
下面是一个示例:
public static IInterfaceHandler GetInterfaceHandlerMoq()
{
// Defining the moq
var moq = new Mock<IInterfaceHandler>();
// Trying to set up a moq using another moq
moq.Setup(m => m.CreateCommunicationInterface(It.IsAny<Guid>(), I
我想知道以下过程声明之间是否有任何功能差异:
procedure spi_write_bus
(
spi_data_mosi : in DATA_BURST;
spi_data_miso : in DATA_BURST;
spi_data_lenght : in natural;
signal spi_mosi : out std_logic;
signal spi_miso : out std_logic;
signal spi_clk_en : out std_logic;
signal spi_cs : out std_l