public static class ApplicationUtils
{
public static bool IsCurrentUserAManager()
{
var username = WindowsIdentity.GetCurrent().Name;
bool inAdmin;
if (username == "AdminUser") {
inAdmin = true;
} else {
inAdmin = false;
}
return inAdmin;
}
}
Run Code Online (Sandbox Code Playgroud)
以上是一些用于测试当前登录用户是否为管理员的代码,我想通过传入不同的用户名来对本节进行单元测试,并测试结果是否正确。
我听说依赖注入是最好的方法。但我不知道如何依赖注入静态类和静态方法。
任何人都可以帮助我填写下面的 TestMethod 以传递用户名并测试该方法吗?(不使用企业)
[TestMethod]
public void IsCurrentUserAManagerTestIsAdmin()
{
}
Run Code Online (Sandbox Code Playgroud) 下面的组件按预期执行所有操作,但无法写入最后一个注册表项值.我没有错.
<Component Id="ProgramMenuDir" Guid="68977683-3F36-45EF-9FF4-7B9461A42D06">
<RemoveFolder Id="ProgramMenuDir" On="uninstall" />
<RegistryKey Root="HKLM" Key="Software\Wow6432Node\[Manufacturer]\[ProductName]" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes">
<RegistryValue Type="string" Name="APIUrl" Value="http://api.blah/" KeyPath="yes" />
<RegistryValue Type="string" Name="Token" Value="blah" />
</RegistryKey>
<RegistryKey Root="HKLM" Key="Software\Wow6432Node\[Manufacturer]\[ProductName]\Tokens" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryKey Root="HKLM" Key="Software\Wow6432Node\[Manufacturer]\[ProductName]\Tokens\WOvN+Lac+d3wRtY0uBUsAeHTYg4x7j2/NWpftWv/16qaOz3J6TpDQmvjUpQmoCWPSFdMpbrcpi4rJd56aBKkkvSR54RsS5xueaYfPgk1QmQ=" ForceCreateOnInstall="yes" ForceDeleteOnUninstall="yes" />
<RegistryValue Root="HKLM" Action="write" Key="Software\Microsoft\Windows\CurrentVersion\Run" Name="[ProductName]" Value="blah" Type="string" />
</Component>
Run Code Online (Sandbox Code Playgroud)
为什么不写,但没有错误?
如何使用Windows PowerShell脚本计算今天1601-01-01以来的毫秒数?我需要这个来构建正确的LDAP查询.