Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Kostornoj-Dmitrij
Copy link

No description provided.

using NUnit.Framework;
using NUnit.Framework.Legacy;
using System.ComponentModel.DataAnnotations;

This comment was marked as resolved.

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.


private void ValidateNumber(NumberValidator validator, string input, bool expected)
{
bool result = validator.IsValidNumber(input);

This comment was marked as resolved.

[Test]
public void WhenScaleIsMoreThanPrecision_ShouldThrowArgumentException()
{
Action act = () => new NumberValidator(2, 3, false);

This comment was marked as resolved.

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.

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.

public void WhenInputIsEmpty_ShouldReturnFalse()
{
NumberValidator validator = new NumberValidator(5, 2, true);
ValidateNumber(validator, "", false);

This comment was marked as resolved.

}

[Test]
public void WhenInputIsNull_ShouldReturnFalse()

This comment was marked as resolved.

[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.

}


[Test]

This comment was marked as resolved.

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.

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.

[TestCase("123,67", true, true)]
[TestCase("123 45", false, true)]
[TestCase("++1", false, true)]
[TestCase("1.", false, true)]

Copy link

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

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

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

@shiyois shiyois Nov 6, 2024

Choose a reason for hiding this comment

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

Хорошая правка, теперь мы защитились от циклических ссылок, когда Person в Parent указывает сам на себя.
Рекурсия при большой вложенности, больше 10, не решена. Тест все еще будет падать, можешь сам в этом убедиться.
Достаточно добавить AllowingInfiniteRecursion чтобы это поправить

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.

2 participants