小编Nic*_*aub的帖子

从HttpResponseMessage中提取内容

我正在收到一个类型的对象,System.Net.Http.HttpResponseMessage<List<T>>我该如何获得List<T>

我尝试转换内容属性并通过其value属性从content属性中获取值,但似乎没有任何效果.

谢谢您的帮助!

.net casting wcf-web-api

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

在AngularJS事件单元测试中模拟事件对象

我有以下测试:

    it('Should keep location when user rejects confirmation', inject(function ($controller, $rootScope) {
        var confirmStub = sinon.stub(),
            eventStub = {
                preventDefault: sinon.spy()
            };

        miscServiceStub = function () {
            this.confirm = confirmStub;
        };

        confirmStub.returns(false);

        initializeController($controller, 'Builder', $rootScope);

        $rs.$broadcast('$locationChangeStart', eventStub);
        expect(confirmStub).toHaveBeenCalledOnce();
        expect(confirmStub).toHaveBeenCalledWith('Are you sure you want to leave? you will loose any unsaved changes.');
        expect(eventStub.stopPropagation).toHaveBeenCalledOnce();

        miscServiceStub = function () {};
    }));
Run Code Online (Sandbox Code Playgroud)

测试此代码:

$rootScope.$on('$locationChangeStart', function (event) {
    dump(arguments);
    if (!$miscUtils.confirm('Are you sure you want to leave? you will loose any unsaved changes.')){
        event.preventDefault();
    } …
Run Code Online (Sandbox Code Playgroud)

javascript unit-testing angularjs angularjs-controller

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

我该如何使用ensure_csrf_cookie?

我是python的新手.Django也是新手.我正在尝试发出一个AJAX请求,并按照这里的说明进行操作.首先,检索csrf cookie的结果总是为null,所以我找到了一个名为ensure_csrf_cookie的装饰器方法.问题是它要求一个视图,我不知道要传递什么视图以及我可以在哪里获得它的引用.代码很简单:

from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.views.decorators.csrf import ensure_csrf_cookie

def csv_to_xform(csv, template):
    return render_to_response(template, { "data": "it works!" })
Run Code Online (Sandbox Code Playgroud)

我是否需要使用基于类的视图?如果是这样,有没有更好的方法来设置cookie?我不想使用这里描述的方法,因为我不想手动处理该值.

其余代码如下:

sandbox.html:

<!doctype html>

<html>
    <head>
        <title>Sandbox</title>

        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <script src="/static/js/csrf.js"></script>

        <script type="text/javascript">
            $(function () {
                $('#send-csv-btn').click(function () {
                    $.post('/csv', { 
                        data: '1, 2, 3',
                        success: function (response) {
                            console.debug(response);
                        },
                        error: function (response) {
                            console.debug(response);
                        }
                    });
                });
            });
        </script>
    </head>

    <body>
        <form>
            {% csrf_token %}
            <input type="button" id="send-csv-btn" /> …
Run Code Online (Sandbox Code Playgroud)

python django csrf django-views

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

如何在Karma上使用Jasmine将一个模拟依赖项注入到angular指令中

我有以下指令:

function TopLevelMenuDirective ($userDetails, $configuration) {
    return {
        restrict:'A',
        templateUrl: staticFilesUri + 'templates/TopLevelMenu.Template.html', 
        scope: {
            activeTab: '='
        },
        link: function (scope, element, attributes) {
            var userDetails = $userDetails;
            if ($userDetails) {
                scope.user = {
                    name: userDetails.name ? userDetails.name : 'KoBoForm User',
                    avatar: userDetails.gravatar ? userDetails.gravatar: (staticFilesUri + '/img/avatars/example-photo.jpg')
                };
            } else {
                scope.user = {
                    name: 'KoBoForm User',
                    avatar: staticFilesUri + '/img/avatars/example-photo.jpg'
                }
            }

            scope.sections = $configuration.sections();

            scope.isActive = function (name) {
                return name === scope.activeTab ? 'is-active' : ''; …
Run Code Online (Sandbox Code Playgroud)

unit-testing dependency-injection angularjs angularjs-directive karma-runner

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

asp.net路由集成功能要求asp.net兼容webapi 0.6.0并启用asp.net兼容性

使用asp.net webapi v0.6.0我在启动时遇到了这个错误.为该站点启用了asp.net兼容性.我一直试图修复它几天,坦率地说甚至不知道从哪里开始.

任何帮助,将不胜感激

asp.net .net-4.0 asp.net-web-api

6
推荐指数
1
解决办法
6546
查看次数

使用AutoIt获取所有打开窗口的列表

我试图摆脱所有窗口上的最小化,最大化和关闭按钮.谷歌搜索我发现这个:

$h = WinGetHandle("[CLASS:Notepad]")

$iOldStyle = _WinAPI_GetWindowLong($h, $GWL_STYLE)
$iNewStyle = BitXOr($iOldStyle, $WS_SYSMENU)
_WinAPI_SetWindowLong($h, $GWL_STYLE, $iNewStyle)
_WinAPI_ShowWindow($h, @SW_SHOW)
Run Code Online (Sandbox Code Playgroud)

这很好用,所以现在我只需要使用这段代码迭代所有窗口,我就完成了.如何获取系统中所有HWND的列表?

autoit

6
推荐指数
1
解决办法
9873
查看次数

InternalsVisibleTo属性的问题

我有以下代码:

namespace ConectorV2
{
    [assembly:InternalsVisibleTo("Pruebas")]
    internal static class Utilidades
    {
        internal static string extraerCadenaDeConexion()
        {
            return extraerCadenaDeConexion(new XElement());
        }
        internal static string extraerCadenaDeConexion(XElement documento)
        {
            throw new NotImplementedException();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

然后在Pruebas项目中:

namespace Pruebas.ConectorV2.Cliente
{
    [TestFixture]
    class ModuloExtraerCadenaDeConexion
    {
        [Test]
        public void devuelveCadenaSolicitada()
        {
            var mock = new MockRepository();
            var appSettings =
                XElement.Parse(
                    @"<appSettings>
                                <setting key='dbtype' value='SQLSERVER' />
                                <setting key='SQLSERVER' value='prueba' />
                            </appSettings>");
            Assert.That(ConectorV2.Utilidades.extraerCadenaDeConexion(appSettings), Is.EqualTo("prueba"));
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我在编译时遇到以下错误:

名称空间Pruebas.ConectorV2'中不存在类型或命名空间名称"Utilidades"(您是否缺少程序集引用?)

在我的pruebas项目中正确引用了程序集,我在msdn上读到项目的默认程序集名称是项目名称...我错过了什么?

.net c#-4.0

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