我正在尝试对绑定到ngClick指令的函数进行单元测试.它现在看起来像这样,因为我们刚刚开始这个项目,在我到达目前之前我想要一些测试覆盖:
vm.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
vm.opened = true;
};
Run Code Online (Sandbox Code Playgroud)
我这样单元测试:
describe('Unit: simpleSearchController', function(){
//include main module
beforeEach(module('myApp'));
var ctrl, scope, event ;
// inject the $controller and $rootScope services
// in the beforeEach block
beforeEach(inject(function($controller, $rootScope){
// Create a new scope that's a child of the $rootScope
scope = $rootScope.$new();
// Create the controller and alias access using controllerAs
ctrl = $controller('simpleSearchController as vm', {
$scope: scope
});
}));
// unit tests
it('should set vm.opened to true', function(){ …Run Code Online (Sandbox Code Playgroud) 我试图使用C#将嵌套文档插入MongoDB.我有一个名为类别的集合.在该集合中,必须存在具有2个数组,一个命名类别和一个命名标准的文档.在这些数组中必须存在具有自己的ID的新文档,这些ID也包含上面列出的相同名称的数组.以下是我到目前为止的情况,但我不确定如何继续.如果您查看代码我想要做的是添加嵌套在categories文档中的categories数组下的"namingConventions"文档,但是namingConventions也必须具有唯一的ID.
在这一点上,我不确定我是否已经以最好的方式做到了这一点,所以我对这一切都有任何建议.
namespace ClassLibrary1
{
using MongoDB.Bson;
using MongoDB.Driver;
public class Class1
{
public void test()
{
string connectionString = "mongodb://localhost";
MongoServer server = MongoServer.Create(connectionString);
MongoDatabase standards = server.GetDatabase("Standards");
MongoCollection<BsonDocument> categories = standards.GetCollection<BsonDocument>("catagories");
BsonDocument[] batch = {
new BsonDocument { { "categories", new BsonArray {} },
{ "standards", new BsonArray { } } },
new BsonDocument { { "catagories", new BsonArray { } },
{ "standards", new BsonArray { } } },
};
categories.InsertBatch(batch);
((BsonArray)batch[0]["categories"]).Add(batch[1]);
categories.Save(batch[0]);
}
}
}
Run Code Online (Sandbox Code Playgroud)
为清楚起见,这就是我需要的: …