简体   繁体   English

一段代码在控制台应用程序中工作,但在nunit测试中不起作用

[英]piece of code works in console application, but does not works inside nunit test

Simple console application open connection without any problems: 简单的控制台应用程序打开连接没有任

    static void Main(string[] args)
    {
        string connectionString = String.Format(
           @"Provider=OraOLEDB.Oracle;PLSQLRSet=1;Password={0};Persist Security Info=True;User ID={1};Data Source={2};OLEDB.NET=true;FetchSize=5000",
            "pwd", "schema", "server");

        using (IDbConnection con = new OleDbConnection(connectionString))
        {
            con.Open();
            Console.WriteLine("Opened");
        }
        Console.ReadKey();
    }

but if try do same in the nunit test method: 但如果尝试在nunit测试方法中做同样的事情:

public class UnitTest1
{
    [Test]
    public void TestMethod1()
    {
        string connectionString = String.Format(
           @"Provider=OraOLEDB.Oracle;PLSQLRSet=1;Password={0};Persist Security Info=True;User ID={1};Data Source={2};OLEDB.NET=true;FetchSize=5000",
            "pwd", "schema", "server");

        using (IDbConnection con = new OleDbConnection(connectionString))
        {
            con.Open();
        }
    }
}

I have got exception: ORA-12154: TNS:could not resolve the connect identifier specified 我有例外:ORA-12154:TNS:无法解析指定的连接标识符

Obviously problem that is in environment. 显然是环境问题。

How to 'configure' nunit for using 'same' settings as console application 如何'配置'nunit使用'相同'设置作为控制台应用程序

some details: 一些细节:

target framework: 4.0 target platform: x86 nunit 2.5.9 OS: Windows 7 x64 目标框架:4.0目标平台:x86 nunit 2.5.9操作系统:Windows 7 x64

Problem cause parenthesis in folder name. 问题导致文件夹名称中的括号。 (C:\\Program Files (x86)) (C:\\ Program Files(x86))

If I run nunit from folder c:\\something(nunit)\\ I got same error. 如果我从文件夹c:\\ something(nunit)\\运行nunit我得到了同样的错误。

Replacing VS path to short 8.3 names does not help me. 将VS路径替换为8.3短名称对我没有帮助。 So had to install Oracle Client 11 and problem is gone. 因此不得不安装Oracle Client 11,问题就消失了。

检查以下是否有帮助: http//ora-12154.ora-code.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Soap Client在控制台模式下工作,但不能作为NUnit测试 - Soap Client works in console mode, but not as a NUnit test 对于 NUnit 测试,将 RunImpersonated 用于 HttpClient 调用失败,但在控制台中有效 - Using RunImpersonated for an HttpClient call fails for a NUnit test, but works in Console 代码在控制台应用程序中有效,但在Windows Service中运行时不起作用 - Code works in a console application, but does not work when running in windows service 测试中的异步代码有效但显示未运行 - Async code inside of a test works but shows not run 命令在控制台中起作用,而不在代码中起作用 - Command works in console, not in code 如何从NUnit测试中启动控制台 - How to launch Console from inside a NUnit test 代码在控制台应用程序上有效,但在ASP.NET应用程序上无效 - Code works on console application but not on ASP.NET application 代码在测试中有效,但不适用于生产环境 - code works in test, but not on production XmlTextReader仅适用于控制台应用程序吗? - XmlTextReader only works in console application? Websocket代码可在控制台中使用,但不能在Winform中使用 - Websocket code works in console but not in winform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM