C# 单元测试模拟WSFederationAuthenticationModule
我们的团队目前使用WIF进行身份验证。在我们的代码中,我们使用C# 单元测试模拟WSFederationAuthenticationModule,c#,mocking,wif,C#,Mocking,Wif,我们的团队目前使用WIF进行身份验证。在我们的代码中,我们使用 SessionManager.GetClaim(CustomClaimTypes.Username) 和其他SessionManager函数,用于在操作数据时识别当前登录的用户。我最近开始为我们的一个项目编写单元测试,这显然失败了,因为SessionManager为null 当测试方法调用从会话检索数据的函数时,我遇到了相同的问题。为了解决这个问题,我加入了Moq库并模拟了会话,如下所示: var mockHttpContext
SessionManager.GetClaim(CustomClaimTypes.Username)
和其他SessionManager函数,用于在操作数据时识别当前登录的用户。我最近开始为我们的一个项目编写单元测试,这显然失败了,因为SessionManager为null
当测试方法调用从会话检索数据的函数时,我遇到了相同的问题。为了解决这个问题,我加入了Moq库并模拟了会话,如下所示:
var mockHttpContext = new Mock<HttpContextBase>();
mockHttpContext.SetupGet(c => c.Session).Returns(mockSession.Object);
mockHttpContext.SetupSet(c => c.Session["test"] = "test");
我尝试创建WSFederationauthenticationModule并初始化它,但没有成功:
WSFederationAuthenticationModule ws = new WSFederationAuthenticationModule();
ws.Init(mockHttpContext.ApplicationInstance);
我似乎找不到任何有用的资源来帮助我解决这个问题。有人帮忙吗
WSFederationAuthenticationModule ws = new WSFederationAuthenticationModule();
ws.Init(mockHttpContext.ApplicationInstance);