小编Ken*_*all的帖子

需要在单元测试中添加自定义标头以进行请求

我终于能够HttpContext.Current通过在线查找一些代码来获得不为空.但我仍然无法在单元测试中向请求添加自定义标头.这是我的测试:

[TestClass]
public class TagControllerTest
{
    private static Mock<IGenericService<Tag>> Service { get; set; }
    private TagController controller;

    [TestInitialize]
    public void ThingServiceTestSetUp()
    {
        Tag tag = new Tag(1, "people");
        Response<Tag> response = new Response<Tag>();
        response.PayLoad = new List<Tag>() { tag };

        Service = new Mock<IGenericService<Tag>>(MockBehavior.Default);
        Service.Setup(s => s.FindAll("username", "password", "token")).Returns(response);

        controller = new TagController(Service.Object);
        HttpContext.Current = FakeHttpContext();
    }

    public static HttpContext FakeHttpContext()
    {
        var httpRequest = new HttpRequest("", "http://kindermusik/", "");
        var stringWriter = new StringWriter();
        var httpResponce = new …
Run Code Online (Sandbox Code Playgroud)

c# unit-testing httprequest httpcontext asp.net-apicontroller

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

Chrome 57使.data()功能不佳

.on("change")当用户在Chrome 57中工作时,此部分活动无法正常运行.这只是Chrome 57问题.

设置中的userId变量if并在到达此代码之前具有值.
但是,条件在应该的时候没有被发现.

但是如果我正在调试并且有一个断点设置我会想到if并且我在断点处停下来并且停留一段时间这是否正常工作.

这并没有影响使用57的每个人.
我只能重新创建这个问题两次,在调试之后,它就消失了.

对于发生了什么以及如何解决它的想法?
我还要注意,我们使用的是非常旧版本的jquery - 1.11.1并且升级并不容易.

var selected = $(this).children("option:selected");
var name = selected.html();
var userId = selected.attr("value");
var personInList;

$("li", "#list1").add("li.person", "#list2").each(function () {
    if ($(this).data("userId") == userId) {
        personInList = $(this);
        return;
    }
});

if (userId && userId!= "default" && !personInList) {
    //some code that gets triggered that shouldn't because this "if" is turning up true
}
Run Code Online (Sandbox Code Playgroud)

javascript jquery google-chrome

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