我正在测试某个班级.该类在内部实例化一个"GetMethod"对象,该对象被传递给"HttpClient"对象,该对象被注入到测试类中.
我正在嘲笑"HttpClient"类,但我还需要修改"GetMethod"类的一个方法的行为.我正在玩ArgumentCaptor,但我似乎无法在"when"调用中获取实例化对象.
例:
HttpClient mockHttpClient = mock(HttpClient.class);
ArgumentCaptor<GetMethod> getMethod = ArgumentCaptor.forClass(GetMethod.class);
when(mockHttpClient.executeMethod(getMethod.capture())).thenReturn(HttpStatus.SC_OK);
when(getMethod.getValue().getResponseBodyAsStream()).thenReturn(new FileInputStream(source));
Run Code Online (Sandbox Code Playgroud)
响应:
org.mockito.exceptions.base.MockitoException:
No argument value was captured!
You might have forgotten to use argument.capture() in verify()...
...or you used capture() in stubbing but stubbed method was not called.
Be aware that it is recommended to use capture() only with verify()
Run Code Online (Sandbox Code Playgroud) 假设我已经调用了$ element.fadeIn(200).100毫秒后,该页面上发生了一些事情,我想要中断淡入淡出并立即fadeOut().我怎样才能做到这一点?
如果调用$ element.fadeIn(200).fadeOut(0),则fadeOut()仅在fadeIn()完成后发生.
另外,有没有办法我可以检查$ element来确定fadeIn()或fadeOut()是否正在运行?$ element是否有任何更改的.data()成员?
这个问题与用于线程提示的gmail中的Header相反
我有一个系统可以为各种事情生成通知.其中很多都有相同的主题,但内容不同.
无论如何还没有在主题行中添加某种独特的令牌,迫使电子邮件不在同一个线程中,即单独显示.更改标题和/或内容是可以接受的,但更改主题行会吓到人.此外,并非所有收件人都是Google Apps/@gmail.com帐户,因此我无法使用"+ hash"之类的内容.
如果重要,应用程序是用C#和ASP.Net编写的.
有人知道怎么做吗?
在SQLite中,如何选择some_column为空的记录?
空计为NULL和"".
嘿所有,我想知道如何在我的表格上创建动态复选框时,我不知道我需要多少个盒子.
问题是我不知道如何DIM多个对象.这是我创建一个复选框的代码
Dim checkBox As New CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)
Run Code Online (Sandbox Code Playgroud)
它工作得很好,但我不能添加多个checkBox而不必这样做:
Dim checkBox As New CheckBox()
Dim checkBox2 As New CheckBox()
Form1.Controls.Add(checkBox)
checkBox.Location = New Point(10, 10)
checkBox.Text = "testing"
checkBox.Checked = True
checkBox.Size = New Size(100, 20)
Form1.Controls.Add(checkBox2)
checkBox2.Location = New Point(40, 10)
checkBox2.Text = "testing2"
checkBox2.Checked = True
checkBox2.Size = New Size(100, 20)
Run Code Online (Sandbox Code Playgroud)
等等...
有没有办法调暗多个复选框而不必为每个checkBoxe写多个dim语句?
对不起也许我应该这样说..
我想做这样的事情:
dim checkBox() as CheckBox
do until i …Run Code Online (Sandbox Code Playgroud) 这很好用:
Func<string, string> func1 = s => s + "func";
ViewState["function"] = func1;
Run Code Online (Sandbox Code Playgroud)
但是,这不是:
Func<string, string> func1 = s => s + "func";
Func<string, string> func2 = s => func1(s);
ViewState["function"] = func2;
Run Code Online (Sandbox Code Playgroud)
它会抛出运行时序列化异常: Type 'MyProjectName._Default+<>c__DisplayClass3' in Assembly 'MyProjectName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
现在,我可以解决这个问题,但是我想了解为什么会发生这种情况,以便将来除了在序列化之前编写函数之外我别无选择,我将有一个解决方案.
我使用的ASP.NET越多,就越if (!IsPostBack) {}没有意义......
第一个例子:
例如,我只是用谷歌搜索了一个问题,他们说这是解决方案的一部分:
if (!Page.IsPostBack)
{
Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
Run Code Online (Sandbox Code Playgroud)
完全与编码完全相同,LoadComplete仅在第一次加载时触发.单击按钮或触发回发的任何内容后,LoadComplete事件将取消挂钩,从而跳过事件处理程序.因此,他们的"修复"仅适用于第一次加载=毫无价值.我立即注释掉了if (!Page.IsPostBack) {},现在事件总是按照需要触发.
第二个例子:
我试图将事件挂钩到动态创建的按钮(顺便说一下,我无法开始工作[GRR!]).我看到示例显示:
myEditToggleButton = new Button();
myEditToggleButton.ID = "editToggleButton";
//^GOTTA HAVE THIS FOR EVENTS TO WORK! (supposedly, I haven't seen it work...)
if (!IsPostBack)
{
myEditToggleButton.Click += new EventHandler(myEditToggleButton_Click);
}
Controls.Add(myEditToggleButton);
Run Code Online (Sandbox Code Playgroud)
与第一个示例一样,我的理解是在第一次加载页面后不会挂起事件,因此单击一下按钮就是"惰性"(因为点击触发了回发).
题:
你应该什么时候使用if (!IsPostBack) {}?我猜它只与标记创建的控件有关.
在gmail中如果你勾选标记电子邮件4然后移动到不同的50或25个记录并标记选择26,那么如果你来回移动则保留4和26.
谷歌如何做到这一点?
是否有可能在一个只带50条记录的页面中做这样的事情,当点击NEXT时...它再次进入DB以带来下一组50条记录.
C#,VS2010,WinForm应用程序:
有时我确实遇到了打开一些控件/表单时收到错误消息的问题.所有代码都编译并且应用程序正常运行.打开设计师的控件给了我:
设计器加载器没有提供根组件,但没有说明原因.
根据我的经验,我可以说,在我的代码中通常会出现一些未正确初始化的内容,例如,某个属性未设置在运行时以某种方式可用,但在设计人员打开时则无法设置.唯一的问题是,根本原因很难找到.
问:当设计人员在Visual Studio 2010中打开我的组件时,是否有机会以某种方式使用调试器?这将有很大帮助,解决问题很可能只需几分钟.
备注:为了清楚说明,我知道如何使用调试器;-),我只是不知道如何告诉VS2010的设计人员在调试模式下打开我的控件.
截至2010年9月2日,增加了:
谢谢你的帮助.基本上它是描述如何执行它的MSDN Library文章.
顺便说一句,使用这种方法,从符号加载(通过模块窗口)中排除一些东西是有帮助的,因为这将安全很多时间.
现在,如果必须弄清楚如何解决符号,那么我可以解决这个问题.....
我有一个简单的服务,我尝试设置身份验证.在客户端上,我希望用户输入他们的Windows用户帐户.WCF将使用客户端提供的用户名/密码,并根据Windows身份验证对其进行身份验证.
这是我的服务器app.config
<system.serviceModel>
<services>
<service name="WcfService.Service1" behaviorConfiguration="WcfService.Service1Behavior">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8731/Design_Time_Addresses/WcfService/Service1/" />
</baseAddresses>
</host>
<endpoint address ="" binding="wsHttpBinding" contract="WcfService.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfService.Service1Behavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode = "Windows"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Run Code Online (Sandbox Code Playgroud)
这是我的客户端app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IService1">
<security mode = "Message">
<message clientCredentialType = "UserName"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/Design_Time_Addresses/WcfService/Service1/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">
<identity>
<dns value="localhost" /> …Run Code Online (Sandbox Code Playgroud)