【问题标题】:Is it possible to use 'HttpRuntime' in a NUnit project?是否可以在 NUnit 项目中使用“HttpRuntime”?
【发布时间】:2019-10-02 14:44:34
【问题描述】:

我正在关注guide,将 Visual Studio 的输出数据写入谷歌电子表格。我将 NUnit 项目类型用于测试自动化目的。

在指南的最后有一个我粘贴到我的项目中的代码块:

using OpenQA.Selenium.Support.UI;
using System;
using NUnit.Framework;
using OpenQA.Selenium;
using System.Collections;
using System.Collections.Generic;
using Google.Apis.Sheets.v4;
using Google.Apis.Auth.OAuth2;
using System.IO;
using Google.Apis.Services;
using Newtonsoft.Json;
using WikipediaTests.Foundation_Class;

namespace AutomationProjects
{
    [TestFixture]
    public class TestClass : TestFoundation
    {
        public class SpreadSheetConnector
        {
        //Codeblock from guide pasted here!
        }
        [Test]
        public void test1()
        {
         //Test case 1. Do XYZ...
        }
    }
}

guide 包含的代码块中有一段读取 JSON 凭证文件:

private void ConnectToGoogle()
{
    GoogleCredential credential;                
    using (var stream = new FileStream(Path.Combine(HttpRuntime.BinDirectory, "Export Project-03e8aa07234e.json"),
        FileMode.Open, FileAccess.Read))
    {
        credential = GoogleCredential.FromStream(stream).CreateScoped(_scopes);
    }

    //...

但我收到一个错误,提示“HttpRuntime”:Error CS0103 The name 'HttpRuntime' does not exist in the current context

VS 没有建议添加新的“使用”引用,所以我假设这不是问题。

那么可能是什么问题?到整个代码块:guide

【问题讨论】:

    标签: c# selenium unit-testing nunit httpruntime


    【解决方案1】:

    简短的回答 - 是的。

    长答案 - 我相信您需要在此处添加 System.Web dll。默认情况下,C# 项目不会添加所有依赖项,而是为您提供潜在引用列表,并让用户根据需要进行选择。

    在您的项目下,找到Dependencies 部分。右键单击,然后单击Add Reference。在Assemblies 下,找到System.Web 并选中它旁边的框,然后单击确定。

    添加后,您需要将using System.Web 添加到文件顶部。

    本指南也可能有所帮助:https://docs.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs-2019

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-10
      • 1970-01-01
      • 2012-05-15
      • 2017-06-30
      • 2019-05-25
      • 1970-01-01
      • 2016-11-25
      • 2018-08-22
      相关资源
      最近更新 更多