针对RCW设计测试?

时间:2012-12-04 14:56:30

标签: design-patterns com tdd abstraction rcw

好的,我做错了什么或者根本没做什么,这里?

待测方法:

    public iManageWorkspace(ManDMSClass manDms, string server, string database, string userId, string password)
    {
        if (manDms == null) throw new ArgumentNullException("manDms");
        if (server == null) throw new ArgumentNullException("server");
        if (database == null) throw new ArgumentNullException("database");
        if (userId == null) throw new ArgumentNullException("userId");
        if (password == null) throw new ArgumentNullException("password");
        this.manDms = manDms;
        this.server = server;
        this.database = database;
        this.userId = userId;
        this.password = password;

        manProfileSearchParameters = manDms.CreateProfileSearchParameters();
        manWorkspaceSearchParameters = manDms.CreateWorkspaceSearchParameters();
        dbList = GetDbList(this.database);
    }

    public void Login()
    {
        manSession = manDms.Sessions.Add(server);
        if (manSession == null)
            throw new ApplicationException("Failed to start DMS session");

        manSession.Timeout = timeout;
        manSession.Login(userId, password);
    }

测试代码:

    [Test]
    [ExpectedException(typeof(ApplicationException))]
    public void GetWorkspaceList_CreateWithNoAbilityToCreateSession_ThrowsApplicationExceptionOnLogin()
    {
        var mockProfileParams = new Mock<IManProfileSearchParameters>();
        var mockWorkspaceParams = new Mock<IManWorkspaceSearchParameters>();

        var mockDmsClass = new Mock<ManDMSClass>();
        mockDmsClass.Setup(manDms => manDms.CreateProfileSearchParameters()).Returns(mockProfileParams.Object);
        mockDmsClass.Setup(manDms => manDms.CreateWorkspaceSearchParameters()).Returns(mockWorkspaceParams.Object);
        mockDmsClass.Setup(manDms => manDms.Sessions.Add("serverName")).Returns<IManSession>(null);
        var manageWorkspace = new iManageWorkspace(mockDmsClass.Object, "serverName", "database", "userId", "password");

        //// Assert
        Assert.Throws<ApplicationException>(manageWorkspace.Login);
    }

例外:

抛出了意外的异常类型 预期:System.ApplicationException  但是:System.Runtime.InteropServices.COMException:检索具有CLSID {FDD9199A-1BB4-4433-B9E1-D550D3118676}的组件的COM类工厂由于以下错误而失败:80040154类未注册(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG) ))。    在System.Runtime.Remoting.RemotingServices.AllocateUninitializedObject(RuntimeType objectType)    在System.Runtime.Remoting.Activation.ActivationServices.CreateInstance(RuntimeType serverType)    在System.Runtime.Remoting.Activation.ActivationServices.IsCurrentContextOK(RuntimeType serverType,Object [] props,Boolean bNewObj)    在System.RuntimeMethodHandle。 InvokeConstructor(IRuntimeMethodInfo方法,Object [] args,ref SignatureStruct签名,RuntimeType declaringType)    在System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr,Binder binder,Object []参数,CultureInfo文化)    在System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr,Binder binder,Object [] args,CultureInfo culture,Object [] activationAttributes)    在Castle.DynamicProxy.ProxyGenerator.CreateClassProxyInstance(类型proxyType,列出1 proxyArguments, Type classToProxy, Object[] constructorArguments) at Moq.Proxy.CastleProxyFactory.CreateProxy(ICallInterceptor interceptor, Type[] interfaces, Object[] arguments) at Moq.Mock 1.b _0()    在Moq.Mock 1.InitializeInstance() at Moq.Mock 1.OnGetObject()    在Moq.Mock`1.get_Object()    at iManage.ConfigurableDAC.Tests.iManageWorkspaceTests.GetWorkspaceList_CreateWithNoAbilityToCreateSession_ThrowsApplicationExceptionOnLogin()in iManageWorkspaceTests.cs:第29行

0 个答案:

没有答案