我正在学习 MediatR,但在将控制器连接到处理程序时遇到问题。
控制器:
[HttpGet]
public async Task<List<PersonModel>> Get()
{
return await _mediator.Send(new GetPersonListQuery());
}
Run Code Online (Sandbox Code Playgroud)
我的理解是控制器将使用 来调用处理程序_mediator.Send()。然而,Send 的参数不是 Handler 而是Command/ Query。
在 Visual Studio 中,我检查了对处理程序的引用数量,结果显示为零。那么 MediatR 如何知道要调用哪个特定处理程序?
谢谢。
我创建了一个方法:
\npublic static Tuple<string, string, string> SplitStr(string req)\n{\n //...\n return (A, B, C)\n}\nRun Code Online (Sandbox Code Playgroud)\n它抱怨说"CSOOZQ: Cannot implicitly convert type '(strinq _keyword, strinq _filterCondition, strinq _filterCateqory)' to 'System.Tuple<strinq, strinq, string)\xe2\x80\x98"
但如果代码:
\npublic static (string, string, string) SplitStr(string req)\n{\n //...\n return (A, B, C)\n}\nRun Code Online (Sandbox Code Playgroud)\n错误消失。从错误来看,元组的括号形式和元组的括号形式Tuple<>不同。
Tuple<>?如何返回元组?谢谢。
\n我想做一个像这样的简单列表:
1. xxxxx
2. xxxxx
a. xxxxx
b. xxxxx
3. xxxxx
4. xxxxx
a. xxxxx
b. xxxxx
Run Code Online (Sandbox Code Playgroud)
内容取自反应状态变量并进行映射以创建此列表。状态变量结构尚未确定。
如果我使用 css ol & li,它看起来很简单。但当我查看 MUI List 时,它似乎不支持这一点。我必须手动创建编号 1,2,3 和 a,b,c。
是否有任何 MUI 组件可以完成与 css ul & li 类似的工作?
谢谢。
我读到 act / waitFor 是等待 DOM 更新。我还读到渲染是同步的。我假设我不需要用 act/waitFor 包装渲染,因为当我单击或测试时 DOM 总是会更新?它是否正确 ?
接下来,我不明白为什么我需要 act / waitFor ? 我不能只是等待吗? 对于测试A,我使用user.click,并且我看到在线示例代码使用await。它似乎在我的笔记本电脑上运行良好。
然而,在测试 B 中,当我看到 fireEvent.click 的一些示例代码时,他们使用了 waitFor。我尝试使用等待,它标记我“等待对这种类型的表达式没有影响”。但“await waitFor()”有效。为什么是这样 ?
首先十分感谢 !
Test A
it('user.click', async () => {
render(
<BrowserRouter>
<Notes />
</BrowserRouter>
);
const checkBox = screen.getByRole('checkbox');
await user.click(checkBox);
const prev = screen.getByRole('button', { name: 'Prev' });
expect(prev).toBeEnabled();
});
Test B
it('fireEvent.click', async () => {
render(
<BrowserRouter>
<Notes />
</BrowserRouter>
);
const checkBox = screen.getByRole('checkbox');
await fireEvent.click(checkBox);
const prev = …Run Code Online (Sandbox Code Playgroud) c# ×3
reactjs ×2
javascript ×1
list ×1
material-ui ×1
mediatr ×1
testing ×1
tuples ×1
unit-testing ×1
valuetuple ×1