我正在尝试调试从单元测试项目执行的代码,但是当我尝试进入某个方法时,它只是直接进入下一行,并且该方法内的断点未被命中.该方法位于一个不同项目的类中,但所有代码都是在调试模式下构建的,我尝试过清理和重建解决方案,没有任何乐趣.
但是,这只是因为我在方法中添加了一个迭代器块.当我删除它并重建时,我可以介入.奇怪的?
我正在使用Visual Studio 2010 Beta 1,这可能只是一个错误吗?
我正在编写一个使用现有插件的插件,我想嘲笑它.
我写的插件看起来像这样:
(function($){
$.widget("myPlugin",{
_create: function(){
var otherControl = $("<div></div>");
otherControl.pluginWhichShouldBeMocked({foo: "bar"});
this.element.append(otherControl);
}
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
我有一个Jasmine测试,看起来像这样:
describe("When creating", function(){
var element;
var passedOptions;
beforeEach(function(){
jQuery.pluginWhichShouldBeMocked = function(options){
passedOptions = options;
}
element = $("<div></div>");
element.myPlugin();
});
it("should create the other plugin and pass 'bar' to it as the foo parameter", function(){
expect(passedOptions.foo).toEqual("bar");
});
});
Run Code Online (Sandbox Code Playgroud)
这行是我试图模拟插件的地方:
jQuery.pluginWhichShouldBeMocked = function(options){
passedOptions = options;
}
Run Code Online (Sandbox Code Playgroud)
但仍会调用实际的插件实例.
我正在使用活动模型序列化器来从rails控制器呈现JSON响应.
我有这样的控制器动作:
def show
@foo = Foo.find(params[:id])
if @foo.user == current_user
render json: @foo, serializer: FooSerializer
else
render json: @foo, serializer: TrimmedFooSerializer
end
end
Run Code Online (Sandbox Code Playgroud)
我希望能够测试在我的Rspec控制器测试中使用了哪个序列化器.是否有可能从测试中获得对序列化器的引用?
更新:
我不认为这是正确使用序列化器.我现在在序列化程序本身中有逻辑来有条件地包含属性.控制器不应该真正关心使用哪个序列化器.
我需要指定我的类的泛型类型实现接口,并且也是引用类型.我尝试了下面的代码片段,但都没有工作
public abstract class MyClass<TMyType>
where TMyType : IMyInterface
where TMyType : class
public abstract class MyClass<TMyType>
where TMyType : class, IMyInterface
Run Code Online (Sandbox Code Playgroud)
我无法为类型指定多个where子句,是否可以执行此操作?
我正在开发一个使用Windows Mobile设备调用Web服务的项目.
需要说明如果服务调用失败,则应提示用户重试.目前,有一个服务代理调用Web服务代理上的所有方法,如果调用失败,则会有一些代码提示用户重试,然后再次调用该调用.它看起来像这样:
public void MyServiceCall(string stringArg, bool boolArg, int intArg)
{
try
{
MyWebService.MyServiceCall(stringArg, boolArg, intArg);
}
catch(SoapException ex)
{
bool retry = //a load of horrid code to prompt the user to retry
if (retry)
{
this.MyServiceCall(stringArg, boolArg, intArg);
}
}
}
Run Code Online (Sandbox Code Playgroud)
catch中的东西在系统上看起来比在该片段中看起来更麻烦,并且CTRL-C CTRL-V模式已被用于在每个服务调用中复制它.我想将这个重复的代码重构为一个方法,但我不确定重试方法调用的最佳方法.我正在考虑让一个委托作为我的新方法的参数,但由于我不知道签名,我不确定如何以通用方式执行此操作.有人可以帮忙吗?谢谢.
我在将JSON数据发布到我的rails控制器并将我的JSON数据中的字段映射到paremeters上以创建我的实体时遇到了一些问题.
这是动作的样子:
def create
@trip = Trip.new(params[:trip])
if @trip.save
respond_to do |format|
format.json{render :json => @trip, :status => :created, :location => @trip }
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是Web服务器的输出:
Started POST "/trips.json" for 127.0.0.1 at Sat Sep 03 12:37:41 -0400 2011
Processing by TripsController#create as JSON
Parameters: {"title"=>"Charlie"}
AREL (0.5ms) INSERT INTO "trips" ("created_at", "updated_at", "title") VALUES ('2011-09-03 16:37:41.945743', '2011-09-03 16:37:41.945743', NULL)
Completed 201 Created in 15ms (Views: 3.5ms | ActiveRecord: 0.5ms)
Run Code Online (Sandbox Code Playgroud)
正如你可以看到它在标题字段中插入NULL,我希望它能从JSON数据中映射它吗?
这是HTTP请求:
Host localhost:3000
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS …Run Code Online (Sandbox Code Playgroud) 我正在使用 node.js 和 heroku,并且希望运行多个 web 进程。在 Procfile 我有它看起来像这样:
web: node web.js
web: node differentWeb.js
Run Code Online (Sandbox Code Playgroud)
但是,当我运行它时,它只会运行两者中的最后一个。有没有办法做到这一点?
我想尝试一些iPhone开发但不是Mac用户.我并不热衷于在新的Mac上花大笔钱,所以如果我要在ebay上买一台旧的Mac,那么我应该把什么系统看作是可接受的iphone开发机器的最低限度.显然越便宜越好.
注意:不热衷于在PC上运行mac os,因此真正寻找苹果硬件选项.旧Mac迷你适合吗?
我正在使用CoffeeScript和KnockoutJS,并且在函数中获取视图模型的值时遇到问题.
我有一个视图模型:
window.Application || = {}
class Application.ViewModel
thisRef = this
searchTerm: ko.observable("")
search: ->
alert @searchTerm
Run Code Online (Sandbox Code Playgroud)
编译为:
window.Application || (window.Application = {});
Application.ViewModel = (function() {
var thisRef;
function ViewModel() {}
thisRef = ViewModel;
ViewModel.prototype.searchTerm = ko.observable("");
ViewModel.prototype.search = function() {
return alert(this.searchTerm);
};
return ViewModel;
})();
Run Code Online (Sandbox Code Playgroud)
此视图模型是父视图模型的一部分,它将其公开为字段.问题是我无法获得对子视图模型的引用.在搜索功能中,"this"是父级的一个实例,我不想要它.
我有一个方法,需要一堆可选参数,我正在重载方法,以提供不同的签名组合.Intellisense弹出一堆不同的签名,但我认为它现在看起来很混乱,因为我需要提供不同的组合,而不仅仅是在方法签名的末尾建立参数.
我应该不重载我的方法并坚持一个签名,以便我的方法的用户必须传入空值?它会使签名更清晰,但会使调用代码变得更加混乱.
c# ×5
.net ×4
json ×2
coffeescript ×1
debugging ×1
generics ×1
hardware ×1
heroku ×1
iphone ×1
iterator ×1
javascript ×1
jquery ×1
jquery-ui ×1
knockout.js ×1
mocking ×1
node.js ×1
objective-c ×1
rspec ×1
unit-testing ×1