我不能为我的生活找到使用Rhino中的Fluent/AAA语法来验证操作顺序的正确语法.
我知道如何使用旧的学校记录/播放语法执行此操作:
MockRepository repository = new MockRepository();
using (repository.Ordered())
{
// set some ordered expectations
}
using (repository.Playback())
{
// test
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我在Rhino Mocks的AAA语法中与此相当的是什么.如果你能指点我的一些文件,那就更好了.
我认为最好用一个例子来解释.
这是数据的样子:
|project |
|id|name |
|1 |some project |
|2 |my other project|
|run |
|id|project_id|start_time |result |
|1 |1 |1305732581845|something|
|2 |1 |1305732593721|nothing |
|3 |2 |1305732343721|nothing |
|4 |2 |1305732556821|something|
Run Code Online (Sandbox Code Playgroud)
我希望能够从项目的每个最新运行中获得整个记录集.SQL Query看起来像这样:
SELECT *, MAX("run"."start_time")
FROM "run"
LEFT OUTER JOIN "project" ON ("run"."project_id" = "project"."id")
GROUP BY "project"."id"
Run Code Online (Sandbox Code Playgroud)
这将返回两个表中所有列的最新项目运行,这很棒,这正是我需要的.
所以在尝试在django 1.3中找到django orm等价物时,我根本找不到合适的方法来做到这一点.如果我做这样的事情:
Run.objects.annotate(Max('start_time'))
Run Code Online (Sandbox Code Playgroud)
生成的SQL查询将类似于:
SELECT
"run"."id", "run"."result", "run"."project_id", "project"."id", "project"."name",
MAX("run"."start_time")
FROM "run"
LEFT OUTER JOIN "project" ON ("run"."project_id" = "project"."id")
GROUP BY "run"."id", "run"."result", "run"."project_id", "project"."id", …Run Code Online (Sandbox Code Playgroud) 我使用Spring 3.1.0.RELEASE进行Spring休息服务.以下是相关服务调用的相关代码:
@RequestMapping(value="/{var1}", method=RequestMethod.GET, produces="application/json")
@ResponseBody
public String getSomeStuff(@PathVariable final String var1) {
return myJsonString;
}
Run Code Online (Sandbox Code Playgroud)
如果我使用以下curl命令调用它,它很高兴地返回我的内容类型为application/xml的json字符串,而我期望基于Spring 3.1文档的406:
curl -v -H "Accept: application/xml" http://localhost:8080/MyServiceSite/myvalue
Run Code Online (Sandbox Code Playgroud)
我的应用程序中没有针对此服务的额外配置(无序列化),我返回原始json,没有对配置的服务进行后处理.我确定我错过了什么,有人能指出我可能错过的任何东西吗?
编辑:这是我试图让这个工作时看到的文档.具体见第16.3.2.5节.我的代码非常相似,只是它们的代码看起来像是假设配置设置让Spring处理序列化.绕过Spring序列化时,产品可能不起作用?
编辑:我改变了对响应代码的期望.A 415表示我在我的请求正文中发送了不正确的内容,而406表示接收表头与服务器的内容类型不一致.
无论如何,我已经改变了这个方法确实返回一个Map并添加了配置,以便序列化为json,现在如果我从客户端发送无效的内容类型,我得到正确的406响应.当方法的输出未被序列化时,似乎可能忽略"生成"设置.
我无法找到在jqgrid单元格中获得迷你图形渲染的正确方法,并且在我的生活中无法在任何地方找到任何相关的样本.
无论如何,经过一些研究我决定要做的是尝试将sparkline图注入afterRowInsert中的单元格.不幸的是我做错了.这是我在做的事情:
afterInsertRow: function(rowid, rowdata, rowelem) {
var cell = jQuery('#datapointlist').getCell(rowid, 'Graph');
$(cell).sparkline([1,34,3,2,1])
},
Run Code Online (Sandbox Code Playgroud)
插入时单元格的内容为"正在加载",事件发生后保持不变.我真的不确定这是否是尝试让这个工作的最佳方式,所以如果有人能帮助我,我将不胜感激.
在进行模拟调用之前自动更新时间戳的最佳方法是什么?
这是我试图测试的一些虚拟代码:
public class ThingWithATimestamp {
public Long timestamp;
public String name;
public ThingWithATimestamp(String name) {
this.name = name;
}
}
public class TheClassThatDoesStuff {
private ThingConnector connector;
public TheClassThatDoesStuff(ThingConnector connector) {
this.connector = connector;
}
public void updateTheThing(MyThingWithATimestamp thing) {
thing.timestamp = currentTimestamp();
connector.update(thing);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我想要测试的:
public class TheClassThatDoesStuffTests {
@Test
public void canUpdateTheThing() {
ThingConnector connector = mock(ThingConnector.class);
TheClassThatDoesStuff doer = new ThisClassThatDoesStuff(connector);
doer.updateTheThing(new ThingWithATimestamp("the name"));
verify(connector, times(1)).update(SomeMatcherThatICantFigureOut);
}
Run Code Online (Sandbox Code Playgroud)
我知道这段代码非常愚蠢,但我认为它准确地描绘了我想要验证的内容.我基本上需要一个匹配器来填写测试来验证时间戳是否在当前时间的X之内,所以我知道它已正确更新并且connector.update使用适当的时间戳为对象调用.
java ×2
unit-testing ×2
c# ×1
django ×1
django-orm ×1
jqgrid ×1
jquery ×1
mocking ×1
mockito ×1
mysql ×1
orm ×1
python ×1
rhino-mocks ×1
sparklines ×1
spring ×1
spring-mvc ×1
time ×1