【问题标题】:How to write NUnit test for this method using the interface for mocking?如何使用模拟接口为此方法编写 NUnit 测试?
【发布时间】:2011-01-31 19:35:59
【问题描述】:

这是我拥有的 WCF 接口和类的精确表示。

我想知道如何为此编写一个 NUnit 测试...使用模拟接口。

主要是我不想为 WCF 服务集成测试添加服务引用。但是单元测试部分更集中一些东西。专门用来测试 ProcessStuff 方法。

namespace CompanyName.Services.ProcessStuff {
 public class ProcessStuffService : IProcessStuff
    {

        public string ProcessStuff(string input)
        {
            ISomeOtherInterface ProcessManager = new ProcessManager();
            return ProcessManager.ProcessStuff(input);            
        }

    }
}


namespace CompanyName.Common.FacadeInterfaces
{
    [ServiceContract(Namespace = "com.companyname.services", Name = "Process Stuff Service")]
    public interface IProcessStuff
    {
        [OperationContract(Name = "ProcessStuff")]
        string ProcessStuff(string input);
    }
}

【问题讨论】:

    标签: c# wcf unit-testing nunit mocking


    【解决方案1】:

    好的,我可能读错了这个问题,所以请随时澄清。

    如果被测方法是:

    ProcessManager.ProcessStuff(input)
    

    IProcessStuff 接口无关紧要。您将创建一个新的流程管理器并调用此方法。

    // You would pass mocks IN to the process manager if it required them here...
    var processManager = new ProcessManager();
    var result = processManager.ProcessStuff(testInput);
    Assert.IsNotNull(result);
    

    所以在这种情况下,我看不到您要模拟的接口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-17
      相关资源
      最近更新 更多