{"id":337503,"date":"2022-08-25T03:00:08","date_gmt":"2022-08-25T03:00:08","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=337503"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=337503","title":{"rendered":"<span>\u041c\u0435\u0447\u0442\u0430\u044e\u0442 \u043b\u0438 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438 \u043e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u0430\u0445 \u2014 2. \u041e\u0441\u043e\u0431\u043e\u0435 \u043c\u043d\u0435\u043d\u0438\u0435<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/35b\/5f6\/c3b\/35b5f6c3b68342f08dc0f0ffa3437db3.png\" width=\"780\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/35b\/5f6\/c3b\/35b5f6c3b68342f08dc0f0ffa3437db3.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c, \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u043e\u0432 &#171;<em>\u0441\u043c\u043e\u0442\u0440\u0438, \u043a\u0430\u043a \u044f \u0443\u043c\u0435\u044e<\/em>&#171;, \u0434\u0440\u0443\u0433\u0430\u044f \u0436\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u2014 \u043f\u043e\u0441\u043b\u0435 &#171;<em>\u0435\u0440\u0443\u043d\u0434\u0430, \u0441\u043c\u043e\u0442\u0440\u0438, \u043a\u0430\u043a \u043d\u0430\u0434\u043e<\/em>&#171;.<\/p>\n<p>\u0422\u0443\u0442 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u044f\u0442\u0435\u043b\u044c, \u0443\u0432\u0438\u0434\u0435\u0432 <a href=\"https:\/\/habr.com\/ru\/post\/681886\/\" rel=\"noopener noreferrer nofollow\">\u0444\u043e\u043a\u0443\u0441 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0431\u0435\u0437 \u0442\u0435\u0441\u0442\u043e\u0432<\/a>\u00a0\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0445 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438\u0437 preview \u0432\u0435\u0440\u0441\u0438\u0438 C# \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b NUnit, \u043e\u0442\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0442\u0440\u0430\u043d\u0441-\u0440\u0435\u043a\u0442\u0430\u043b\u044c\u043d\u043e, \u0430 \u0441\u0430\u043c \u0431\u044b \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b Fody, \u0438 \u0432\u044b\u0448\u043b\u043e \u0431\u044b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435. \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043b. \u0410 \u043c\u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b\u0441\u044f\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/513062\/#comment_21932102\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/a>\u00a0\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430. \u0422\u043e\u0433\u0434\u0430 \u0440\u0443\u043a\u0438 \u043d\u0435 \u0434\u043e\u0448\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u043e\u0442 \u0440\u0435\u0448\u0438\u043b \u0433\u043b\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u043f\u0442\u0438\u0446\u0430, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#1\" rel=\"noopener noreferrer nofollow\">\u0414\u0430\u043d\u043e<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#2\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#3\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h4>\u0414\u0430\u043d\u043e<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0432 \u0444\u043e\u043a\u0443\u0441\u0435, \u0442\u043e \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 `IScript`, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0430\u0442\u0430\u043a\u043e\u0439 `Attack` \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0442\u0430\u043a\u043e\u0439 `AdvancedAttack`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface IScript { }  public class Attack : IScript { }  public class AdvancedAttack : Attack { }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 `IValidator`, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c `OrdinaryValidator` \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c `AdvancedValidator`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface IValidator {     void Validate(IScript script); }  public class OrdinaryValidator : IValidator {     void IValidator.Validate(IScript script)     {         if (script is Attack &amp;&amp; script is not AdvancedAttack)             throw new Exception(\"Attack detected.\");     } }  public class AdvancedValidator : IValidator {     void IValidator.Validate(IScript script)     {         if (script is Attack)             throw new Exception(\"Attack detected.\");     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 `ICheck`. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0430\u0442\u0430\u043a\u0438 `AttackDetected`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface ICheck {     bool Check(IValidator validator, IScript script); }  public class AttackDetected : ICheck {     public bool Check(IValidator validator, IScript script)     {         try         {             validator.Validate(script);             return false;         }         catch         {             return true;         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432 (\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e <code>OrdinaryValidator<\/code> \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0433\u043e <code>AdvancedValidator<\/code>) \u0441 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0442\u0430\u043a\u043e\u0439 <code>AdvancedAttack<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">using NUnit.Framework;  [TestFixture] public class DemoTests : IDeclarativeTest {     public void Test&lt;TValidator, TScript, TCheck>(bool expected)         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new() =>         DefaultDeclarativeTest.Test&lt;TValidator, TScript, TCheck>(expected);      [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)]     [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)]     public void TestAdvancedAttack() { } }<\/code><\/pre>\n<p>\u0424\u043e\u043a\u0443\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0435\u0441\u0442\u044b \u0431\u0435\u0437 \u0442\u0435\u043b\u0430 \u043c\u0435\u0442\u043e\u0434\u0430, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c \u0438 \u0432 \u043d\u0435\u043c \u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c `DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>` \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> : GenericCaseAttribute, ITestBuilder         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new() {     private static readonly IReadOnlyCollection&lt;Type> types = new[]     {         typeof(TValidator),         typeof(TScript),         typeof(TCheck)     };      public DeclarativeCaseAttribute(bool expected)         : base(expected) { }      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite)     {         IEnumerable&lt;TestMethod> tests;         var type = suite.TypeInfo.Type;          if (!typeof(IDeclarativeTest).IsAssignableFrom(type))             tests = base.BuildFrom(method, suite)                 .SetNotRunnable($\"{type} does not implement {typeof(IDeclarativeTest)}.\");         else if (!method.MethodInfo.IsIdle())             tests = base.BuildFrom(method, suite)                 .SetNotRunnable(\"Method is not idle, i.e. does something.\");         else             tests = base.BuildFrom(new MethodWrapper(type, nameof(IDeclarativeTest.Test)), suite);                  return tests.Select(test =>         {             test.FullName = CreateName(test, suite, method,                 suite => suite.FullName, type => type.FullName);             test.Name = CreateName(test, suite, method,                 suite => suite.Name, type => type.Name);             return test;         });     }      private static string CreateName(         TestMethod test,         Test suite,         IMethodInfo method,         Func&lt;Test, string> suitNameSelector,         Func&lt;Type, string> typeNameSelector) =>         $\"{suitNameSelector(suite)}.{method.Name}&lt;{             string.Join(\",\", types.Select(typeNameSelector))}>({             string.Join(',', test.Arguments)})\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442 <code>GenericCaseAttribute<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>TestCaseAttribute<\/code> \u0443\u043c\u0435\u0435\u0442 \u0432 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>ITestBuilder<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>`GenericCaseAttribute`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class GenericCaseAttribute : TestCaseAttribute, ITestBuilder {     private readonly IReadOnlyCollection&lt;Type> typeArguments;      public GenericCaseAttribute(params object[] arguments)         : base(arguments) => typeArguments = GetType().GetGenericArguments();      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite)     {         try         {             return base.BuildFrom(                 method.IsGenericMethodDefinition || typeArguments.Any() ?                 method.MakeGenericMethod(typeArguments.ToArray()) :                 method,                 suite);         }         catch (Exception ex)         {             return base.BuildFrom(method, suite).SetNotRunnable(ex.Message);         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0430\u043c <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0442\u043e\u0436\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>ITestBuilder<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 <code>IDeclarativeTest.Test<\/code>, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IDeclarativeTest<\/code> \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. (\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043f\u043e\u0434\u043c\u0435\u043d\u043e\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IDeclarativeTest<\/code> \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0433\u043e \u0438 \u043d\u0435\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0440\u0438\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f NUnit, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u0431\u044b\u043b \u043e\u0442\u0432\u0435\u0440\u0433\u043d\u0443\u0442 \u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438). \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442\u0441\u044f \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b Test Explorer.<\/p>\n<details class=\"spoiler\">\n<summary>\u0415\u0449\u0435 \u0432\u0441\u044f\u043a\u0430\u044f \u043c\u0435\u043b\u043e\u0447\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices;  public static class TestMethodExtensions {     public static IEnumerable&lt;TestMethod> SetNotRunnable(this IEnumerable&lt;TestMethod> tests, string message)     {         foreach(var test in tests)             yield return test.SetNotRunnable(message);     }      public static TestMethod SetNotRunnable(this TestMethod test, string message)     {         test.RunState = RunState.NotRunnable;         test.Properties.Set(PropertyNames.SkipReason, message);         return test;     } }  public static class MethodInfoExtensions {     private static readonly IReadOnlyCollection&lt;byte> idle = new[]     {         OpCodes.Nop,         OpCodes.Ret     }.Select(code => (byte)code.Value).ToArray();      public static bool IsIdle(this MethodInfo method)     {         var body = method.GetMethodBody();          if (body.LocalVariables.Any())             return false;          if (body.GetILAsByteArray().Except(idle).Any())             return false;          if (method.DeclaringType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)             .Any(candidate => IsLocalMethod(candidate, method)))             return false;          return true;     }      private static bool IsLocalMethod(MethodInfo method, MethodInfo container) =>         method.Name.StartsWith($\"&lt;{container.Name}>\") &amp;&amp;         method.GetCustomAttributes&lt;CompilerGeneratedAttribute>().Any(); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>DemoTests<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>IDeclarativeTest<\/code> \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 <code>DefaultDeclarativeTest<\/code>, \u043a\u043e\u0442\u0440\u043e\u0440\u044b\u0439, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"cs\">using NUnit.Framework;  public static class DefaultDeclarativeTest {     public static void Test&lt;TValidator, TScript, TCheck>(bool expected)         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new()     {         \/\/ Arrange         IValidator validator = new TValidator();         IScript script = new TScript();         ICheck check = new TCheck();          \/\/ Act         bool actual = check.Check(validator, script);          \/\/ Assert         Assert.AreEqual(expected, actual);     } }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p><code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0438 <code>DefaultDeclarativeTest<\/code> \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u0441\u0432\u043e\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f self-review \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438. \u0412\u043e\u043e\u0431\u0449\u0435, \u0440\u0435\u0432\u044c\u044e &#8212; \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430. \u041f\u043e\u043c\u043d\u044e, \u0432 \u043e\u0434\u043d\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u0432\u044c\u044e\u0438\u043b \u043a\u0430\u0436\u0434\u043e\u0433\u043e. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0440\u043e\u0432\u043e\u043b\u044c\u043d\u043e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0442\u043a\u043b\u0438\u043a\u0430\u043b\u043e\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430. \u0418 \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u0442\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u043b\u0441\u044f \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438 \u043c\u0435\u043b\u043e\u0447\u0438, \u0443\u0441\u043a\u043e\u043b\u044c\u0437\u0430\u0432\u0448\u0438\u0435 \u043e\u0442 \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u043f\u0435\u0440\u0432\u044b\u0445, \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0443\u0447\u0448\u0435. \u041a\u043e\u0440\u043e\u0447\u0435, \u0431\u0440\u0430\u0442\u0438\u0435, \u0434\u0430 \u0440\u0435\u0432\u044c\u044e\u0438\u0442\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<\/p>\n<\/div>\n<\/details>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u043c <code>GenericCaseAttribute<\/code> \u0441 <code>IDeclarativeTest<\/code> \u0438 \u0438\u0445 \u0441\u043b\u0435\u0434\u044b. \u041f\u043e\u043f\u0443\u0442\u043d\u043e \u0432 <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0437\u0430\u0432\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u0435 <code>bool expected<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c <strong><em>&#171;Arguments provided for method with no parameters&#187;<\/em><\/strong>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c `DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>` \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> : TestCaseAttribute, ITestBuilder         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new() {     private static readonly IReadOnlyCollection&lt;Type> types = new[]     {         typeof(TValidator),         typeof(TScript),         typeof(TCheck)     };     private readonly bool expected;      public DeclarativeCaseAttribute(bool expected) =>         this.expected = expected;      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite)     {         IEnumerable&lt;TestMethod> tests;          if (!method.MethodInfo.IsIdle())             tests = base.BuildFrom(method, suite)                 .SetNotRunnable(\"Method is not idle, i.e. does something.\");         else             tests = base.BuildFrom(method, suite);           return tests.Select(test =>         {             test.FullName = CreateName(test, suite, method,                 suite => suite.FullName, type => type.FullName);             test.Name = CreateName(test, suite, method,                 suite => suite.Name, type => type.Name);             return test;         });     }      private string CreateName(         TestMethod test,         Test suite,         IMethodInfo method,         Func&lt;Test, string> suitNameSelector,         Func&lt;Type, string> typeNameSelector) =>         $\"{suitNameSelector(suite)}.{method.Name}&lt;{             string.Join(\",\", types.Select(typeNameSelector))}>({expected})\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0410 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0442\u0430\u043a (\u0442\u0435\u0441\u0442\u044b, \u043a\u0441\u0442\u0430\u0442\u0438, \u0443\u0436\u0435 \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u044e\u0442):<\/p>\n<pre><code class=\"cs\">using NUnit.Framework;  [TestFixture] public class DemoTests {     [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)]     [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)]     public void TestAdvancedAttack() { } }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0448\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0432\u044b\u0431\u0440\u0430\u0442\u044c weaver. \u041c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0447\u0435\u0440\u0435\u0437 NuGet UI \u043f\u043e \u0444\u0438\u043b\u044c\u0442\u0440\u0443 &#171;fody&#187; \u0438 \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c, \u0447\u0442\u043e \u043f\u043e\u0442\u0435\u043d\u0446\u0438\u0430\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0442 <strong><em>MethodBoundaryAspect.Fody<\/em><\/strong> \u0438 <strong><em>MethodDecorator<\/em><\/strong>. \u041e\u043d\u0438 \u043e\u0431\u0430 \u0436\u0438\u0432\u044b\u0435, \u043d\u043e \u0443 \u043f\u0435\u0440\u0432\u043e\u0433\u043e \u0432 1.5 \u0440\u0430\u0437\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0437\u0430\u0433\u0440\u0443\u0437\u043e\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u043d\u0435\u043c. \u0415\u0441\u0442\u044c \u0435\u0449\u0435 \u043e\u0434\u043d\u0430 \u043f\u0440\u0438\u0447\u0438\u043d\u0430, \u043d\u043e \u043e \u043d\u0435\u0439 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>NuGet UI<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5b3\/d2c\/262\/5b3d2c262b818abedec2acfd7682f4de.png\" alt=\"\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 fody weaver \u0432 NuGet\" title=\"\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 fody weaver \u0432 NuGet\" width=\"1232\" height=\"688\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5b3\/d2c\/262\/5b3d2c262b818abedec2acfd7682f4de.png\"\/><figcaption>\u0412\u044b\u0431\u0438\u0440\u0430\u0435\u043c \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0438\u0439 fody weaver \u0432 NuGet<\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0418\u0434\u0435\u043c \u0432 <a href=\"https:\/\/github.com\/vescon\/MethodBoundaryAspect.Fody#the-aspect-code\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u043c<\/a> \u0438 \u043f\u043e \u043a\u043e\u0441\u0432\u0435\u043d\u043d\u044b\u043c \u043f\u0440\u0438\u0437\u043d\u0430\u043a\u0430\u043c \u0432\u0438\u0434\u0438\u043c, \u0447\u0442\u043e \u043e\u043d \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043a\u043b\u0430\u0441\u0441. \u0410 <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0443\u0436\u0435 \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 <code>TestCaseAttribute<\/code>. \u041a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u0434\u043b\u044f NUnit \u0433\u043b\u0430\u0432\u043d\u043e\u0435 &#8212; \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432 (\u0442\u0435 \u0436\u0435 <code>TestCaseAttribute<\/code> \u0438 <code>TestAttribute<\/code> \u043d\u0435 \u0441\u0432\u044f\u0437\u0430\u043d\u044b \u0446\u0435\u043f\u043e\u0447\u043a\u043e\u0439 \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044f, \u043d\u043e \u043e\u0431\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u044e\u0442\u0441\u044f, \u043a\u0430\u043a \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u044b). \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u044e\u0430\u043d\u0441\u0430 \u0438 \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u0447\u0438\u043d\u0430 \u0432\u044b\u0431\u043e\u0440\u0430 weaver&#8217;\u0430. \u0422\u0430\u043a \u0447\u0442\u043e \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u043c <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u043e\u0442 <code>OnMethodBoundaryAspect<\/code> \u0438 \u043f\u0435\u0440\u0435\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>void OnEntry(MethodExecutionArgs)<\/code>, \u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>ITestBuilder<\/code>, <code>ITestCaseData<\/code>, <code>IImplyFixture<\/code> \u0434\u0435\u043b\u0430\u0435\u043c \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043f\u043e\u043b\u044f  <code>TestCaseAttribute testCaseAttribute<\/code>. \u0417\u0430\u043e\u0434\u043d\u043e \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c <strong><em>&#171;Method is not idle, i.e. does something&#187;<\/em><\/strong> (weaver \u043f\u0435\u0440\u0435\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0434\u043e \u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0432 \u0442\u0435\u0441\u0442\u044b), \u0443\u0434\u0430\u043b\u044f\u044f \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0443\u044e \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 (\u043d\u043e \u043f\u043e\u0442\u043e\u043c \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b \u0435\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c).<\/p>\n<details class=\"spoiler\">\n<summary>`DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using MethodBoundaryAspect.Fody.Attributes; using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  [AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = false)] public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> :     OnMethodBoundaryAspect, ITestBuilder, ITestCaseData, IImplyFixture     where TValidator : IValidator, new()     where TScript : IScript, new()     where TCheck : ICheck, new() {     private static readonly IReadOnlyCollection&lt;Type> types = new[]     {         typeof(TValidator),         typeof(TScript),         typeof(TCheck)     };     private readonly bool expected;     private readonly TestCaseAttribute testCaseAttribute = new();      public DeclarativeCaseAttribute(bool expected) =>         this.expected = expected;      public override void OnEntry(MethodExecutionArgs arg) =>         DefaultDeclarativeTest.Test&lt;TValidator, TScript, TCheck>(expected);      public IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite) =>         testCaseAttribute.BuildFrom(method, suite).Select(test =>         {             test.FullName = CreateName(test, suite, method,                 suite => suite.FullName, type => type.FullName);             test.Name = CreateName(test, suite, method,                 suite => suite.Name, type => type.Name);             return test;         });      public object ExpectedResult => testCaseAttribute.ExpectedResult;      public bool HasExpectedResult => testCaseAttribute.HasExpectedResult;      public string TestName => testCaseAttribute.TestName;      public RunState RunState => testCaseAttribute.RunState;      public object[] Arguments => testCaseAttribute.Arguments;      public IPropertyBag Properties => testCaseAttribute.Properties;      private string CreateName(         TestMethod test,         Test suite,         IMethodInfo method,         Func&lt;Test, string> suitNameSelector,         Func&lt;Type, string> typeNameSelector) =>         $\"{suitNameSelector(suite)}.{method.Name}&lt;{             string.Join(\",\", types.Select(typeNameSelector))}>({expected})\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u043d\u0430\u0433\u0440\u0430\u0434\u0443 \u0437\u0430 \u0432\u0441\u0435 \u044d\u0442\u0438 \u043f\u0440\u0438\u0441\u0435\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043f\u0430\u0434\u0435\u043d\u0438\u0435 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c:<\/p>\n<pre><code>Message:\u2009 System.InvalidOperationException : Could not execute the method because either the method itself or the containing type is not fully instantiated.    Stack Trace:\u2009 DeclarativeCaseAttribute`3.ctor(Boolean expected) DemoTests.TestAdvancedAttack()<\/code><\/pre>\n<p>\u0414\u0443\u043c\u0430\u044e, \u043f\u043e\u0440\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0447\u0442\u043e \u0436\u0435 \u0442\u0430\u043c \u043d\u0430\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0432 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434. \u0421\u043c\u043e\u0442\u0440\u0438\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043c\u0435\u0442\u043e\u0434\u0430 \u0432 \u043a\u0430\u043a\u043e\u043c-\u043d\u0438\u0431\u0443\u0434\u044c ILSpy \u0438 \u0432\u0438\u0434\u0438\u043c:<\/p>\n<pre><code class=\"cs\">object[] __var_0 = new object[0]; MethodExecutionArgs __var_4 = new MethodExecutionArgs(); __var_4.Arguments = __var_0; MethodBase __var_5 = (__var_4.Method = MethodInfos._methodInfo_2742FEFF28FE4F5C0DA05D8E6FB631BC053D523283F80EE7DFD2FA576C10BE40); DemoTests __var_1 = (DemoTests)(__var_4.Instance = this); DeclarativeCaseAttribute&lt;OrdinaryValidator, AdvancedAttack, AttackDetected> __var_6 = (DeclarativeCaseAttribute&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>)(object)new DeclarativeCaseAttribute&lt;, , >(expected: false); DeclarativeCaseAttribute&lt;AdvancedValidator, AdvancedAttack, AttackDetected> __var_8 = (DeclarativeCaseAttribute&lt;AdvancedValidator, AdvancedAttack, AttackDetected>)(object)new DeclarativeCaseAttribute&lt;, , >(expected: true); ((DeclarativeCaseAttribute&lt;, , >)(object)__var_6).OnEntry(__var_4); object __var_7 = __var_4.MethodExecutionTag; FlowBehavior __var_2 = __var_4.FlowBehavior; if (__var_2 != FlowBehavior.Return) { ((DeclarativeCaseAttribute&lt;, , >)(object)__var_8).OnEntry(__var_4); object __var_9 = __var_4.MethodExecutionTag; FlowBehavior __var_3 = __var_4.FlowBehavior; if (__var_3 != FlowBehavior.Return) { $_executor_TestAdvancedAttack(); } }<\/code><\/pre>\n<p>\u041e\u0447\u0435\u0432\u0438\u0434\u043d\u043e, \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u043a\u043e\u0434. \u042d\u0442\u043e \u043b\u0435\u0433\u043a\u043e \u043f\u043e\u0434\u0442\u0432\u0435\u0440\u0434\u0438\u0442\u044c, \u043c\u0435\u043d\u044f \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432. \u0422\u0430\u043a\u0436\u0435 \u043f\u0440\u0438\u0441\u0443\u0442\u0441\u0442\u0432\u0438\u0435 \u0432 \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 <code>DeclarativeCaseAttribute&lt;, , >(expected: false)<\/code> \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u043e \u0442\u0440\u0443\u0434\u043d\u043e\u0441\u0442\u044f\u0445 \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u043c\u0438 \u0442\u0438\u043f\u0430\u043c\u0438. \u041a\u0430\u043a-\u0442\u043e \u043f\u043e\u043a\u0430 \u043d\u0435 \u0432\u044b\u0445\u043e\u0434\u0438\u0442 \u043a\u0430\u043c\u0435\u043d\u043d\u044b\u0439 \u0446\u0432\u0435\u0442\u043e\u043a.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u0438\u044e \u043e\u0442 `TestCaseAttribute` \u0438 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043c `string CreateName(IMethodInfo, Func&lt;Type, string>)`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> : TestCaseAttribute, ITestBuilder     where TValidator : IValidator, new()     where TScript : IScript, new()     where TCheck : ICheck, new() {     private static readonly IReadOnlyCollection&lt;Type> types = new[]     {         typeof(TValidator),         typeof(TScript),         typeof(TCheck)     };     private readonly bool expected;      public DeclarativeCaseAttribute(bool expected) =>         this.expected = expected;      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite) =>         base.BuildFrom(method, suite).Select(test =>         {             test.FullName = CreateName(method, type => type.FullName);             test.Name = CreateName(method, type => type.Name);             return test;         });      private string CreateName(IMethodInfo method, Func&lt;Type, string> nameSelector) =>         $\"{nameSelector(method.TypeInfo.Type)}.{method.Name}&lt;{             string.Join(\",\", types.Select(nameSelector))}>({expected})\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442 <code>DeclarativeAttribute<\/code>:<\/p>\n<pre><code class=\"cs\">using MethodBoundaryAspect.Fody.Attributes;  public class DeclarativeAttribute : OnMethodBoundaryAspect {     public override void OnEntry(MethodExecutionArgs arg)     {         arg.FlowBehavior = FlowBehavior.Return; \/\/ original method's code won't execute          \/\/ ???     } }<\/code><\/pre>\n<p>\u0418 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c \u0435\u0433\u043e \u043a \u0442\u0435\u0441\u0442\u0430\u043c:<\/p>\n<pre><code class=\"cs\">[Declarative] [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)] [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)] public void TestAdvancedAttack() { }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0432\u043e\u0437\u043d\u0438\u043a\u0430\u0435\u0442 \u0432\u043e\u043f\u0440\u043e\u0441, \u0447\u0442\u043e \u0436\u0435 \u0434\u0435\u043b\u0430\u0442\u044c \u0432 <code>void OnEntry(MethodExecutionArgs)<\/code> \u0438 \u043a\u0430\u043a \u0443\u0437\u043d\u0430\u0442\u044c, \u0432 \u0441\u0432\u044f\u0437\u0438 \u0441 \u043a\u0430\u043a\u0438\u043c <code>DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected><\/code> \u043e\u043d \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b \u0445\u043e\u0442\u0438\u0442\u0435 \u043e\u0442\u0432\u0435\u0442\u043e\u0432 &#8212; \u0438\u0445 \u0435\u0441\u0442\u044c \u0443 \u043c\u0435\u043d\u044f. \u041d\u043e \u0441\u043f\u0435\u0440\u0432\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u0440\u0435\u0444\u0430\u043a\u0442\u043e\u0440\u0438\u043d\u0433.<\/p>\n<details class=\"spoiler\">\n<summary>\u0412 `DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>` \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u043c `IDeclarativeTest`, \u043f\u043e\u043c\u0435\u0449\u0430\u044f \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430,  \u043a\u043b\u0430\u0441\u0441 `DefaultDeclarativeTest` \u0436\u0435 \u0437\u0430 \u043d\u0435\u043d\u0430\u0434\u043e\u0431\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0434\u0430\u043b\u044f\u0435\u043c.<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public interface IDeclarativeTest {     public void Test(); }  public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> :     TestCaseAttribute, ITestBuilder, IDeclarativeTest     where TValidator : IValidator, new()     where TScript : IScript, new()     where TCheck : ICheck, new() {     \/\/ ...      public void Test()     {         \/\/ Arrange         IValidator validator = new TValidator();         IScript script = new TScript();         ICheck check = new TCheck();          \/\/ Act         bool actual = check.Check(validator, script);          \/\/ Assert         Assert.AreEqual(expected, actual);     }      \/\/ ... }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0410 \u0442\u0435\u043f\u0435\u0440\u044c \u0444\u0438\u043d\u0442 \u0443\u0448\u0430\u043c\u0438. \u0423 <code>NUnit.Framework.Internal.Test<\/code> \u0435\u0441\u0442\u044c \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e <code>IPropertyBag Properties<\/code>. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0432 <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u043f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0442\u0435\u0441\u0442\u043e\u0432:<\/p>\n<pre><code class=\"cs\">public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite) =>     base.BuildFrom(method, suite).Select(test =>     {         test.Properties.Add(typeof(DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>).FullName, this);         test.FullName = CreateName(method, type => type.FullName);         test.Name = CreateName(method, type => type.Name);         return test;     });<\/code><\/pre>\n<p>\u042d\u0442\u0438 <code>Properties<\/code> \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 <code>NUnit.Framework.TestContext.TestAdapter<\/code> \u0447\u0435\u0440\u0435\u0437 <code>PropertyBagAdapter Properties<\/code>, \u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u0442\u0435\u0441\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0435\u043d \u0447\u0435\u0440\u0435\u0437 <code>NUnit.Framework.TestContext.CurrentContext.Test<\/code>. \u0414\u043b\u044f \u0443\u0434\u043e\u0431\u0441\u0442\u0432\u0430 \u043c\u043e\u0436\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0434\u043e\u0441\u0442\u0443\u043f \u043a <code>Properties<\/code> \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f:<\/p>\n<pre><code class=\"cs\">using System.Collections.Generic; using System.Linq; using static NUnit.Framework.TestContext;  public static class TestAdapterExtensions {     public static IEnumerable&lt;object> GetProperties(this TestAdapter test) =>         test.Properties.Keys.SelectMany(key => test.Properties[key]); }<\/code><\/pre>\n<p>\u0418 \u0442\u043e\u0433\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>DeclarativeAttribute<\/code> \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">using MethodBoundaryAspect.Fody.Attributes; using NUnit.Framework; using System.Linq;  public class DeclarativeAttribute : OnMethodBoundaryAspect {     public override void OnEntry(MethodExecutionArgs arg)     {         arg.FlowBehavior = FlowBehavior.Return; \/\/ original method's code won't execute          TestContext.CurrentContext.Test.GetProperties()             .OfType&lt;IDeclarativeTest>().Single()             .Test();     } }<\/code><\/pre>\n<p>\u0420\u0430\u043d\u0435\u0435 \u0431\u044b\u043b\u0430 \u0443\u0434\u0430\u043b\u0435\u043d\u0430 \u0437\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 \u043d\u0435\u043f\u0443\u0441\u0442\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432. \u041d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0435\u0435 \u0432\u0435\u0440\u043d\u0443\u0442\u044c:<\/p>\n<pre><code class=\"cs\">public override void OnEntry(MethodExecutionArgs arg) {     var method = arg.Method.DeclaringType         .GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)         .Single(m => m.Name.Equals($\"$_executor_{arg.Method.Name}\"));     if (!method.IsIdle())         throw new InvalidOperationException(\"Test method is not idle, i.e. does something.\");      TestContext.CurrentContext.Test.GetProperties()         .OfType&lt;IDeclarativeTest>().Single()         .Test(); }<\/code><\/pre>\n<p>\u0427\u0442\u043e\u0431\u044b \u043d\u0435 \u0432\u0435\u0448\u0430\u0442\u044c <code>DeclarativeAttribute<\/code> \u043d\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434:<\/p>\n<pre><code class=\"cs\">[TestFixture] public class DemoTests {     [Declarative]     [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)]     public void TestOrdinaryValidator() { }      [Declarative]     [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)]     public void TestAdvancedValidator() { } }<\/code><\/pre>\n<p>\u041c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u0435\u0433\u043e \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u043a\u043e \u0432\u0441\u0435\u043c\u0443 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c\u0443 \u043a\u043b\u0430\u0441\u0441\u0443:<\/p>\n<pre><code class=\"cs\">[TestFixture, Declarative] public class DemoTests {     [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)]     public void TestOrdinaryValidator() { }      [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)]     public void TestAdvancedValidator() { } }<\/code><\/pre>\n<p>\u041d\u043e \u0442\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u043f\u0430\u0442\u0447\u0430\u0442\u0441\u044f <strong><em>\u0432\u0441\u0435<\/em><\/strong> \u043c\u0435\u0442\u043e\u0434\u044b \u043a\u043b\u0430\u0441\u0441\u0430, \u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0442\u0430\u043a\u043e\u0433\u043e \u0442\u0435\u0441\u0442\u0430:<\/p>\n<pre><code class=\"cs\">[Test] public void NormalTest() {     Assert.Pass(); }<\/code><\/pre>\n<p>\u041f\u0440\u0438\u0432\u0435\u0434\u0435\u0442 \u043a \u0435\u0433\u043e \u043f\u0430\u0434\u0435\u043d\u0438\u044e \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c <strong><em>&#171;System.InvalidOperationException: Test method is not idle, i.e. does something&#187;<\/em><\/strong>, \u043d\u043e, \u043a \u0441\u0447\u0430\u0441\u0442\u044c\u044e, \u044d\u0442\u043e \u0442\u043e\u0436\u0435 \u043b\u0435\u0447\u0438\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0435 \u043f\u043e\u043c\u0435\u0447\u0435\u043d \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u043c <code>IDeclarativeTest<\/code>, \u0442\u043e \u0434\u043e\u0441\u0440\u043e\u0447\u043d\u043e \u0432\u044b\u0445\u043e\u0434\u0438\u043c \u0438\u0437 <code>void OnEntry(MethodExecutionArgs)<\/code>:<\/p>\n<pre><code class=\"cs\">public override void OnEntry(MethodExecutionArgs arg) {     var isIDeclarativeTest = arg.Method.CustomAttributes         .Select(attribute => attribute.AttributeType)         .Any(type => type.IsAssignableTo(typeof(IDeclarativeTest)));     if (!isIDeclarativeTest)         return;      var method = arg.Method.DeclaringType         .GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)         .Single(m => m.Name.Equals($\"$_executor_{arg.Method.Name}\"));     if (!method.IsIdle())         throw new InvalidOperationException(\"Test method is not idle, i.e. does something.\");      TestContext.CurrentContext.Test.GetProperties()         .OfType&lt;IDeclarativeTest>().Single()         .Test(); }<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u043e, <code>void NormalTest()<\/code> \u0432\u0441\u0435 \u0440\u0430\u0432\u043d\u043e \u043f\u0440\u043e\u043f\u0430\u0442\u0447\u0438\u0442\u0441\u044f, \u043d\u043e \u0432\u043d\u0435\u0448\u043d\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u0437\u0430\u043c\u0435\u0442\u043d\u043e.<\/p>\n<p><a class=\"anchor\" name=\"3\" id=\"3\"><\/a><\/p>\n<h4>\u041e\u0442\u0432\u0435\u0442<\/h4>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0438\u0437 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 Fody-\u043f\u043b\u0430\u0433\u0438\u043d\u043e\u0432, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 NUnit \u0438 \u0442\u0430\u043a\u043e\u0439-\u0442\u043e \u043c\u0430\u0442\u0435\u0440\u0438 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0446\u0435\u043f\u0446\u0438\u044e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u0438\u0437 <a href=\"https:\/\/habr.com\/ru\/post\/681886\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a>, \u043d\u043e \u043f\u043e \u0441\u0443\u0431\u044a\u0435\u043a\u0442\u0438\u0432\u043d\u044b\u043c \u043e\u0449\u0443\u0449\u0435\u043d\u0438\u044f\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0435\u0449\u0435 \u0431\u043e\u043b\u0435\u0435 \u043a\u043e\u0441\u0442\u044b\u043b\u044c\u043d\u043e\u0435. \u0412\u043e\u0437\u043c\u043e\u0436\u043d\u043e, \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043b\u0430\u0433\u0438\u043d\u0430 \u043c\u043e\u0433\u043b\u043e \u0431\u044b \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e.<\/p>\n<details class=\"spoiler\">\n<summary>Fody \u0432\u044b\u0432\u043e\u0434\u0438\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0434\u0435\u043a\u043b\u0430\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0442\u0435\u0441\u0442\u043e\u0432 \u043d\u0430 \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438 \u043d\u043e\u0432\u044b\u0439 \u0443\u0440\u043e\u0432\u0435\u043d\u044c (gif)<\/summary>\n<div class=\"spoiler__content\">\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06e\/1e1\/e5e\/06e1e1e5e0d0574fd581babdbe633656.gif\" width=\"780\" height=\"440\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/06e\/1e1\/e5e\/06e1e1e5e0d0574fd581babdbe633656.gif\"\/><figcaption><\/figcaption><\/figure>\n<\/p>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"v-portal\" style=\"display:none;\"><\/div>\n<\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/684056\/\"> https:\/\/habr.com\/ru\/post\/684056\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e \u043d\u0435\u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u044b\u043c \u0434\u0430\u043d\u043d\u044b\u043c, \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043d\u0435\u0441\u0447\u0430\u0441\u0442\u043d\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u043f\u043e\u0441\u043b\u0435 \u0441\u043b\u043e\u0432 &#171;<em>\u0441\u043c\u043e\u0442\u0440\u0438, \u043a\u0430\u043a \u044f \u0443\u043c\u0435\u044e<\/em>&#171;, \u0434\u0440\u0443\u0433\u0430\u044f \u0436\u0435 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u2014 \u043f\u043e\u0441\u043b\u0435 &#171;<em>\u0435\u0440\u0443\u043d\u0434\u0430, \u0441\u043c\u043e\u0442\u0440\u0438, \u043a\u0430\u043a \u043d\u0430\u0434\u043e<\/em>&#171;.<\/p>\n<p>\u0422\u0443\u0442 \u043e\u0434\u0438\u043d \u043f\u0440\u0438\u044f\u0442\u0435\u043b\u044c, \u0443\u0432\u0438\u0434\u0435\u0432 <a href=\"https:\/\/habr.com\/ru\/post\/681886\/\" rel=\"noopener noreferrer nofollow\">\u0444\u043e\u043a\u0443\u0441 \u0441 \u0442\u0435\u0441\u0442\u0430\u043c\u0438 \u0431\u0435\u0437 \u0442\u0435\u0441\u0442\u043e\u0432<\/a>\u00a0\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0445 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u0432 \u0438\u0437 preview \u0432\u0435\u0440\u0441\u0438\u0438 C# \u0438 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b NUnit, \u043e\u0442\u043c\u0435\u0442\u0438\u043b, \u0447\u0442\u043e \u0432\u0441\u0435 \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u0442\u0440\u0430\u043d\u0441-\u0440\u0435\u043a\u0442\u0430\u043b\u044c\u043d\u043e, \u0430 \u0441\u0430\u043c \u0431\u044b \u043e\u043d \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u043b Fody, \u0438 \u0432\u044b\u0448\u043b\u043e \u0431\u044b \u0433\u043e\u0440\u0430\u0437\u0434\u043e \u043b\u0443\u0447\u0448\u0435. \u0414\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0441\u0442\u0430\u043b. \u0410 \u043c\u043d\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b\u0441\u044f\u00a0<a href=\"https:\/\/habr.com\/ru\/post\/513062\/#comment_21932102\" rel=\"noopener noreferrer nofollow\">\u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0439<\/a>\u00a0\u043a \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u0434\u0440\u0443\u0433\u043e\u0433\u043e \u043f\u0440\u0435\u043e\u0434\u043e\u043b\u0435\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u0435\u043f\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u044f\u0437\u044b\u043a\u0430. \u0422\u043e\u0433\u0434\u0430 \u0440\u0443\u043a\u0438 \u043d\u0435 \u0434\u043e\u0448\u043b\u0438 \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c, \u0430 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u043e\u0442 \u0440\u0435\u0448\u0438\u043b \u0433\u043b\u044f\u043d\u0443\u0442\u044c, \u0447\u0442\u043e \u044d\u0442\u043e \u0437\u0430 \u043f\u0442\u0438\u0446\u0430, \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043b\u0438 \u043e\u043d\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u0435\u0435 \u044d\u043b\u0435\u0433\u0430\u043d\u0442\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<details class=\"spoiler\">\n<summary>\u0421\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#1\" rel=\"noopener noreferrer nofollow\">\u0414\u0430\u043d\u043e<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#2\" rel=\"noopener noreferrer nofollow\">\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/post\/684056#3\" rel=\"noopener noreferrer nofollow\">\u041e\u0442\u0432\u0435\u0442<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/details>\n<p><a class=\"anchor\" name=\"1\" id=\"1\"><\/a><\/p>\n<h4>\u0414\u0430\u043d\u043e<\/h4>\n<p>\u0418\u0442\u0430\u043a, \u0435\u0441\u043b\u0438 \u0435\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u0442\u043e, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u043e\u0441\u044c \u0432 \u0444\u043e\u043a\u0443\u0441\u0435, \u0442\u043e \u0438\u043c\u0435\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<\/p>\n<details class=\"spoiler\">\n<summary>\u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 `IScript`, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0430\u0442\u0430\u043a\u043e\u0439 `Attack` \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0442\u0430\u043a\u043e\u0439 `AdvancedAttack`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface IScript { }  public class Attack : IScript { }  public class AdvancedAttack : Attack { }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u041f\u0440\u043e\u0432\u0435\u0440\u044f\u044e\u0449\u0438\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440 `IValidator`, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u044b\u043c `OrdinaryValidator` \u0438\u043b\u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u043c `AdvancedValidator`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface IValidator {     void Validate(IScript script); }  public class OrdinaryValidator : IValidator {     void IValidator.Validate(IScript script)     {         if (script is Attack &amp;&amp; script is not AdvancedAttack)             throw new Exception(\"Attack detected.\");     } }  public class AdvancedValidator : IValidator {     void IValidator.Validate(IScript script)     {         if (script is Attack)             throw new Exception(\"Attack detected.\");     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<details class=\"spoiler\">\n<summary>\u0418 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 `ICheck`. \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0443 \u043d\u0430 \u043e\u0431\u043d\u0430\u0440\u0443\u0436\u0435\u043d\u0438\u0435 \u0430\u0442\u0430\u043a\u0438 `AttackDetected`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">public interface ICheck {     bool Check(IValidator validator, IScript script); }  public class AttackDetected : ICheck {     public bool Check(IValidator validator, IScript script)     {         try         {             validator.Validate(script);             return false;         }         catch         {             return true;         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0422\u0435\u0441\u0442\u044b \u0434\u043b\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0430\u043b\u0438\u0434\u0430\u0442\u043e\u0440\u043e\u0432 (\u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e <code>OrdinaryValidator<\/code> \u0438 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0433\u043e <code>AdvancedValidator<\/code>) \u0441 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u043e\u0439 \u0430\u0442\u0430\u043a\u043e\u0439 <code>AdvancedAttack<\/code> \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0442\u0430\u043a:<\/p>\n<pre><code class=\"cs\">using NUnit.Framework;  [TestFixture] public class DemoTests : IDeclarativeTest {     public void Test&lt;TValidator, TScript, TCheck>(bool expected)         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new() =>         DefaultDeclarativeTest.Test&lt;TValidator, TScript, TCheck>(expected);      [DeclarativeCase&lt;OrdinaryValidator, AdvancedAttack, AttackDetected>(false)]     [DeclarativeCase&lt;AdvancedValidator, AdvancedAttack, AttackDetected>(true)]     public void TestAdvancedAttack() { } }<\/code><\/pre>\n<p>\u0424\u043e\u043a\u0443\u0441 \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e \u044d\u0442\u043e \u0442\u0435\u0441\u0442\u044b \u0431\u0435\u0437 \u0442\u0435\u043b\u0430 \u043c\u0435\u0442\u043e\u0434\u0430, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u044b\u0435 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u043e\u043c \u0438 \u0432 \u043d\u0435\u043c \u0436\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0435\u0441\u044f.<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u0434 \u043a\u0430\u043f\u043e\u0442\u043e\u043c `DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>` \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck> : GenericCaseAttribute, ITestBuilder         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new() {     private static readonly IReadOnlyCollection&lt;Type> types = new[]     {         typeof(TValidator),         typeof(TScript),         typeof(TCheck)     };      public DeclarativeCaseAttribute(bool expected)         : base(expected) { }      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite)     {         IEnumerable&lt;TestMethod> tests;         var type = suite.TypeInfo.Type;          if (!typeof(IDeclarativeTest).IsAssignableFrom(type))             tests = base.BuildFrom(method, suite)                 .SetNotRunnable($\"{type} does not implement {typeof(IDeclarativeTest)}.\");         else if (!method.MethodInfo.IsIdle())             tests = base.BuildFrom(method, suite)                 .SetNotRunnable(\"Method is not idle, i.e. does something.\");         else             tests = base.BuildFrom(new MethodWrapper(type, nameof(IDeclarativeTest.Test)), suite);                  return tests.Select(test =>         {             test.FullName = CreateName(test, suite, method,                 suite => suite.FullName, type => type.FullName);             test.Name = CreateName(test, suite, method,                 suite => suite.Name, type => type.Name);             return test;         });     }      private static string CreateName(         TestMethod test,         Test suite,         IMethodInfo method,         Func&lt;Test, string> suitNameSelector,         Func&lt;Type, string> typeNameSelector) =>         $\"{suitNameSelector(suite)}.{method.Name}&lt;{             string.Join(\",\", types.Select(typeNameSelector))}>({             string.Join(',', test.Arguments)})\"; }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u041e\u043d \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043e\u0442 <code>GenericCaseAttribute<\/code>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0441\u0432\u043e\u0435\u0433\u043e \u0431\u0430\u0437\u043e\u0432\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 <code>TestCaseAttribute<\/code> \u0443\u043c\u0435\u0435\u0442 \u0432 \u043e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u0447\u0435\u0440\u0435\u0437 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u0443\u044e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e <code>ITestBuilder<\/code>.<\/p>\n<details class=\"spoiler\">\n<summary>`GenericCaseAttribute`<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class GenericCaseAttribute : TestCaseAttribute, ITestBuilder {     private readonly IReadOnlyCollection&lt;Type> typeArguments;      public GenericCaseAttribute(params object[] arguments)         : base(arguments) => typeArguments = GetType().GetGenericArguments();      public new IEnumerable&lt;TestMethod> BuildFrom(IMethodInfo method, Test suite)     {         try         {             return base.BuildFrom(                 method.IsGenericMethodDefinition || typeArguments.Any() ?                 method.MakeGenericMethod(typeArguments.ToArray()) :                 method,                 suite);         }         catch (Exception ex)         {             return base.BuildFrom(method, suite).SetNotRunnable(ex.Message);         }     } }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0421\u0430\u043c <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0442\u043e\u0436\u0435 \u043f\u043e\u0432\u0442\u043e\u0440\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 <code>ITestBuilder<\/code>, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u0434\u043c\u0435\u043d\u044f\u0442\u044c \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 <code>IDeclarativeTest.Test<\/code>, \u0438 \u0434\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IDeclarativeTest<\/code> \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c. (\u0412\u0430\u0440\u0438\u0430\u043d\u0442 \u0441 \u043f\u043e\u0434\u043c\u0435\u043d\u043e\u0439 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 \u0430\u0442\u0442\u0440\u0438\u0431\u0443\u0442\u0430 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 <code>IDeclarativeTest<\/code> \u0442\u0435\u0441\u0442\u043e\u0432\u044b\u043c \u043a\u043b\u0430\u0441\u0441\u043e\u043c \u0432\u043e\u0437\u043c\u043e\u0436\u0435\u043d, \u043d\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043d\u0435\u043e\u0447\u0435\u0432\u0438\u0434\u043d\u043e\u0433\u043e \u0438 \u043d\u0435\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0440\u0438\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f NUnit, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043e\u043d \u0431\u044b\u043b \u043e\u0442\u0432\u0435\u0440\u0433\u043d\u0443\u0442 \u0432 \u043e\u043a\u043e\u043d\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438). \u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u043d\u0430\u0434 \u0438\u043c\u0435\u043d\u0430\u043c\u0438 \u0442\u0435\u0441\u0442\u043e\u0432 \u0441\u043e\u0432\u0435\u0440\u0448\u0430\u044e\u0442\u0441\u044f \u043c\u0430\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0434\u043b\u044f \u043a\u0440\u0430\u0441\u0438\u0432\u043e\u0439 \u0440\u0430\u0431\u043e\u0442\u044b Test Explorer.<\/p>\n<details class=\"spoiler\">\n<summary>\u0415\u0449\u0435 \u0432\u0441\u044f\u043a\u0430\u044f \u043c\u0435\u043b\u043e\u0447\u044c \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0432 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u0438\u044f<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices;  public static class TestMethodExtensions {     public static IEnumerable&lt;TestMethod> SetNotRunnable(this IEnumerable&lt;TestMethod> tests, string message)     {         foreach(var test in tests)             yield return test.SetNotRunnable(message);     }      public static TestMethod SetNotRunnable(this TestMethod test, string message)     {         test.RunState = RunState.NotRunnable;         test.Properties.Set(PropertyNames.SkipReason, message);         return test;     } }  public static class MethodInfoExtensions {     private static readonly IReadOnlyCollection&lt;byte> idle = new[]     {         OpCodes.Nop,         OpCodes.Ret     }.Select(code => (byte)code.Value).ToArray();      public static bool IsIdle(this MethodInfo method)     {         var body = method.GetMethodBody();          if (body.LocalVariables.Any())             return false;          if (body.GetILAsByteArray().Except(idle).Any())             return false;          if (method.DeclaringType.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)             .Any(candidate => IsLocalMethod(candidate, method)))             return false;          return true;     }      private static bool IsLocalMethod(MethodInfo method, MethodInfo container) =>         method.Name.StartsWith($\"&lt;{container.Name}>\") &amp;&amp;         method.GetCustomAttributes&lt;CompilerGeneratedAttribute>().Any(); }<\/code><\/pre>\n<\/p>\n<\/div>\n<\/details>\n<p>\u0412 \u0442\u0435\u0441\u0442\u043e\u0432\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0435 <code>DemoTests<\/code> \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f <code>IDeclarativeTest<\/code> \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0440\u0430\u0431\u043e\u0442\u0443 <code>DefaultDeclarativeTest<\/code>, \u043a\u043e\u0442\u0440\u043e\u0440\u044b\u0439, \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438, \u0438 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043a\u043e\u0434 \u0442\u0435\u0441\u0442\u0430.<\/p>\n<pre><code class=\"cs\">using NUnit.Framework;  public static class DefaultDeclarativeTest {     public static void Test&lt;TValidator, TScript, TCheck>(bool expected)         where TValidator : IValidator, new()         where TScript : IScript, new()         where TCheck : ICheck, new()     {         \/\/ Arrange         IValidator validator = new TValidator();         IScript script = new TScript();         ICheck check = new TCheck();          \/\/ Act         bool actual = check.Check(validator, script);          \/\/ Assert         Assert.AreEqual(expected, actual);     } }<\/code><\/pre>\n<details class=\"spoiler\">\n<summary>\u041b\u0438\u0440\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u043e\u0442\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435<\/summary>\n<div class=\"spoiler__content\">\n<p><code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0438 <code>DefaultDeclarativeTest<\/code> \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043b\u0438\u0447\u0430\u044e\u0442\u0441\u044f \u043e\u0442 \u0441\u0432\u043e\u0438\u0445 \u0432\u0435\u0440\u0441\u0438\u0439 \u0438\u0437 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0438 \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u044f self-review \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u043e\u0441\u043b\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438. \u0412\u043e\u043e\u0431\u0449\u0435, \u0440\u0435\u0432\u044c\u044e &#8212; \u043e\u0442\u043b\u0438\u0447\u043d\u0430\u044f \u0448\u0442\u0443\u043a\u0430. \u041f\u043e\u043c\u043d\u044e, \u0432 \u043e\u0434\u043d\u043e\u0439 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u0443 \u043d\u0430\u0441 \u0431\u044b\u043b\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0430, \u043a\u043e\u0433\u0434\u0430 \u043a\u0430\u0436\u0434\u044b\u0439 \u0440\u0435\u0432\u044c\u044e\u0438\u043b \u043a\u0430\u0436\u0434\u043e\u0433\u043e. \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0434\u043e\u0431\u0440\u043e\u0432\u043e\u043b\u044c\u043d\u043e, \u043d\u043e \u043e\u0431\u044b\u0447\u043d\u043e \u043e\u0442\u043a\u043b\u0438\u043a\u0430\u043b\u043e\u0441\u044c \u0431\u043e\u043b\u0435\u0435 \u043e\u0434\u043d\u043e\u0433\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430. \u0418 \u043f\u043e\u043a\u0430 \u043a\u0442\u043e-\u0442\u043e \u043f\u043e\u0433\u0440\u0443\u0436\u0430\u043b\u0441\u044f \u0432 \u0433\u043b\u0443\u0431\u0438\u043d\u044b \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b, \u0434\u0440\u0443\u0433\u0438\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438 \u043c\u0435\u043b\u043e\u0447\u0438, \u0443\u0441\u043a\u043e\u043b\u044c\u0437\u0430\u0432\u0448\u0438\u0435 \u043e\u0442 \u0432\u0437\u0433\u043b\u044f\u0434\u0430 \u043f\u0435\u0440\u0432\u044b\u0445, \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u0443\u0447\u0448\u0435. \u041a\u043e\u0440\u043e\u0447\u0435, \u0431\u0440\u0430\u0442\u0438\u0435, \u0434\u0430 \u0440\u0435\u0432\u044c\u044e\u0438\u0442\u0435 \u0434\u0440\u0443\u0433 \u0434\u0440\u0443\u0433\u0430.<\/p>\n<\/p>\n<\/div>\n<\/details>\n<p><a class=\"anchor\" name=\"2\" id=\"2\"><\/a><\/p>\n<h4>\u0420\u0435\u0448\u0435\u043d\u0438\u0435<\/h4>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0434\u0430\u043b\u044f\u0435\u043c <code>GenericCaseAttribute<\/code> \u0441 <code>IDeclarativeTest<\/code> \u0438 \u0438\u0445 \u0441\u043b\u0435\u0434\u044b. \u041f\u043e\u043f\u0443\u0442\u043d\u043e \u0432 <code>DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck><\/code> \u0437\u0430\u0432\u043e\u0434\u0438\u043c \u043f\u043e\u043b\u0435 <code>bool expected<\/code> \u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0435\u0433\u043e \u0434\u043b\u044f \u043f\u0440\u0435\u0434\u043e\u0442\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043f\u0430\u0434\u0435\u043d\u0438\u044f \u0442\u0435\u0441\u0442\u043e\u0432 \u0441 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435\u043c <strong><em>&#171;Arguments provided for method with no parameters&#187;<\/em><\/strong>.<\/p>\n<details class=\"spoiler\">\n<summary>\u0422\u0435\u043f\u0435\u0440\u044c `DeclarativeCaseAttribute&lt;TValidator, TScript, TCheck>` \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cs\">using NUnit.Framework; using NUnit.Framework.Interfaces; using NUnit.Framework.Internal; using System; using System.Collections.Generic; using System.Linq;  public class<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-337503","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337503","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=337503"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/337503\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=337503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=337503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=337503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}