我有一个UnitTests.dll
,Common.dll
被引用(都是用 VS2015 构建的)。
我有以下目录结构:
C:\Test\
- UnitTests.dll
- UnitTests.runsettings
C:\Bin\
- Common.dll
Run Code Online (Sandbox Code Playgroud)
UnitTests.runsettings
内容如下:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<RunConfiguration>
<TargetPlatform>x64</TargetPlatform>
</RunConfiguration>
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>False</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
<AssemblyResolution>
<Directory Path="C:\Bin\" includeSubDirectories="true" />
</AssemblyResolution>
</MSTest>
</RunSettings>
Run Code Online (Sandbox Code Playgroud)
我调用测试:
C:\Test> vstest.console.exe UnitTests.dll /settings:UnitTests.runsettings /inIsolation
Run Code Online (Sandbox Code Playgroud)
vstest.console.exe
指的是C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe。
我收到以下错误:
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTests.UnitTest1.TestMethod1 threw exception: System.IO.FileNotFoundException: Could not load file or assembly 'Common, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or …
Run Code Online (Sandbox Code Playgroud) 在_Layout.cshtml文件中,我有以下条目:
@Html.Action("LoadPagesStructure", "Page")
Run Code Online (Sandbox Code Playgroud)
在PageController类中,LoadPagesStructure方法如下:
[ChildActionOnly] /* this attribute indicates that an action should not
be invoked as a result of a user request (by url) */
public ActionResult LoadPagesStructure()
{
ViewModel.Pages = new List<string>() {"page1", "page2", "page3"};
return View();
}
Run Code Online (Sandbox Code Playgroud)
最后,我的LoadPagesStructure.cshtml视图如下所示:
@inherits System.Web.Mvc.WebViewPage<dynamic>
<ul>
@foreach (var page in View.Pages) {
<li>
@Html.ActionLink(page, "Index", "Home")
</li>
}
</ul>
Run Code Online (Sandbox Code Playgroud)
不幸的是,执行后会抛出异常:
System.InvalidOperationException: Child actions are not allowed to perform redirect actions.
Run Code Online (Sandbox Code Playgroud)
动态创建指向我页面的链接的方式是什么?
PS:我知道我可以这样做:<a …
我的问题如下:
我有ms单元测试,它使用存根的http上下文进行mvc路由测试.但代码的一部分(使用rhino mock)存在问题:
var httpContextMock = MockRepository.GenerateStub<HttpContextBase>();
httpContextMock.Stub(c => c.Request.AppRelativeCurrentExecutionFilePath)
.Return(url);
Run Code Online (Sandbox Code Playgroud)
在调试模式下,第二行引发异常:
为什么会出现这样的错误?虽然在没有调试器的情况下触发测试,但一切正常.
问候
<div id="addCompaniesModal">
<div id="addCompany_map"></div>
<div class="addMarkerBtn"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
嗨,当我点击孩子 addCompany_map时,不应该调用父 addCompaniesModal ...我做过这样的事情......但是由于某种原因它没有工作..父母div在点击儿童时被选中可以请一些人解释我的解决方案
$(document).on('click','#addCompany_map', function (e) {
e.stopPropagation();
});
$('#addCompaniesModal').click(function(){
});
Run Code Online (Sandbox Code Playgroud) 我想了解为什么我的代码中会出现两个CA警告:
CA2000在丢失范围之前处置对象在方法'ImpersonateValidUser(string,string,string,LogOnType,LogOnProvider,ImpersonationLevel)'中,在对对象'tempWindowsIdentity'的所有引用超出范围之前调用System.IDisposable.Dispose.
CA1404在P/Invoke方法'ImpersonateValidUser(字符串,字符串,字符串,LogOnType,LogOnProvider,ImpersonationLevel)'调用GetLastWin32Error后立即调用GetLastError,但前一次调用'IDisposable.Dispose()'不是P/Invoke语句.将调用移动到GetLastWin32Error,以便它立即跟随相关的平台调用调用.
下面是简化的代码示例,其中的行完全在警告外观的位置进行了注释:
private static void Impersonate(string userName, string domain, string password, LogOnType logonType, LogOnProvider logonProvider, ImpersonationLevel impersonationLevel)
{
var token = IntPtr.Zero;
var tokenDuplicate = IntPtr.Zero;
if (NativeMethods.RevertToSelf())
{
if (NativeMethods.LogonUser(userName, domain, password, (int)logonType, (int)logonProvider, ref token) != 0)
{
if (NativeMethods.DuplicateToken(token, (int)impersonationLevel, ref tokenDuplicate) != 0)
{
/* CA2000 */ using (var tempWindowsIdentity = new WindowsIdentity(tokenDuplicate))
{
_impersonationContext = tempWindowsIdentity.Impersonate();
return;
}
}
}
}
/* CA1404 */ var e = Marshal.GetLastWin32Error();
throw new Win32Exception(e); …
Run Code Online (Sandbox Code Playgroud) 我已经实现了一些模块,其简化代码如下所示:
(function() {
var context = {...}; // an object which serves as the context for the expression being evaluated
with (context) {
var x = eval(expression);
...
}
}());
Run Code Online (Sandbox Code Playgroud)
澄清一下,我可以完全控制表达式和动态创建的上下文对象。Expression 始终是安全的,并且由受信任的来源提供。表达式中出现的所有成员(字段和函数)始终存在于上下文对象中,例如
var context = {
Concat: function(strA, strB) { return [strA, strB].join(''); },
Name: 'ABC',
Surname: 'DEF'
}
with (context) {
var x = eval("Concat(Name, Surname) == 'XYZ'"); // evaluates to false
...
}
Run Code Online (Sandbox Code Playgroud)
现在,我想将'use strict';
pragma 作为模块的第一行插入(假设出于某些原因,我希望整个模块都这样做,我不想对缩小的函数范围集应用严格性并将严格代码与草率混合本模块中的一个)。
因此,我需要更改代码以通过严格模式要求,因为正如 ECMAScript 5.1 规范中所述,严格模式下不允许使用 with语句。
我通过进行以下修改来勒索兼容性来破解这个问题: …
根据MDN 的new Date()
说法:
创建一个代表单个时间点的 JavaScript Date 实例。日期对象基于时间值,该时间值是自 1970 年 1 月 1 日 UTC 以来的毫秒数
到那个时刻getTime()
:
返回指定日期的数值,作为自 1970 年 1 月 1 日 00:00:00 UTC 以来的毫秒数(之前的时间为负)。
为什么声明:
new Date(new Date(1, 0, 1).setFullYear(1)).getTime();
Run Code Online (Sandbox Code Playgroud)
假设返回从 1970 年 1 月 1 日 00:00:00 UTC 到 01/01/0001 12:00:00 AM 的毫秒数,在不同的机器上给出不同的值,例如-62135600400000
和-62135596800000
? 本地时区(或系统时间?)是否会以某种方式影响此逻辑?
我有简单的类型Question
:
public class Question
{
public Question(string id)
{
Id = id;
Tags = new List<string>();
}
public string Id { get; private set; }
public IList<string> Tags { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我已经定义了这些问题的样本集:
var q1 = new Question("q1") { Tags = new List<string>() {"aa", "bb"} };
var q2 = new Question("q2") { Tags = new List<string>() {"aa"} };
var q3 = new Question("q3") { Tags = new List<string>() {"aa", "bb", "cc"} };
var q4 = new Question("q4"); …
Run Code Online (Sandbox Code Playgroud) 我的项目我正在使用WIF (但这对于这个问题的上下文并不重要.你可以使用替代框架处理你的身份验证.问题是在执行ajax请求时处理身份验证失败).然而,在我的情况下,我编写了自定义服务器逻辑,它继承自ClaimsAuthenticationManager
并处理身份验证:
public override IClaimsPrincipal Authenticate(string resourceName, IClaimsPrincipal incomingPrincipal)
{
if (incomingPrincipal != null && incomingPrincipal.Identity.IsAuthenticated)
{
// add some custom claims
}
return incomingPrincipal;
}
Run Code Online (Sandbox Code Playgroud)
现在,在我删除所有会话Cookie后,再次输入任何页面,我被重定向到WIF服务的登录页面,我被要求再次登录.一切都按预期工作.
但是如果我做了一个ajax请求,我就会收到一个错误,这个错误被拦截了:
$(document).ready(function () {
$.ajaxSetup({
error: function (XMLHttpRequest, textStatus, errorThrown) {
// do something
}
});
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,XMLHttpRequest
对象没有返回任何有意义的消息,基于此我可以像其他人一样以任何其他方式处理这种错误.在这种特殊情况下,我只希望应用程序重定向到登录页面 - 正常请求就是这样.
在执行ajax调用时,将调用方法Authenticate
from ClaimsAuthenticationManager
.Identity.IsAuthenticated
返回false,方法结束,一切都完成.即使是OnAuthorization
方法from BaseController
也没有被调用,所以我无法将任何状态传递给ajax结果对象.
protected override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext.HttpContext.Request.IsAjaxRequest() && !User.Identity.IsAuthenticated)
{
//do something, …
Run Code Online (Sandbox Code Playgroud) c# ×5
javascript ×4
.net ×2
asp.net-mvc ×2
jquery ×2
date ×1
ecmascript-5 ×1
eval ×1
iso ×1
linq ×1
mstest ×1
ravendb ×1
razor ×1
regex ×1
rfc ×1
rhino-mocks ×1
runsettings ×1
strict ×1
unit-testing ×1
wif ×1