【问题标题】:Mock OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name in WCF service在 WCF 服务中模拟 OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name
【发布时间】:2015-04-01 22:06:24
【问题描述】:

我有 WCF 服务,我正在尝试进行单元测试。该服务的唯一依赖项是调用 OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name 以了解使用该服务的 Windows 用户(Windows 身份验证)我只想模拟这个。 有人有简单的方法吗?

【问题讨论】:

    标签: c# wcf unit-testing


    【解决方案1】:

    根据您的服务配置方式,Thread.CurrentPrincipal 可能包含一个代表已连接客户端的主体。因此,您可以从中获取名称,而不是依赖于 OperationContext。

    【讨论】:

    • 哇真的谢谢你!!!很好的答案,因为在我的服务中我有凭据,我可以在我的单元测试中模拟当前的主体!
    猜你喜欢
    • 2011-02-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多