如何测试,如果某些组件已经被加载到内存? [英] How to test if certain assemblies have been loaded into memory?

查看:239
本文介绍了如何测试,如果某些组件已经被加载到内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Crystal Reports的运行时库来产生和丢弃的小假报告,以确保库加载到内存的好时机之前,用户创建了一个真正的报告,一些code。 (这是一个感知性能的问题。)的性能得到了显着提高,当用户生成一个报告,以便清楚所有的作品。

I have some code that uses the Crystal Reports runtime libraries to generate and discard a small dummy report, in order to ensure that the libraries are loaded into memory in good time before the user creates a genuine report. (It's a 'perceived performance' issue.) The performance has been notably improved when the user generates a report, so that clearly all works.

现在我需要编写一个单元测试,证明了晶库确实被加载到预期当内存 - 但是我试图测试什么是使用 Assembly.GetExecutingAssembly()有GetModules()。 于事无补。 ( GetCallingAssembly()。GetModules()是再好不过无论是。)

Now I need to write a unit test that proves that the Crystal libraries have indeed been loaded into memory when expected - however my attempts to test what is there using Assembly.GetExecutingAssembly().GetModules() does not help. (GetCallingAssembly().GetModules() is no better either.)

我如何从我的单元测试检查,看是否已经被加载这些程序集?

How can I check from within my unit test to see if these assemblies have been loaded?

TIA

推荐答案

以下code示例使用GetAssemblies方法来获取已加载到应用程序域的所有程序集的列表。该组件,然后显示到控制台上。

The following code example uses the GetAssemblies method to get a list of all assemblies that have been loaded into the application domain. The assemblies are then displayed to the console.

public static void Main() 
    {
        AppDomain currentDomain = AppDomain.CurrentDomain;
        //Provide the current application domain evidence for the assembly.
        Evidence asEvidence = currentDomain.Evidence;
        //Load the assembly from the application directory using a simple name. 

        //Create an assembly called CustomLibrary to run this sample.
        currentDomain.Load("CustomLibrary",asEvidence);

        //Make an array for the list of assemblies.
        Assembly[] assems = currentDomain.GetAssemblies();

        //List the assemblies in the current application domain.
        Console.WriteLine("List of assemblies loaded in current appdomain:");
            foreach (Assembly assem in assems)
                Console.WriteLine(assem.ToString());
    }

P.S。 :要运行这个code例如,你需要创建一个名为CustomLibrary.dll集会,或更改传递给GetAssemblies方法的程序集名称

P.S. : To run this code example, you need to create an assembly named CustomLibrary.dll, or change the assembly name that is passed to the GetAssemblies method.

在这里看到在 MSDN

这篇关于如何测试,如果某些组件已经被加载到内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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