【问题标题】:How to shim HttpWebRequest如何填充 HttpWebRequest
【发布时间】:2013-04-16 09:21:12
【问题描述】:

我在尝试填充 HttpWebRequest 时遇到问题。 如果您只是添加系统程序集的伪造程序集,它不会立即工作。 但是,如果您更改 fakes 文件并添加它可以工作的特定命名空间。

<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
  <Assembly Name="System" Version="4.0.0.0"/>
  <ShimGeneration>
    <Clear/>
    <Add FullName="System.Net.WebRequest!"/>
    <Add FullName="System.Net.HttpWebRequest!"/>
    <Add FullName="System.Net.HttpWebResponse!"/>
  </ShimGeneration>
</Fakes>

问题是这只适用于本地。尝试解析 ShimHttpWebRequest 时,Team Foundation Server 上的自动构建会引发错误。看起来自动构建忽略了假文件,因为当我在构建服务器上使用 VS 手动构建它时,它可以工作。

【问题讨论】:

  • 其他类型的垫片有用吗?
  • 构建服务器抛出了哪个异常?什么是调用栈?哪个测试运行程序(MSTest 或 VSTest)正在构建服务器上运行测试?
  • 您是否尝试将 Fakes 程序集添加到构建服务器?

标签: unit-testing mstest tfsbuild microsoft-fakes


【解决方案1】:

我也有同样的问题。尝试提交到项目主目录中的 build-server 目录“FakesAssemblies”。

【讨论】:

    【解决方案2】:

    转到程序集参考并添加 System.Net 假程序集。双击 System.Net.Fake 文件并在 System.Net.Fake 文件中添加以下条目

    <Fakes xmlns="http://schemas.microsoft.com/fakes/2011/" Diagnostic="true">
    <Assembly Name="System" Version="4.0.0.0"/>
    <StubGeneration>
      <Clear/>
    </StubGeneration>
    <ShimGeneration>
       <Clear/>
       <Add FullName="System!"/>
       <Add FullName="System.Net!"/>
       <Add FullName="System.Net.WebRequest!"/>
       <Add FullName="System.Net.HttpWebRequest!"/>
       <Add FullName="System.Net.HttpWebResponse!"/>
     </ShimGeneration>
     </Fakes>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-30
      • 2012-02-15
      • 1970-01-01
      • 2012-06-26
      • 2020-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多