0

我目前正在学习如何在Silverlight RIA项目中测试我的方法。我有一些用户被授权的方法。我虽然可以通过创建一个模拟授权服务来解决这个问题。然后让用户以这种方式获得授权,但似乎我从代码中引用了null参考,因为它调用了我测试的代码所源自的项目中的授权服务,并在createdefaultuser方法中获取了nullreference,否则会在mockauthorizationservice中手动重写。授权服务导致单元测试失败

我该如何解决这个问题? 我mockauthorization有这个命名空间/类definitionnamespace

Notlr.Test 
    { 
     public class MockAuthentication : AuthenticationService 
     { 
     } 
    } 

我的地头的AuthenticationService看起来是这样的:

namespace Notlr.Web 
    { 
     using System; 
     using System.ServiceModel.DomainServices.Hosting; 
     using System.ServiceModel.DomainServices.Server.ApplicationServices; 
     using System.Web.Security; 

     /// <summary> 
     /// RIA Services DomainService responsible for authenticating users when 
     /// they try to log on to the application. 
     /// 
     /// Most of the functionality is already provided by the base class 
     /// AuthenticationBase 
     /// </summary> 
     [EnableClientAccess] 
     public class AuthenticationService : AuthenticationBase<User> 
{ 
} 
} 

回答

1

雅各布,这听起来像你有命名空间的问题。请记住,Visual Studio中的“测试项目”与其他项目相似。它有自己的命名空间并编译成它自己的.net程序集。拥有“测试项目”不会自动将模拟对象放入测试中;你必须编写代码来完成这一切。

您需要确保在测试运行时您正在编写测试代码以使用模拟授权服务。如果您需要更具体的帮助,请发布您遇到问题的代码。

+0

我试图编辑我的帖子,我希望我发布的代码是您请求的,请引导我沿着正确的路径。我的测试应该在Notlr.Test? – Jakob 2010-11-04 20:46:27