-
Notifications
You must be signed in to change notification settings - Fork 0
MyNUnit #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
MyNUnit #9
Conversation
MyNUnit/AttributesMyNunit/After.cs
Outdated
| using System; | ||
|
|
||
| /// <summary> | ||
| /// Атрибут, которым обозначают методы, которые вызываются после каждого тестом |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| /// Атрибут, которым обозначают методы, которые вызываются после каждого тестом | |
| /// Атрибут, которым обозначают методы, которые вызываются после каждого теста |
MyNUnit/AttributesMyNunit/After.cs
Outdated
| public After() | ||
| { | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Вообще, пустой конструктор сгенерируется и так, можно не писать.
MyNUnit/AttributesMyNunit/Test.cs
Outdated
|
|
||
| public string Ignore { get; set; } | ||
|
|
||
| public Test(Type expected, string ignore = null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Компилятор огорчён происходящим
MyNUnit/MyNUnit.Test/MyNUnit.Test.cs
Outdated
|
|
||
| public class Tests | ||
| { | ||
| private readonly MyNUnit myNUnit = new MyNUnit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private readonly MyNUnit myNUnit = new MyNUnit(); | |
| private readonly MyNUnit myNUnit = new (); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| var dlls = Directory.GetFiles(path, "*.dll"); | ||
| var tasks = new Task<List<(string, string)>>[dlls.Length]; | ||
| var message = new List<(string, string)>(); | ||
| Parallel.ForEach(dlls,dll => DoTestFromDll(dll, message)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Parallel.ForEach(dlls,dll => DoTestFromDll(dll, message)); | |
| Parallel.ForEach(dlls, dll => DoTestFromDll(dll, message)); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| return; | ||
| } | ||
| object classInstance = Activator.CreateInstance(classDll); | ||
| Parallel.ForEach(before, method => RunMethodsWithAttributes(method, messagesFromCurrentTest, classInstance)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
То же с Before — если их много, могут быть гонки в пользовательском коде. Так что либо запрещать, чтобы их было много, либо исполнять последовательно
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| } | ||
| else | ||
| { | ||
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); | |
| message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms"); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| } | ||
| else if (exception.InnerException.GetType() != attribute.Expected) | ||
| { | ||
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); | |
| message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms"); |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| private int CheckAttributesInMethod(Attribute[] attribute) | ||
| { | ||
| if (attribute.Length > 0) | ||
| { | ||
| return 1; | ||
| } | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private int CheckAttributesInMethod(Attribute[] attribute) | |
| { | |
| if (attribute.Length > 0) | |
| { | |
| return 1; | |
| } | |
| return 0; | |
| } | |
| private int CheckAttributesInMethod(Attribute[] attribute) | |
| => attribute.Length > 0 ? 1 : 0; |
MyNUnit/MyNUnit/MyNUnit.cs
Outdated
| return 0; | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase) | |
| private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object classInstance) |
yurii-litvinov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Всё ещё несколько предупреждений "Cannot convert null literal to non-nullable reference type." при компиляции. А должно компилироваться без предупреждений.
| /// </summary> | ||
| /// <param name="path">путь до .dll</param> | ||
| /// <returns>Кортеж из (названия теста, результат о нем)</returns> | ||
| public (string, string)[] RunTests(string path) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Интересно, почему именно массив и зачем ToArray в конце
| return count; | ||
| } | ||
|
|
||
| private void GetAttributesAndDoBeforeAndAfterClass(MethodInfo method, TestAttributes testAttributes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Название метода всё ещё неправдиво.
| /// </summary> | ||
| public class MyNUnit | ||
| { | ||
| private ConcurrentBag<(string, string)> messages; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ConcurrentBag — это неупорядоченное множество. Сообщения могут произвольно перемешиваться, что, наверное, не то, что хотелось.
| { | ||
| return; | ||
| } | ||
| messages.Add(($"Проверка тестов из {classFromDll.Name}", "")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Выше написано, что messages --- это Кортеж из (названия теста, результат о нем). Тут (и везде, где используется messages) что-то не то написано, либо комментарий неправдив.
| } | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) | |
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classInstance) |
| } | ||
| } | ||
|
|
||
| private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Тоже неправдивое название, кстати. Этот метод буквально ничего не делает касательно атрибутов.
| var types = new Type[] { typeof(Before), typeof(BeforeClass), typeof(Test), typeof(AfterClass), typeof(After)}; | ||
| var typesCount = new Attribute[5][]; | ||
| for (int i = 0; i < types.Length; i++) | ||
| { | ||
| typesCount[i] = Attribute.GetCustomAttributes(method).Where(t => t.GetType() == types[i]).ToArray(); | ||
| } | ||
| return typesCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Самодельный IEnumerable.GroupBy :)
| private int GetSumOfAttributesInMethod(Attribute[][] array) | ||
| { | ||
| var count = 0; | ||
| for (int i = 0;i < array.Length;i++) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| for (int i = 0;i < array.Length;i++) | |
| for (int i = 0; i < array.Length; i++) |
| } | ||
| private class TestAttributes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| } | |
| private class TestAttributes | |
| } | |
| private class TestAttributes |
No description provided.