小编rya*_*zec的帖子

如何使用滚动测试AngularJS指令

我有一个无限滚动指令,我试图进行单元测试.目前我有这个:

describe('Infinite Scroll', function(){
  var $compile, $scope;

  beforeEach(module('nag.infiniteScroll'));

  beforeEach(inject(function($injector) {
    $scope = $injector.get('$rootScope');
    $compile = $injector.get('$compile');

    $scope.scrolled = false;
    $scope.test = function() {
      $scope.scrolled = true;
    };
  }));

  var setupElement = function(scope) {
    var element = $compile('<div><div id="test" style="height:50px; width: 50px;overflow: auto" nag-infinite-scroll="test()">a<br><br><br>c<br><br><br><br>e<br><br>v<br><br>f<br><br>g<br><br>m<br>f<br><br>y<br></div></div>')(scope);
    scope.$digest();
    return element;
  }

  it('should have proper initial structure', function() {
    var element = setupElement($scope);

    element.find('#test').scrollTop(10000);

    expect($scope.scrolled).toBe(true);
  });
});
Run Code Online (Sandbox Code Playgroud)

然而.scrollTop(10000); 似乎没有触发任何东西.

是否有单元测试这种类型的功能(我能够单独测试其他指令与类似的交互,如点击元素)?

如果它是相对的,这是无限滚动代码:

angular.module('nag.infiniteScroll', [])
.directive('nagInfiniteScroll', [
  function() {
    return function(scope, elm, attr) {
      var raw = …
Run Code Online (Sandbox Code Playgroud)

testing jasmine angularjs

10
推荐指数
1
解决办法
6607
查看次数

开玩笑的快照使用酶破坏了情感10 /通天塔7

所以我开玩笑的快照可以正常工作,并使用babel 6 / emotion 9在快照中生成css和html,但是我需要更新为babel 7和情绪10,但是用酶的快照测试不再起作用。更新所需代码后,代码将编译并正常工作,只是测试被破坏了(迁移文档中没有任何内容显示与测试设置更新有关的任何内容)。

test('renders properly', () => {
  // this works generating the correct css / html snapshot output
  expect(renderer.create(<component.Template>test</component.Template>).toJSON()).toMatchSnapshot();

  //this does not
  const wrapper = shallow(<component.Template>test</component.Template>);

  expect(toJson(wrapper)).toMatchSnapshot();
});
Run Code Online (Sandbox Code Playgroud)

酶版本生成以下输出:

exports[`renders properly 1`] = `
<ContextConsumer>
  <Component />
</ContextConsumer>
`;
Run Code Online (Sandbox Code Playgroud)

我尝试通过将情感序列化器添加到snapshotSerializersjest配置中并将其手动添加到setupFilesAfterEnv脚本中来添加情感序列化器。

有人知道为什么我会得到这个输出吗?

javascript emotion reactjs jestjs enzyme

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

ASP.NET MVC 3,RavenDB和Autofac Issue Plus 2其他Autofac问题

注意:这里有3个问题,我没有提出单独的问题,因为它们都与相同的代码有些相关.

我有以下代码,根据应用程序的生命周期,在Application_Start中注册与RavenDB的连接:

var store = new DocumentStore { Url = "http://localhost:8080" };
store.Initialize();

builder.RegisterInstance(store).SingleInstance();
Run Code Online (Sandbox Code Playgroud)

现在这个工作正常,这应该是每个应用程序的生命周期只应创建一次.现在我想将DocumentSession添加到Autofac中,所以我尝试在Application_Start中添加:

var session = store.OpenSession();
builder.RegisterInstance(session).SingleInstance();
Run Code Online (Sandbox Code Playgroud)

在我的UserRepository中,我有以下构造函数:

 public UserRepository(DocumentStore store, DocumentSession session)
Run Code Online (Sandbox Code Playgroud)

当我尝试运行它时,我得到以下运行时错误:

无法解析构造函数'Void .ctor(Raven.Client.Document.DocumentStore,Raven.Client.Document.DocumentSession)'的参数'Raven.Client.Document.DocumentSession Session'

对我来说这个错误听起来像Autofac并不认为它有DocumentSession但是store.OpenSession()返回它应该是这样.有人知道会导致这个错误吗?我没有正确设置会话变量(它与存储变量工作正常)?

与上述问题有关或可能没有关系的另一件事是如何根据请求而不是按应用程序生命周期向Autofac添加对象实例?虽然RavenDB DocumentStore对象只应该在生命应用程序周期中创建一次,但是应该根据请求创建一次DocumentSession(可能每个应用程序级别创建它会导致上面的错误).

关于Autofac(与上面的代码有点相关)的​​最后一个问题是关于释放对象.如果你看看这个教程:

http://codeofrob.com/archive/2010/09/29/ravendb-image-gallery-project-iii-the-application-lifecycle.aspx

最后一段代码:

ObjectFactory.ReleaseAndDisposeAllHttpScopedObjects();
Run Code Online (Sandbox Code Playgroud)

这段代码的目的是防止会话泄露.现在这是我还需要担心的Autofac,如果是这样,我将如何在Autofac中执行此操作?

dependency-injection autofac ravendb asp.net-mvc-3

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

Backbone.js和mod重写

所以我正在玩骨干网并且已经到了加载使用pushState的直接页面无法正常工作的put.如果我尝试访问my.url.com/login,它会给我一个未找到的页面,因为它直接不存在.我有以下重写规则:

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [L,QSA]
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用(想到它我得到一个错误的请求,而不是没有找到).如何通过mod重写使pushState url正确加载?

javascript apache mod-rewrite backbone.js pushstate

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

使用LINQ和NHibernate

好的,我认为我的所有配置都正确,现在我只是尝试从数据库中选择一些数据进行选择查询.现在我正在使用NHibernate 3.0,我默认支持LINQ(或者至少是链接的一个很好的部分.现在我找到的每个LINQ示例都有这个代码

session.Linq<User>()
Run Code Online (Sandbox Code Playgroud)

但我为我的生活找不到如何或在哪里设置会话.这是正确的,为什么在3.0中进行,如果是这样,我如何设置会话(我需要什么使用,类,方法等...)?如果没有,使用LINQ和NHibernate 3.0的正确方法是什么?

更新:

现在我有以下代码:

var configuration = new Configuration();
configuration.Configure();
configuration.AddAssembly(typeof(Tag).Assembly);
var sessionFactory = configuration.BuildSessionFactory();
var session = sessionFactory.GetCurrentSession();
Run Code Online (Sandbox Code Playgroud)

但我得到一个编译错误,说NHibernate.ISession没有Linq的定义.我有以下用法:

using System.Collections.Generic;
using System.Web.Mvc;
using MyProject.Models;
using MyProject.ViewModels.Desktop;
using NHibernate.Cfg;
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

c# linq nhibernate

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

NHibernate无法将MySQL日期/时间值转换为System.DateTime

我得到"无法将MySQL日期/时间值转换为System.DateTime"错误,因为从我可以告诉我有一个记录与0000-00-00 00:00:00.现在虽然数据永远不应该(它应该为null),但有时可能会发生这种情况,并且我不希望整个应用程序因此而崩溃.我正在使用NHibernate,我尝试添加更改我的连接字符串以允许零日期时间,因此连接字符串配置如下所示:

<property name="connection.connection_string">
 Server=localhost;Database=user_system;User ID=root;Password=root;
   Allow Zero Datetime=true;
</property>
Run Code Online (Sandbox Code Playgroud)

但是我仍然收到这个错误.如何允许NHibernate为时间戳/日期时间/数据/时间允许零值?

c# mysql asp.net nhibernate

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

字节与短对比Int(以及无符号变化)在C#中?

有人告诉我,只要内存大小不是一个大问题,最好使用int而不是字节或短,因为它实际上更容易处理一个int(CPU需要做额外的东西)使用字节和短路).在C#中这是真的吗?

c# memory cpu types

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

使用ASP.NET MVC 3散列密码

我现在正在尝试找出为我的ASP.NET MVC 3应用程序散列密码的最佳方法.根据我的意见,最好使用给定的密码和随机盐,然后将散列密码和盐存储在一起.我的问题是不会使随机盐毫无意义吗?我的意思是散列密码的原因是因为如果有人进入你的数据库,他们没有普通的密码和盐使得反转哈希更难以获得密码但是如果我存储散列与密码,盐的重点是什么(我对哈希的知识是有限的所以我可以完全脱离我的想法).

我的第二个问题是什么散列方法是最好用的?我读到MD5(这是我一直使用的)很容易破解.我听说bcrypt/sha512非常好.应该使用哪一个?我知道C#默认带有sha512哈希.从我所看到的,bcrypt不包含在.NET库中,有没有适合C#和bcrypt的好库?

c# passwords hash password-protection asp.net-mvc-3

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

将Session $数据转换为数组?

在会话保存处理程序的写入函数中,$ data以如下格式传递:

测试|一个:1:{S:3: "foo" 的; S:3: "棒";}会话|一个:2:{S:10: "isLoggedIn"; B:1; S:8: "的clientId" ; s:5:"12345";}

有没有办法将其转换为适当的数组,这将是:

array
(
    'test' => array
    (
        'foo' => 'bar'
    )
    'session' => array
    (
        'isLoggedIn' => true
        'clientId' => '12345'
    )
)
Run Code Online (Sandbox Code Playgroud)

我尝试将其传递给反序列化但我得到一个错误:

unserialize()[function.unserialize]:偏移量为0的95字节错误

它只是返回false.

php session serialization

7
推荐指数
2
解决办法
3022
查看次数

当列超出时,clang-format 强制每个参数/参数占一行?

我试图弄清楚是否可以使用 clang-format 以我正在寻找的方式获取参数/参数。

我已经尝试了很多东西,但是到目前为止我只能得到这个:

SDL_SetRenderDrawColor(renderer,153 + floor(toGreenRed * percentage),51 + floor(toGreenGreen * percentage),51 + floor(toGreenBlue * percentage),255);
Run Code Online (Sandbox Code Playgroud)

格式化成这个:

SDL_SetRenderDrawColor(renderer,
  153 + floor(toGreenRed * percentage),
  51 + floor(toGreenGreen * percentage),
  51 + floor(toGreenBlue * percentage),
  255);
Run Code Online (Sandbox Code Playgroud)

但我想要这个:

SDL_SetRenderDrawColor(
  renderer,
  153 + floor(toGreenRed * percentage),
  51 + floor(toGreenGreen * percentage),
  51 + floor(toGreenBlue * percentage),
  255
);
Run Code Online (Sandbox Code Playgroud)

目前还有这个:

void renderHealthBox( SDL_Renderer *renderer, int sideUiWidth, int yOffset, float percentage, float laksjdlkajsdlkasjdlkasjd) {
Run Code Online (Sandbox Code Playgroud)

格式为:

void renderHealthBox(
  SDL_Renderer *renderer, int sideUiWidth, int yOffset, float percentage, …
Run Code Online (Sandbox Code Playgroud)

c++ clang-format

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