我有这样的测试:
[TestCase("~/page/myaction")]
public void Page_With_Custom_Action(string path) {
// Arrange
var pathData = new Mock<IPathData>();
var pageModel = new Mock<IPageModel>();
var repository = new Mock<IPageRepository>();
var mapper = new Mock<IControllerMapper>();
var container = new Mock<IContainer>();
container.Setup(x => x.GetInstance<IPageRepository>()).Returns(repository.Object);
repository.Setup(x => x.GetPageByUrl<IPageModel>(path)).Returns(() => pageModel.Object);
pathData.Setup(x => x.Action).Returns("myaction");
pathData.Setup(x => x.Controller).Returns("page");
var resolver = new DashboardPathResolver(pathData.Object, repository.Object, mapper.Object, container.Object);
// Act
var data = resolver.ResolvePath(path);
// Assert
Assert.NotNull(data);
Assert.AreEqual("myaction", data.Action);
Assert.AreEqual("page", data.Controller);
}
Run Code Online (Sandbox Code Playgroud)
GetPageByUrl在我的dashboardpathresolver中运行两次,我如何告诉Moq第一次返回null并且pageModel.Ojbect第二次?
如果我在骨干路由器中启用pushState,是否需要在所有链路上使用return false或者骨干是否自动处理?那里有任何样本,包括html部分和脚本部分.
我正在尝试在我的设置中设置这样的全局序列化设置global.asax
.
var formatter = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
formatter.SerializerSettings = new JsonSerializerSettings
{
Formatting = Formatting.Indented,
TypeNameHandling = TypeNameHandling.Objects,
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
Run Code Online (Sandbox Code Playgroud)
使用以下代码序列化对象时,不使用全局序列化程序设置?
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new StringContent(JsonConvert.SerializeObject(page))
};
Run Code Online (Sandbox Code Playgroud)
是不是可以像这样设置全局序列化设置,还是我错过了什么?
使用structuremap 2.6.4.1,我的容器配置如下:
existingContainer.Configure(expression =>
{
expression.For<IDocumentSession>()
.HybridHttpOrThreadLocalScoped()
.Use(container =>
{
var store = container.GetInstance<IDocumentStore>();
return store.OpenSession();
});
}
Run Code Online (Sandbox Code Playgroud)
HybridHttpOrThreadLocalScoped
在结构图3中不存在,所以我的问题是,structuremap 3中的等效配置是什么?
我正在尝试将updatemodel(myItem,formcollection)与asp.net mvc 2一起使用,但它失败并显示下面的堆栈跟踪.
at System.Web.Mvc.FormCollection.GetValue(String name)
at System.Web.Mvc.DefaultModelBinder.BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, String prefix, String[] includeProperties, String[] excludeProperties, IValueProvider valueProvider)
at System.Web.Mvc.Controller.TryUpdateModel[TModel](TModel model, IValueProvider valueProvider)
at Stormbreaker.Dashboard.Controllers.DashboardController`1.Update(FormCollection collection) in D:\Projects\SVN\Stormbreaker\trunk\Stormbreaker.Dashboard\Controllers\DashboardController.cs:line 23
at lambda_method(ExecutionScope , ControllerBase , Object[] )
at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClassd.<InvokeActionMethodWithFilters>b__a()
at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
Run Code Online (Sandbox Code Playgroud)
我的动作如下:
[AcceptVerbs(HttpVerbs.Post)]
[ValidateInput(false)]
public ActionResult Update(FormCollection collection) {
UpdateModel(CurrentItem, collection);
CurrentItem = (T)_repository.Update(CurrentItem);
return RedirectToAction("edit", new { pagePath = …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用下划线模板引擎渲染html表.首先,我从这样的服务器获得JSON响应
{
CurrentModel: {
Heading: "Home",
Id: "pages/193",
Metadata: {
Name: "Home",
Title: null,
Keywords: null,
Description: null,
DisplayInMenu: true,
Published: "/Date(1334499539404)/",
Changed: "/Date(1334499539404)/",
ChangedBy: "Marcus",
IsPublished: true,
IsDeleted: false,
Slug: null,
Url: null,
SortOrder: 0
},
Parent: null,
Children: [
"pages/226",
"pages/257"
]
},
Children: [
{
Heading: "Foo",
MainBody: null,
Id: "pages/226",
Metadata: {
Name: "I'm an article",
Title: null,
Keywords: null,
Description: null,
DisplayInMenu: true,
Published: "/Date(1334511318838)/",
Changed: "/Date(1334511318838)/",
ChangedBy: "Marcus",
IsPublished: true,
IsDeleted: false,
Slug: "i-m-an-article", …
Run Code Online (Sandbox Code Playgroud) 我在RavenDB项目中实现存储库和服务模式有些困难.主要关注的是我的存储库界面应该是什么样子,因为在RavenDB中我使用了几个索引来查询.
假设我需要获取parentid等于1的所有项目.一种方法是使用IQueryable List()并获取所有文档,然后添加一个where子句来选择parentid等于1的项目.这似乎是一个坏主意因为我无法在RavenDB中使用任何索引功能.所以另一种方法是在存储库中有类似这样的东西,IEnumerable Find(字符串索引,Func谓词),但这似乎也是一个坏主意,因为它不够通用,并且要求我实现这个方法,如果我从RavenDB更改到一个常见的SQL服务器.
那么我如何实现通用存储库,但仍然可以获得RavenDB中索引的好处?
我正在声明一个这样的视图:
var VirtualFileSelectorView = Backbone.View.extend({
selected: function() {
console.log("selected function");
},
initialize: function() {
// Shorthand for the application namespace
var app = brickpile.app;
// bind to the selected event
app.bind('selected', this.selected, this);
}
});
Run Code Online (Sandbox Code Playgroud)
然后我实例化了这个View的两个实例,你可以在这里看到:http://cl.ly/H5WI
问题是当选择的事件被触发时,所选的功能被调用两次?
我的web api中有以下方法
public void Put(string id, [FromBody]IContent value) {
//Do stuff
}
Run Code Online (Sandbox Code Playgroud)
我正在使用骨干js使用fiddler将以下JSON发送到服务器,值为null:
{
"id": "articles/1",
"heading": "Bar",
"$type": "BrickPile.Samples.Models.Article, BrickPile.Samples"
}
Run Code Online (Sandbox Code Playgroud)
但是如果我在JSON对象中首先添加$ type属性,反序列化工作正常,请参阅:
{
"$type": "BrickPile.Samples.Models.Article, BrickPile.Samples",
"id": "articles/1",
"heading": "Bar"
}
Run Code Online (Sandbox Code Playgroud)
是否可以配置newtonsoft以检查对象中的$ type属性而不是第一个属性,还是可以配置主干,以便它始终$type
首先在JSON对象中添加属性?
serialization json.net backbone.js asp.net-mvc-4 asp.net-web-api
c# ×5
backbone.js ×4
json.net ×2
asp.net ×1
asp.net-mvc ×1
html-helper ×1
javascript ×1
json ×1
moq ×1
nunit ×1
oop ×1
ravendb ×1
structuremap ×1
unit-testing ×1
updatemodel ×1