Conversation
MyNUnit/MyNUnit/Attributes.cs
Outdated
There was a problem hiding this comment.
Атрибуты надо по файлам разнести: один файл -- один класс. У каждого должен быть конструктор (даже пустой). И обязательно нужно их называть в виде ...Attribute. Здесь, например, TestAttribute
MyNUnit/MyNUnit/Attributes.cs
Outdated
There was a problem hiding this comment.
Почему здесь All, а не Method? Все эти шесть атрибутов же для методов предназначены
There was a problem hiding this comment.
Если этот класс необходим родительскому классу и не нужен внешнему миру, то надо его сделать private-вложенным. Если же нужно иметь возможность обращаться к его свойствам/методам, то надо его в отдельный файл вынести
There was a problem hiding this comment.
public => свойство => с большой буквы :)
|
Атрибуты теперь куда-то пропали |
|
|
||
| namespace MyNUnit; | ||
|
|
||
| public class ApplicationForTests |
|
|
||
| using MyNUnit.Atributes; | ||
|
|
||
| namespace MyNUnit; |
There was a problem hiding this comment.
namespace лучше первой строкой файла, сразу после шапки с лицензией
|
|
||
| public class ApplicationForTests | ||
| { | ||
| public readonly List<ResultsTests> listOfResults = new(); |
There was a problem hiding this comment.
public-всё в .NET именуется с заглавной. Но вообще, плохая идея делать мутабельный ссылочный тип readonly public-полем. Любой извне сможет взять и положить в список какой-то элемент — потому что readonly только ссылка, а не то, на что она указывает.
| Parallel.ForEach(classes, StartTests); | ||
| } | ||
|
|
||
| private static MethodInfo[]? GetMethodsByAtributeAndClass(Type _class, Type atribute) |
There was a problem hiding this comment.
Attribute пишется с двумя t, прошу прощения за придирку :)
| var methodsBefore = GetMethodsByAtributeAndClass(_class, typeof(BeforeAttribute)); | ||
| var methodsAfter = GetMethodsByAtributeAndClass(_class, typeof(AfterAttribute)); | ||
| var methods = _class.GetMethods(); | ||
| foreach(var method in methods) |
There was a problem hiding this comment.
| foreach(var method in methods) | |
| foreach (var method in methods) |
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| foreach(var method in methods) |
There was a problem hiding this comment.
| foreach(var method in methods) | |
| foreach (var method in methods) |
| } | ||
| } | ||
| } | ||
| catch(Exception ex) |
There was a problem hiding this comment.
| catch(Exception ex) | |
| catch (Exception ex) |
| var exceptionType = ex.GetType(); | ||
|
|
||
| if (testAttribute != null && testAttribute.Expected != null && testAttribute.Expected.IsAssignableFrom(exceptionType) || | ||
| (ex.InnerException != null && testAttribute != null && testAttribute.Expected != null && testAttribute.Expected.IsAssignableFrom(ex.InnerException.GetType()))) |
There was a problem hiding this comment.
Сложные условия стоит выносить в отдельный метод
| [AttributeUsage(AttributeTargets.Method)] | ||
| public class AfterAttribute : Attribute | ||
| { | ||
| public AfterAttribute() { } |
There was a problem hiding this comment.
Это не нужно, пустой конструктор сгенерируется сам, если в классе нет конструкторов
| [AfterAttribute] | ||
| public void Method() | ||
| { | ||
| ; | ||
| } |
No description provided.