我想测试我的 Quartz.Net 作业的执行功能,它实现了 Quartz.IJob:
public void Execute(IJobExecutionContext context)
Run Code Online (Sandbox Code Playgroud)
问题:如何创建一个新的 IJobExecutionContext 类实例。或者甚至不创建新的作业,而只需从现有的预定作业中获取它。
目标是创建一个测试,例如:
[Test()]
public void Test()
{
IJobExecutionContext jobExecutionContext = ???; //get a defined JobExecutionContext somehow...
m_myJob.Execute(jobExecutionContext);
}
Run Code Online (Sandbox Code Playgroud)
我发现的只是这个具有相同问题的相关帖子。他所说的只是“通过仅将 JobDataMap 对象传递给我的方法来解决:context.MergedJobDataMap”,我似乎无法重现。另一个建议,即使用起订量,目前对我来说是遥不可及的。虽然如果这真的是唯一的方法,我会专注于这个解决方案。但我认为如果我先尝试寻找一种更简单的方法,这是合理的。
Json.Net中的默认标识似乎是2个空格:
var result = JsonConvert.SerializeObject(jsonString, Formatting.Indented);
Run Code Online (Sandbox Code Playgroud)
为清楚起见,我想将其更改为4个空格,但我似乎没有找到应用该属性的正确方法.它似乎存在,因为我发现了一些类似的代码(这里是直接链接):
using (JsonTextWriter jw = new JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
jw.IndentChar = ' ';
jw.Indentation = 4;
jw.WriteRaw(config.ToString());
}
Run Code Online (Sandbox Code Playgroud)
...除非,如果可能的话,我会避免在这种情况下不必要地处理流.
有什么建议吗?
我需要告诉未知变量的类型.Type.GetTypeCode()对我的目的而言似乎已经足够好了,但是在byte[]它没有提供所需结果的情况下.
这是我的问题的简化代码:
var bytes = new byte[10];
var typeCode = Type.GetTypeCode(bytes.GetType());
// Actual result: typeCode equals Object
// Desired result (pseudocode): "array of TypeCode.Byte"
Run Code Online (Sandbox Code Playgroud) 问题
我正在尝试将一个道具传递给我的根构造函数。我知道这propsData 是要走的路:
var appComponent = Vue.component('app', require('./components/app/app.vue.html'));
new Vue({
el: '#app-root',
router: new VueRouter({ mode: 'history', routes: routes }),
propsData: { test: 'hi!' },
components: { appComponent },
render: h => h('app')
});
Run Code Online (Sandbox Code Playgroud)
这是AppComponent收到道具的:
export default class AppComponent extends Vue {
@Prop()
test: string;
mounted() {
console.log('test = ' + this.test);
// result: test = undefined
// expected: test = 'hi!'
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过的事情
使它在开发中(而不是在生产中)工作的唯一方法是:
test: string;
beforeCreate() {
this.test = this.$root.test;
} …Run Code Online (Sandbox Code Playgroud) 我想这样叫MarriageByIdGET:
var url = '/MarriageById?id=' + id;
Run Code Online (Sandbox Code Playgroud)
但我也想拥有一个ActionResult Marriage(Marriage marriage)可以在显示视图之前进行一些处理的单元。第二个原因必须是POST因为它还将收到来自asp的“发送表单”。
我正在尝试此解决方案(请参见下面的我自己的实现),但仍将其作为GET重定向,ActionResult Marriage但未找到:
[HttpGet]
public ActionResult MarriageById(int id)
{
var marriage = _marriageRepository.GetById(id);
return RedirectToAction(nameof(Marriage), marriage);
}
[HttpPost]
public ActionResult Marriage(Marriage marriage)
{
var people = _personRepository.GetAll();
ViewBag.men = Utils.GetPersonsSelectListByGender(people, isMale: true);
ViewBag.women = Utils.GetPersonsSelectListByGender(people, isMale: false);
return View(marriage);
}
Run Code Online (Sandbox Code Playgroud) c# ×4
.net ×1
asp.net ×1
asp.net-core ×1
javascript ×1
json.net ×1
quartz.net ×1
typescript ×1
vue.js ×1