编写单元测试用例时出错-无法加载文件或程序集'Oracle.DataAccess,Version = 4.112.4.0 [英] Error while doing writing unit test case -Could not load file or assembly 'Oracle.DataAccess, Version=4.112.4.0

查看:263
本文介绍了编写单元测试用例时出错-无法加载文件或程序集'Oracle.DataAccess,Version = 4.112.4.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于C#代码,我们需要使用MS Test或NUnit Framework进行单元测试.有许多方法包括DB调用.尝试这样做时,出现以下错误:

We have a requirement to do unit testing using either MS Test or NUnit Framework for our C# code. There are many methods which includes DB call. When trying to do so, I am getting below error:

* {无法加载文件或程序集'Oracle.DataAccess,Version = 4.112.4.0,Culture = neutral,PublicKeyToken = *******'或其依赖项之一.加载格式错误的程序.} *

我检查了Oracle版本,以确保没有不匹配,但没有成功.另请阅读几篇文章,而不是使用DB调用,而应该使用模拟绕过DB.但是由于这个限制,覆盖范围非常小. 任何人都可以指导解决上述错误.添加我只是为POC尝试的示例代码

I checked the Oracle version to make sure there is no mismatch, but no success. Also read couple of articles that instead of making DB call one should be using mocking to bypass DB. But with this limitation the coverage is very minimal. Could anyone please guide to fix the above error. Adding the sample code which i tried just for POC

public class Class1
    {
        public IEnumerable<ModelClass> GetListOfExceptions()
        {
            OracleConnection conn = new OracleConnection(Constants.ConnectionString);
            try
            {
                conn.Open();
                OracleCommand cmd = new OracleCommand(Constants.<Oracle Query>, conn);
                cmd.CommandType = CommandType.Text;
                //cmd.CommandType = CommandType.StoredProcedure;
                OracleDataReader dr = cmd.ExecuteReader();
                ModelClass modelException = null;
                List<ModelClass> lst = new List<ModelClass>();
                while (dr.Read())
                {
                    modelException = new ModelClass();
                    modelException.POLICYNO = Convert.ToString(dr.GetValue(1));
                    modelException.PREMIUM = Convert.ToInt32(dr.GetValue(2));
                    modelException.AGE = Convert.ToInt32(dr.GetValue(3));
                    lst.Add(princeException);
                }
                return lst;

            }
            catch (Exception)
            {

                throw;
            }
            finally
            {
                conn.Close();
            }

        }


    }

    [TestFixture]
    public class Class1Tests
    {
        [Test]
        public void GetListOfExceptionsTest()
        {
            Class1 obj = new Class1();
            obj.GetListOfExceptions();

        }
     }

推荐答案

最后,在安装到Oracle Client 12.1(32位版本)之后,该问题已解决.

Finally the issue is fixed after installation to Oracle Client 12.1 (32 bit version).

这篇关于编写单元测试用例时出错-无法加载文件或程序集'Oracle.DataAccess,Version = 4.112.4.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆