-
Notifications
You must be signed in to change notification settings - Fork 32
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
Косторной Дмитрий #31
base: master
Are you sure you want to change the base?
Conversation
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using System.ComponentModel.DataAnnotations; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public void WhenScaleIsNegative_ShouldThrowArgumentException() | ||
{ | ||
Action act = () => new NumberValidator(1, -1, false); | ||
act.Should().Throw<ArgumentException>().WithMessage("precision must be a non-negative number less or equal than precision"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
||
private void ValidateNumber(NumberValidator validator, string input, bool expected) | ||
{ | ||
bool result = validator.IsValidNumber(input); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[Test] | ||
public void WhenScaleIsMoreThanPrecision_ShouldThrowArgumentException() | ||
{ | ||
Action act = () => new NumberValidator(2, 3, false); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public void WhenScaleIsMoreThanPrecision_ShouldThrowArgumentException() | ||
{ | ||
Action act = () => new NumberValidator(2, 3, false); | ||
act.Should().Throw<ArgumentException>().WithMessage("precision must be a non-negative number less or equal than precision"); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ClassicAssert.IsFalse(new NumberValidator(17, 2, true).IsValidNumber("0.000")); | ||
ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("-1.23")); | ||
ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); | ||
public void WhenPrecisionIsNegative_ShouldReturnArgumentException() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
public void WhenInputIsEmpty_ShouldReturnFalse() | ||
{ | ||
NumberValidator validator = new NumberValidator(5, 2, true); | ||
ValidateNumber(validator, "", false); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
|
||
[Test] | ||
public void WhenInputIsNull_ShouldReturnFalse() |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[TestCase("123 45", false)] | ||
[TestCase("++1", false)] | ||
[TestCase("1.", false)] | ||
public void WhenInputIsVarious_ShouldReturnExpected_PositiveValidator(string input, bool expected) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
} | ||
|
||
|
||
[Test] |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); | ||
public void WhenPrecisionIsNegative_ShouldReturnArgumentException() | ||
{ | ||
Action action = () => new NumberValidator(-1, 2, true); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ClassicAssert.IsFalse(new NumberValidator(3, 2, true).IsValidNumber("a.sd")); | ||
public void WhenPrecisionIsNegative_ShouldReturnArgumentException() | ||
{ | ||
Action action = () => new NumberValidator(-1, 2, true); |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
[TestCase("123,67", true, true)] | ||
[TestCase("123 45", false, true)] | ||
[TestCase("++1", false, true)] | ||
[TestCase("1.", false, true)] | ||
|
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.
Лишняя пустая строка?
ValidateNumber(validator, input, expected); | ||
} | ||
|
||
private void ValidateNumber(NumberValidator validator, string input, bool expected) |
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.
Точно нужен отдельны метод, если он не периспользуется нигде кроме WhenInputIsVarious_ShouldReturnExpected?
[TestCase("-123.45", false, false)] | ||
[TestCase("--1", false, false)] | ||
[TestCase("-1.", false, false)] | ||
public void WhenInputIsVarious_ShouldReturnExpected(string input, bool expected, bool onlyPositive) |
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.
Предлагаю повысить читаемость и прозрачность тестов
Переименовать метод в ShouldReturnExpectedVlidationResult_When
А в тест кейсах задать TestName, c кратким понятным описанием, например ScaleIsGreaterThanZero и т.д
ClassicAssert.AreEqual(expectedTsar.Parent.Parent, actualTsar.Parent.Parent); | ||
actualTsar.Should().BeEquivalentTo(expectedTsar, properties => | ||
properties.Excluding(o => o.Name == "Id" && | ||
o.DeclaringType == typeof(Person)).IgnoringCyclicReferences()); |
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.
Хорошая правка, теперь мы защитились от циклических ссылок, когда Person в Parent указывает сам на себя.
Рекурсия при большой вложенности, больше 10, не решена. Тест все еще будет падать, можешь сам в этом убедиться.
Достаточно добавить AllowingInfiniteRecursion чтобы это поправить
No description provided.