小编Mar*_*cus的帖子

Moq第一次和第二次使用不同的返回值

我有这样的测试:

    [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第二次?

c# nunit unit-testing moq

232
推荐指数
6
解决办法
7万
查看次数

Backbone.js和pushState

如果我在骨干路由器中启用pushState,是否需要在所有链路上使用return false或者骨干是否自动处理?那里有任何样本,包括html部分和脚本部分.

javascript backbone.js

37
推荐指数
2
解决办法
1万
查看次数

设置默认的全局json序列化程序设置

我正在尝试在我的设置中设置这样的全局序列化设置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)

是不是可以像这样设置全局序列化设置,还是我错过了什么?

c# json json.net asp.net-web-api asp.net-mvc-5

35
推荐指数
2
解决办法
5万
查看次数

在结构图3中,HybridHttpOrThreadLocalScoped的等价物是什么?

使用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中的等效配置是什么?

c# structuremap dependency-injection structuremap3

18
推荐指数
1
解决办法
4554
查看次数

UpdateModel的ASP.NET MVC 2问题

我正在尝试将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)

c# asp.net asp.net-mvc updatemodel

13
推荐指数
1
解决办法
5380
查看次数

使用骨干复杂模型使用下划线模板引擎渲染html表

我正在尝试使用下划线模板引擎渲染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)

backbone.js underscore.js

13
推荐指数
1
解决办法
2万
查看次数

使用RavenDB实现存储库和服务模式

我在RavenDB项目中实现存储库和服务模式有些困难.主要关注的是我的存储库界面应该是什么样子,因为在RavenDB中我使用了几个索引来查询.

假设我需要获取parentid等于1的所有项目.一种方法是使用IQueryable List()并获取所有文档,然后添加一个where子句来选择parentid等于1的项目.这似乎是一个坏主意因为我无法在RavenDB中使用任何索引功能.所以另一种方法是在存储库中有类似这样的东西,IEnumerable Find(字符串索引,Func谓词),但这似乎也是一个坏主意,因为它不够通用,并且要求我实现这个方法,如果我从RavenDB更改到一个常见的SQL服务器.

那么我如何实现通用存储库,但仍然可以获得RavenDB中索引的好处?

c# oop design-patterns ravendb

11
推荐指数
4
解决办法
4753
查看次数

使用Html助手的Html里面的标签

如何使用Html.Label在标签内添加内联html元素?

html-helper asp.net-mvc-3

9
推荐指数
2
解决办法
1万
查看次数

事件发生两次

我正在声明一个这样的视图:

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

问题是当选择事件被触发时,所选功能被调用两次?

backbone.js backbone-events backbone-views

8
推荐指数
1
解决办法
7579
查看次数

Newtonsoft中的TypeNameHandling需要$ type作为第一个属性吗?

我的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

7
推荐指数
1
解决办法
1967
查看次数