Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 单元测试模拟WSFederationAuthenticationModule_C#_Mocking_Wif - Fatal编程技术网

C# 单元测试模拟WSFederationAuthenticationModule

C# 单元测试模拟WSFederationAuthenticationModule,c#,mocking,wif,C#,Mocking,Wif,我们的团队目前使用WIF进行身份验证。在我们的代码中,我们使用 SessionManager.GetClaim(CustomClaimTypes.Username) 和其他SessionManager函数,用于在操作数据时识别当前登录的用户。我最近开始为我们的一个项目编写单元测试,这显然失败了,因为SessionManager为null 当测试方法调用从会话检索数据的函数时,我遇到了相同的问题。为了解决这个问题,我加入了Moq库并模拟了会话,如下所示: var mockHttpContext

我们的团队目前使用WIF进行身份验证。在我们的代码中,我们使用

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);