我有一个测试类,下面我从测试类发布了一个示例测试
namespace AdminPortal.Tests.Controller_Test.Customer
{
[TestClass]
public class BusinessUnitControllerTests
{
private IBusinessUnitRepository _mockBusinessUnitRepository;
private BusinessUnitController _controller;
[TestInitialize]
public void TestInitialize()
{
_mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>();
_controller = new BusinessUnitController(_mockBusinessUnitRepository);
}
[TestCleanup]
public void TestCleanup()
{
_mockBusinessUnitRepository = null;
_controller.Dispose();
_controller = null;
}
#region Index Action Tests
[TestMethod]
public void Index_Action_Calls_GetAllBusinessUnit()
{
_mockBusinessUnitRepository.Stub(x => x.GetAllBusinessUnit());
_controller.Index();
_mockBusinessUnitRepository.AssertWasCalled(x=>x.GetAllBusinessUnit());
}
}
}
Run Code Online (Sandbox Code Playgroud)
当我运行项目时,我得到了以下屏幕

我检查了引用,测试项目引用了主项目.知道为什么测试没有运行或说它们没有结果?
编辑1:
我在这里看到了一个帖子并将我的测试设置的默认处理器架构更改为X64,但它仍然无效.
我已升级到VS.NET 2013,现在,每次我开始在IIS中调试ASP.NET MVC4应用程序时,如何创建__vwd/js/artery,这个脚本会干扰我的RequireJS设置并且它会崩溃jQuery参考.
有谁知道我怎么能摆脱这个脚本?
__vwd/JS /动脉
window.vwdTempJQuery = window.jQuery = window.$;
window.jQuery = window.$ = null;
window.vwdTempJSON = window.JSON;
*! jQuery v1.8.2 jquery.com | jquery.org/license */
.....
// Restore original jQuery references.
window.jQuery = window.$ = window.vwdTempJQuery;
window.vwdTempJQuery = null;
// Restore original JSON.
if (window.JSON !== window.vwdTempJSON)
window.JSON = window.vwdTempJSON;
....
Run Code Online (Sandbox Code Playgroud)
在MVC 4中,我们有捆绑.在定义包时,我们可以使用*等通配符来处理文件夹中的所有文件.
在下面的例子中是什么-{version}意思?
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
}
Run Code Online (Sandbox Code Playgroud) 我有一个小的MVC应用程序,我出于练习的原因使用,但现在我每次尝试调试时都遇到错误:
Could not load file or assembly 'System.Net.Http.Formatting' or one of its dependencies.
The system cannot find the path specified.
Run Code Online (Sandbox Code Playgroud)
我用Google搜索但无法找到解决方案.我正在使用.NET 4.5.
它不能是DLL文件,因为我使用.Net 4.5.
我有这样的链接:
<a href='Member/MemberHome/Profile/Id'><span>Profile</span></a>
Run Code Online (Sandbox Code Playgroud)
当我点击它时,它会调用这个部分页面:
@{
switch ((string)ViewBag.Details)
{
case "Profile":
{
@Html.Partial("_Profile"); break;
}
}
}
Run Code Online (Sandbox Code Playgroud)
部分页面_Profile包含:
Html.Action("Action", "Controller", model.Paramter)
Run Code Online (Sandbox Code Playgroud)
例:
@Html.Action("MemberProfile", "Member", new { id=1 }) // id is always changing
Run Code Online (Sandbox Code Playgroud)
我怀疑的是我如何将这个"Id"传递给model.parameter部分?
我的控制器是:
public ActionResult MemberHome(string id)
{
ViewBag.Details = id;
return View();
}
public ActionResult MemberProfile(int id = 0)
{
MemberData md = new Member().GetMemberProfile(id);
return PartialView("_ProfilePage",md);
}
Run Code Online (Sandbox Code Playgroud) 我正在使用MVC4编写的app ports上运行一个应用程序.
一捆css文件不起作用.在调试模式的本地计算机中,我看到了应用程序的代码,我看到了文件.该应用程序按预期工作.
<link href="/Content/css/home/basic-jquery-slider.css" rel="stylesheet"/>
<link href="/Content/css/home/Home.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)
当我将应用程序上传到Appharbor时,我在代码中看到了捆绑包但是App无法正常工作.
<link href="/Content/css/home?v=zhVOIpUNuvCOZhJyBcQWpMlozayor4te6k-pM29wHqI1" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)
当我浏览那个链接时,href我得到403 - 禁止访问:访问被拒绝.
如何解决这个问题?
我需要从Controller A调用控制器B动作FileUploadMsgView并需要为它传递一个参数.
Code---its not going to the controller B's FileUploadMsgView().
In ControllerA
private void Test()
{
try
{//some codes here
ViewBag.FileUploadMsg = "File uploaded successfully.";
ViewBag.FileUploadFlag = "2";
RedirectToAction("B", "FileUploadMsgView", new { FileUploadMsg = "File uploaded successfully" });
}
In ControllerB receiving part
public ActionResult FileUploadMsgView(string FileUploadMsg)
{
return View();
}
Run Code Online (Sandbox Code Playgroud) 虽然微软在剃刀MVC4中创建了一些html属性的自动渲染,但我花了很长时间才找到如何基于条件剃刀表达式在元素上渲染第二个css类.我想和你分享.
基于模型属性@ Model.Details,我想显示或隐藏列表项.如果有细节,则应显示div,否则应隐藏.使用jQuery,我需要做的就是分别添加一个类show或hide.出于其他目的,我还想添加另一个类"详细信息".所以,我的加价应该是:
<div class="details show">[Details]</div> 要么 <div class="details hide">[Details]</div>
下面,我展示了一些失败的尝试(假设没有细节,导致标记).
这:<div @(@Model.Details.Count > 0 ? "class=details show" : "class=details hide")>,
会这样:<div class="details" hide="">.
这个:<div @(@Model.Details.Count > 0 ? "class=\"details show\"" : "class=\"details hide\"")>.
会这样:<div class=""details" hide"="">.
这个: <div @(@Model.Details.Count > 0 ? "class='details show'" : "class='details hide'")>
会这样:<div class="'details" hide'="">.
这些都不是正确的标记.
我正在使用Web API在ASP.MVC MVC 4中创建一组新服务.到目前为止,这很棒.我已经创建了该服务并使其工作,现在我正在尝试使用JQuery来使用它.我可以使用Fiddler取回JSON字符串,它似乎没问题,但是因为该服务存在于一个单独的站点上,所以尝试使用"不允许"的JQuery错误调用它.所以,这显然是我需要使用JSONP的情况.
我知道Web API是新的,但我希望有人可以帮助我.
如何使用JSONP调用Web API方法?
我正在使用Membership.create用户功能,然后发生以下错误,
所需的防伪表单字段"__RequestVerificationToken"不存在
我怎样才能解决这个问题?
asp.net-mvc-4 ×10
asp.net-mvc ×5
c# ×4
asp.net ×2
razor ×2
.net ×1
appharbor ×1
html ×1
jquery ×1
jsonp ×1
resharper ×1
unit-testing ×1