c# - 最小起订量问题 - 仅在构建服务器 (TeamCity) 上

标签 c# teamcity moq

我有一个被模拟的接口(interface):

public interface IEmailService
{
    void SendAsHtml(string to, string from, string subject, string notification);
    void SendAsHtml(string to, string from, string subject, string notification, string[] cc);
}

它以前是一个带有 params string[] cc 的单一方法,但我在试图找出构建服务器上的错误时将这些方法分开。我真正想要的是一个严格的模拟,但我现在正在动态运行它,这样我就可以使用以下验证来比较结果:

emailService.Verify(es => es.SendAsHtml(accountEmail, fromEmail, subject, expectedEmailString));

参数与 accountEmail、fromEmail 和 subject 匹配 - 它是 expectedEmailString(在测试方法中通过 string.Format 构建)似乎不起作用。我在测试时将预期值和实际值写入控制台,在查看输出时它们在构建服务器上看起来是相同的。这是测试失败(这是我试图强制进行序数比较的变体):

Expected invocation on the mock at least once, but was never performed: es => es.SendAsHtml(.accountEmail, .fromEmail, .subject, It.Is(s => s.Equals(.expectedEmailString, StringComparison.Ordinal))) No setups configured.

Performed invocations: IEmailService.SendAsHtml("user@test.com", "sender@email.net", "asdfasdf", "long html string")

以下是我认为的相关设置(全部直接注入(inject)到被测 Controller ):

    var getPersonalAccount = new Mock<IGetPersonalAccount>(MockBehavior.Strict);
    getPersonalAccount.Setup(gpa => gpa.WithAccountId(userAccountId).Execute()).Returns(account);

    var emailService = new Mock<IEmailService>();

    var trialSettings = new Mock<TrialSettings>(MockBehavior.Strict);
    trialSettings.Setup(ts => ts.Length).Returns(trialLength);
    trialSettings.Setup(ts => ts.FromEmail).Returns(fromEmail);
    trialSettings.Setup(ts => ts.Subject).Returns(subject);

主题和发件人地址由试用设置返回,收件人电子邮件地址从帐户中删除。消息正文也使用帐户中的值进行格式化。

相关位:

  • TeamCity 7.1(内部版本 23907)- 尝试了 nunit 2.5.10 和 2.6 测试 运行者
  • .NET 4
  • NUnit 2.5.10.11092
  • 起订量 4.0.10827.0

最佳答案

因此,我最终只是删除了对巨大 HTML 字符串的“整个字符串”检查,并仅检查以确认我们注入(inject)到字符串中的值(通过 string.format)是否存在。这在本地和服务器上都通过。这并不理想,但我想这也不是世界上最糟糕的事情。

关于c# - 最小起订量问题 - 仅在构建服务器 (TeamCity) 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12460426/

相关文章:

c# - 图片框和图像映射的工具提示

c# - 如何根据 GUID 生成唯一的整数

c# - AutoMockContainer 支持具有非接口(interface)依赖性的自动模拟类

c# - .Net Core RC2 的 Moq.netcore 失败

javascript - MVC 列表框如何使用 jQuery 来选择所有,删除所有

c# - Web API - 上传到 Azure 存储时获取进度

maven - 在 TeamCity 中配置 cucumber 以仅使用标签运行单元测试 (Maven)

java - 通过 Maven/TeamCity 运行 IntelliJ 检查

teamcity - 是否可以在 TeamCity 中构建 "group"配置以共享依赖项?

c# - 起订量 : how can mock property and side Effect?