Исходный код вики NSubstitute

Версия 1.3 от Alexandr Fokin на 2026/03/17 15:13

Скрыть последних авторов
Alexandr Fokin 1.3 1 |(% style="width:131px" %) |(% style="width:1351px" %)(((
2 | |nsubstitute/NSubstitute
3 [[https:~~/~~/github.com/nsubstitute/NSubstitute>>https://github.com/nsubstitute/NSubstitute]]
4 | |
5 | |
6 )))
7 |(% style="width:131px" %)Преимущества|(% style="width:1351px" %)(((
8 |[[Moq>>doc:Разработка.NET.Библиотеки.Тестирование.Moq.WebHome]] для создания заглушки используется билдер, который формирует экземпляр. NSubstitute позволяет редактировать заглушку в любой момент (а не только в на этапе конфигурации), иногда это может быть удобно.|
9 |NSubstitute позволяет указывать заглушку не только через Generic тип, но и через [[Reflection ~~~| Рефлексия >>doc:Разработка.NET.C#.Рантайм и типы.Reflection | Рефлексия .WebHome]] указывая {{code language="c#"}}Type{{/code}} интерфейса.
10 Также есть возможность указать метод через {{code language="c#"}}MethodInfo{{/code}}.|
11 | |
12 )))
13 |(% style="width:131px" %)Сценарии|(% style="width:1351px" %)(((
14 |(% style="width:236px" %)Создание заглушки по Type|(% style="width:1096px" %){{code language="c#"}}var stub = Substitude.For(typeof(IService), []);{{/code}}
15 |(% style="width:236px" %)Указание метода по MethodInfo|(% style="width:1096px" %)(((
16 Can NSubstitute mock the return of a MethodInfo?
17 [[https:~~/~~/stackoverflow.com/questions/41918308/can-nsubstitute-mock-the-return-of-a-methodinfo>>https://stackoverflow.com/questions/41918308/can-nsubstitute-mock-the-return-of-a-methodinfo]]
18
19 {{code language="c#"}}
20 var stub = Substitute.For<IService>();
21 var methodInfo = typeof(IService).GetMethod("Method1");
22 methodInfo.Invoke(stub, null).Returns((e) => "stub");
23
24 {{/code}}
25 )))
26 |(% style="width:236px" %) |(% style="width:1096px" %)
27 )))
28
29
30
Alexandr Fokin 1.2 31 ----
32
33 ==== Внутренние ссылки: ====
34
35 ====== Дочерние страницы: ======
36
37 {{children/}}
38
39 ====== Обратные ссылки: ======
40
41 {{velocity}}
42 #set ($links = $doc.getBacklinks())
43 #if ($links.size() > 0)
44 #foreach ($docname in $links)
45 #set ($rdoc = $xwiki.getDocument($docname).getTranslatedDocument())
46 * [[$escapetool.xml($rdoc.fullName)]]
47 #end
48 #else
49 No back links for this page!
50 #end
51 {{/velocity}}
52
53 ----