Skip to content

Conversation

@MikePuzanov
Copy link
Owner

No description provided.

using System;

/// <summary>
/// Атрибут, которым обозначают методы, которые вызываются после каждого тестом
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// Атрибут, которым обозначают методы, которые вызываются после каждого тестом
/// Атрибут, которым обозначают методы, которые вызываются после каждого теста

Comment on lines 11 to 14
public After()
{

}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще, пустой конструктор сгенерируется и так, можно не писать.


public string Ignore { get; set; }

public Test(Type expected, string ignore = null)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Компилятор огорчён происходящим


public class Tests
{
private readonly MyNUnit myNUnit = new MyNUnit();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private readonly MyNUnit myNUnit = new MyNUnit();
private readonly MyNUnit myNUnit = new ();

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Parallel.ForEach(dlls,dll => DoTestFromDll(dll, message));
Parallel.ForEach(dlls, dll => DoTestFromDll(dll, message));

return;
}
object classInstance = Activator.CreateInstance(classDll);
Parallel.ForEach(before, method => RunMethodsWithAttributes(method, messagesFromCurrentTest, classInstance));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

То же с Before — если их много, могут быть гонки в пользовательском коде. Так что либо запрещать, чтобы их было много, либо исполнять последовательно

}
else
{
message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms");
message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}", $"Время: {watch.ElapsedMilliseconds} ms");

}
else if (exception.InnerException.GetType() != attribute.Expected)
{
message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
message = ($"Тест {test.Name} не пройден: ожидалось исключения типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms");
message = ($"Тест {test.Name} не пройден: ожидалось исключение типа {attribute.Expected}, возникло {exception.InnerException.GetType()}", $"Время: {watch.ElapsedMilliseconds} ms");

Comment on lines 120 to 128
private int CheckAttributesInMethod(Attribute[] attribute)
{
if (attribute.Length > 0)
{
return 1;
}

return 0;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private int CheckAttributesInMethod(Attribute[] attribute)
{
if (attribute.Length > 0)
{
return 1;
}
return 0;
}
private int CheckAttributesInMethod(Attribute[] attribute)
=> attribute.Length > 0 ? 1 : 0;

return 0;
}

private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object ClassIntstase)
private void RunMethodsWithAttributes(MethodInfo method, List<(string, string)> messagesForUser, object classInstance)

Copy link
Collaborator

@yurii-litvinov yurii-litvinov left a 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)
Copy link
Collaborator

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)
Copy link
Collaborator

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;
Copy link
Collaborator

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}", ""));
Copy link
Collaborator

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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase)
private void RunMethodsWithAttributes(List<MethodInfo> methods, object classInstance)

}
}

private void RunMethodsWithAttributes(List<MethodInfo> methods, object classIntstase)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тоже неправдивое название, кстати. Этот метод буквально ничего не делает касательно атрибутов.

Comment on lines +136 to +142
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;
Copy link
Collaborator

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++)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (int i = 0;i < array.Length;i++)
for (int i = 0; i < array.Length; i++)

Comment on lines +188 to +189
}
private class TestAttributes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
private class TestAttributes
}
private class TestAttributes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants