单元测试最佳实践? / C#InternalsVisibleTo()属性为VBNET 2.0,而测试? [英] Unit Testing Best Practice? / C# InternalsVisibleTo() attribute for VBNET 2.0 while testing?

查看:262
本文介绍了单元测试最佳实践? / C#InternalsVisibleTo()属性为VBNET 2.0,而测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要建一个Active Directory包装在VBNET 2.0(不能用后来.NET)中,我有以下几点:

I'm building an Active Directory wrapper in VBNET 2.0 (can't use later .NET) in which I have the following:


  1. IUtilisateur

  2. IGroupe

  3. IUniteOrganisation

这些接口在内部类(朋友VBNET)实现的,因此,我想为了与它们的内部类instiate每个接口来实现的外观。这将允许架构更好的灵活性等。

These interfaces are implemented in internal classes (Friend in VBNET), so that I want to implement a façade in order to instiate each of the interfaces with their internal classes. This will allow the architecture a better flexibility, etc.

现在,我想在同一个解决方案中的不同项目来测试这些类(Utilisateur,阳狮集团,UniteOrganisation)。然而,这些类是内部的。我希望能够实例他们没有通过我的立面去,但仅限于这些测试,仅此而已。

Now, I want to test these classes (Utilisateur, Groupe, UniteOrganisation) in a different project within the same solution. However, these classes are internal. I would like to be able to instantiate them without going through my façade, but only for these tests, nothing more.

下面是一段代码来说明吧:

Here's a piece of code to illustrate it:

public static class DirectoryFacade {
    public static IGroupe CreerGroupe() {
        return new Groupe();
    }
}

// Then in code, I would write something alike:

public partial class MainForm : Form {
    public MainForm() {
        IGroupe g = DirectoryFacade.CreerGroupe();
        // Doing stuff with instance here...
    }
}

// My sample interface:

public interface IGroupe {
    string Domaine { get; set; }
    IList<IUtilisateur> Membres { get; }
}

internal class Groupe : IGroupe {
    private IList<IUtilisateur> _membres;

    internal Groupe() {
        _membres = new List<IUtilisateur>();
    }

    public string Domaine { get; set; }
    public IList<IUtilisateur> Membres {
        get {
            return _membres;
        }
    }
}



我听说InternalsVisibleTo的()属性,近日。我不知道它是否适用于VBNET 2.0 / VS2005,这样我可以访问assmebly的内部类我的测试?否则,我怎么能做到这一点?

I heard of InternalsVisibleTo() attribute, recently. I was wondering whether it is available in VBNET 2.0/VS2005 so that I could access the assmebly's internal classes for my tests? Otherwise, how could I achieve this?

修改这是一个很好的测试实践进行像我这样做?

EDIT Is this a good testing practice to proceed like I do?

推荐答案

是的,InternalsVisibleTo属性可在vb.net和工作在朋友的类型。

Yes, the InternalsVisibleTo attribute is available in vb.net and works on Friend types.

这篇关于单元测试最佳实践? / C#InternalsVisibleTo()属性为VBNET 2.0,而测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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